12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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 = 50; // 识别自己名字能力
- public int voiceCommand = 50; // 识别所有口令能力
- //public int commandLieDown = 50;
- //public int commandRotate = 50;
-
-
- }
- public class DogBreed
- {
- public string breed { get; set; }
- public Dictionary<string, string> name { get; set; }
- public Dictionary<string, string> 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<TextAsset>(filePath);
- if (textAsset != null)
- {
- jsonText = textAsset.text;
- // 处理JSON数据
- }
- else
- {
- Debug.LogError("无法加载狗数据库文件!");
- }
- Dictionary<string, object> dogDB = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonText);
- string json2 = dogDB["dogDB"].ToString();
- EnviromentSetting.dogBreeds = JsonConvert.DeserializeObject<DogBreed[]>(json2);
- }
- }
|