using UnityEngine; using System.Collections.Generic; using UnityEngine.UI; using Google.Protobuf.WellKnownTypes; public class JSONReader : MonoBehaviour { // 让 Unity 编辑器能够分别拖入两个不同的 JSON 文件 public TextAsset npcJsonFile; // 用来加载 NPC 数据 public TextAsset locationJsonFile; // 用来加载 Location 数据 public TextAsset eventJsonFile; public TextAsset matialJsonFile; public TextAsset sceneJsonFile; public TextAsset incidentSiteJosnFile; public TextAsset NPCJosnFile; public TextAsset LanguageJsonFile; public TextAsset SelectJsonFile; public TextAsset TaskJsonFile; public Dictionary npcDictionary = new Dictionary(); public Dictionary locationDictionary = new Dictionary(); public Dictionary eventDictionary = new Dictionary(); public Dictionary matialDictionary = new Dictionary(); public Dictionary sceneDictionary = new Dictionary(); public Dictionary incidentSiteDictionary = new Dictionary(); public Dictionary NPCDictionary = new Dictionary(); public Dictionary LanguageDictionary = new Dictionary(); public Dictionary SelectDictionary = new Dictionary(); public Dictionary TaskDictionary = new Dictionary(); void Awake() { // 解析 NPC 和 Location 数据 npcDictionary = ParseJSON(npcJsonFile.text); locationDictionary = LocationParseJSON(locationJsonFile.text); eventDictionary = EventParseJSON(eventJsonFile.text); matialDictionary = MatialParseJSON(matialJsonFile.text); sceneDictionary = SceneParseJSON(sceneJsonFile.text); incidentSiteDictionary = IncidentSiteParseJSON(incidentSiteJosnFile.text); NPCDictionary = NPCParseJSON(incidentSiteJosnFile.text); LanguageDictionary = LanguageParseJSON(LanguageJsonFile.text); SelectDictionary = SelectJSON(SelectJsonFile.text); TaskDictionary = TaskJSON(TaskJsonFile.text); GetLanguageByID(20008); foreach (var npc in npcDictionary) { //Debug.Log(npc.Value.ID); //Debug.Log(npc.Value.Name); } GetNpcDataByID(8001); } // 解析 JSON 字符串为 Task 数据 public Dictionary TaskJSON(string json) { Task_[] npcArray = JsonHelper.FromJson(json); Dictionary selectDictionary = new Dictionary(); foreach (var npc in npcArray) { TaskDictionary[npc.ID] = npc; } return TaskDictionary; } // 解析 JSON 字符串为 Select 数据 public Dictionary SelectJSON(string json) { Select[] npcArray = JsonHelper.FromJson