using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Newtonsoft.Json; using System.IO; /* 本文件包含对于狗的基础类 * DogProperty 用于描述具体某一只狗的属性配置 * DogBreed 用于描述某一种狗的数据 */ [System.Serializable] public class DogProperty { // Start is called before the first frame update public string d_id = "121212121"; public string owner_id = string.Empty; public string dog_name = "小泥鳅"; public int sex = 1; public string breed = "shibaInu"; // 狗的默认模型 public string skin = "black"; // 狗的默认贴图 public string adoption = "home"; public DateTime brithday = new(2023, 1, 1, 12, 0, 0); public int satiety = 15; public int happiness = 50; public int stamina = 29; public int thirsty = 8; public int healthy = 7; public int clean = 21; public int curiosity = 50; public int iq = 50; public int runSpeed = 50; public int JumpHeight = 50; public int liveliness = 50; public int agility = 50; public int obesity = 75; public int intimate = 50; public int friendly = 50; public int obedience = 50; public int friendlyToHost = 50; public int friendlyToStranger = 50; public int friendlyToOtherSSDog = 50; public int friendlyToOtherDSDog = 50; public int frisbeeSkill = 50; public int ballSkill = 50; public int voiceCall = 0; // 识别自己名字能力 public int voiceCommand = 0; // 识别所有口令能力 public bool voiceCallEnable = false; public bool voiceCommandEnable = false; public bool commandSit, commandStand, commandBark, commandLieDown, commandRotate, commandHug, commandDeath, commandTurnL, commandTurnR; // 具体的口令能力是否开启 } public class DogBreed { public string breed { get; set; } public Dictionary name { get; set; } public Dictionary description { get; set; } public DateTime createDate { get; set; } public DateTime lastDpdate { get; set; } public int cost { get; set; } public string prefab { get; set; } public string[] skin { get; set; } } public class DogBreedController { // 读取狗的数据并放入EnviromentSetting.dogBreeds public static void LoadDogBreed() { string filePath = EnviromentSetting.dogDBFilePath; //string jsonText = File.ReadAllText(filePath); // 正确的方式(跨平台工作) string jsonText = string.Empty; TextAsset textAsset = Resources.Load(filePath); if (textAsset != null) { jsonText = textAsset.text; // 处理JSON数据 } else { Debug.LogError("无法加载狗数据库文件!"); } Dictionary dogDB = JsonConvert.DeserializeObject>(jsonText); string json2 = dogDB["dogDB"].ToString(); EnviromentSetting.dogBreeds = JsonConvert.DeserializeObject(json2); } }