DogProperty.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Newtonsoft.Json;
  6. using System.IO;
  7. /* 本文件包含对于狗的基础类
  8. * DogProperty 用于描述具体某一只狗的属性配置
  9. * DogBreed 用于描述某一种狗的数据
  10. */
  11. [System.Serializable]
  12. public class DogProperty
  13. {
  14. // Start is called before the first frame update
  15. public string d_id = "121212121";
  16. public string owner_id = string.Empty;
  17. public string dog_name = "小泥鳅";
  18. public int sex = 1;
  19. public string breed = "shibaInu"; // 狗的默认模型
  20. public string skin = "black"; // 狗的默认贴图
  21. public string adoption = "home";
  22. public DateTime brithday = new(2023, 1, 1, 12, 0, 0);
  23. public int satiety = 15;
  24. public int happiness = 50;
  25. public int stamina = 29;
  26. public int thirsty = 8;
  27. public int healthy = 7;
  28. public int clean = 21;
  29. public int curiosity = 50;
  30. public int iq = 50;
  31. public int runSpeed = 50;
  32. public int JumpHeight = 50;
  33. public int liveliness = 50;
  34. public int agility = 50;
  35. public int obesity = 75;
  36. public int intimate = 50;
  37. public int friendly = 50;
  38. public int obedience = 50;
  39. public int friendlyToHost = 50;
  40. public int friendlyToStranger = 50;
  41. public int friendlyToOtherSSDog = 50;
  42. public int friendlyToOtherDSDog = 50;
  43. public int frisbeeSkill = 50;
  44. public int ballSkill = 50;
  45. public int voiceCall = 0; // 识别自己名字能力
  46. public int voiceCommand = 0; // 识别所有口令能力
  47. public bool voiceCallEnable = false;
  48. public bool voiceCommandEnable = false; // 暂时弃用参数
  49. public bool commandSit, commandStand, commandBark, commandLieDown, commandShake, commandTouch, commandDeath, commandTurnL, commandTurnR; // 具体的口令能力是否开启
  50. public int CommandTrainingPhase()
  51. {
  52. int phase = 0;
  53. if (commandSit) phase++;
  54. if (commandStand) phase++;
  55. if (commandBark) phase++;
  56. if (commandLieDown) phase++;
  57. if (commandShake) phase++;
  58. if (commandTouch) phase++;
  59. if (commandDeath) phase++;
  60. if (commandTurnL) phase++;
  61. if (commandTurnR) phase++;
  62. return phase;
  63. }
  64. }
  65. public class DogBreed
  66. {
  67. public string breed { get; set; }
  68. public Dictionary<string, string> name { get; set; }
  69. public Dictionary<string, string> description { get; set; }
  70. public DateTime createDate { get; set; }
  71. public DateTime lastDpdate { get; set; }
  72. public int cost { get; set; }
  73. public string prefab { get; set; }
  74. public string[] skin { get; set; }
  75. }
  76. public class DogBreedController
  77. {
  78. // 读取狗的数据并放入EnviromentSetting.dogBreeds
  79. public static void LoadDogBreed()
  80. {
  81. string filePath = EnviromentSetting.dogDBFilePath;
  82. //string jsonText = File.ReadAllText(filePath);
  83. // 正确的方式(跨平台工作)
  84. string jsonText = string.Empty;
  85. TextAsset textAsset = Resources.Load<TextAsset>(filePath);
  86. if (textAsset != null)
  87. {
  88. jsonText = textAsset.text;
  89. // 处理JSON数据
  90. }
  91. else
  92. {
  93. Debug.LogError("无法加载狗数据库文件!");
  94. }
  95. Dictionary<string, object> dogDB = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonText);
  96. string json2 = dogDB["dogDB"].ToString();
  97. EnviromentSetting.dogBreeds = JsonConvert.DeserializeObject<DogBreed[]>(json2);
  98. }
  99. }