2024-11-30 18:15:51 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
public class JSONReader : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
// <20><> Unity <20>༭<EFBFBD><E0BCAD><EFBFBD>ܹ<EFBFBD><DCB9>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC> JSON <20>ļ<EFBFBD>
|
|
|
|
|
public TextAsset npcJsonFile; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NPC <20><><EFBFBD><EFBFBD>
|
|
|
|
|
public TextAsset locationJsonFile; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Location <20><><EFBFBD><EFBFBD>
|
2024-11-30 23:32:17 +08:00
|
|
|
|
public TextAsset eventJsonFile;
|
2024-12-01 04:58:16 +08:00
|
|
|
|
public TextAsset matialJsonFile;
|
|
|
|
|
public TextAsset sceneJsonFile;
|
2024-12-01 22:36:41 +08:00
|
|
|
|
public TextAsset incidentSiteJosnFile;
|
2024-12-01 23:00:40 +08:00
|
|
|
|
public TextAsset NPCJosnFile;
|
2024-11-30 23:32:17 +08:00
|
|
|
|
public Dictionary<int, NPCData> npcDictionary = new Dictionary<int, NPCData>();
|
|
|
|
|
public Dictionary<int, LocationData> locationDictionary = new Dictionary<int, LocationData>();
|
|
|
|
|
public Dictionary<int, EventData> eventDictionary = new Dictionary<int, EventData>();
|
2024-12-01 04:58:16 +08:00
|
|
|
|
public Dictionary<int, MatialData> matialDictionary = new Dictionary<int, MatialData>();
|
|
|
|
|
public Dictionary<int, SceneData> sceneDictionary = new Dictionary<int, SceneData>();
|
2024-12-01 22:36:41 +08:00
|
|
|
|
public Dictionary<int, IncidentSite> incidentSiteDictionary = new Dictionary<int, IncidentSite>();
|
2024-12-01 23:00:40 +08:00
|
|
|
|
public Dictionary<int, NPC> NPCDictionary = new Dictionary<int, NPC>();
|
2024-11-30 18:15:51 +08:00
|
|
|
|
|
2024-11-30 23:32:17 +08:00
|
|
|
|
void Awake()
|
2024-11-30 18:15:51 +08:00
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> NPC <20><> Location <20><><EFBFBD><EFBFBD>
|
2024-11-30 23:32:17 +08:00
|
|
|
|
npcDictionary = ParseJSON(npcJsonFile.text);
|
|
|
|
|
locationDictionary = LocationParseJSON(locationJsonFile.text);
|
|
|
|
|
eventDictionary = EventParseJSON(eventJsonFile.text);
|
2024-12-01 04:58:16 +08:00
|
|
|
|
matialDictionary = MatialParseJSON(matialJsonFile.text);
|
|
|
|
|
sceneDictionary = SceneParseJSON(sceneJsonFile.text);
|
2024-12-01 22:36:41 +08:00
|
|
|
|
incidentSiteDictionary = IncidentSiteParseJSON(incidentSiteJosnFile.text);
|
2024-12-01 23:00:40 +08:00
|
|
|
|
NPCDictionary = NPCParseJSON(incidentSiteJosnFile.text);
|
2024-12-01 22:36:41 +08:00
|
|
|
|
foreach (var npc in locationDictionary)
|
2024-11-30 23:32:17 +08:00
|
|
|
|
{
|
2024-12-04 16:37:51 +08:00
|
|
|
|
|
2024-11-30 23:32:17 +08:00
|
|
|
|
}
|
2024-12-04 16:37:51 +08:00
|
|
|
|
GetNpcDataByID(8001);
|
2024-11-30 18:15:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> JSON <20>ַ<EFBFBD><D6B7><EFBFBD>Ϊ NPC <20><><EFBFBD><EFBFBD>
|
2024-11-30 23:32:17 +08:00
|
|
|
|
public Dictionary<int, NPCData> ParseJSON(string json)
|
2024-11-30 18:15:51 +08:00
|
|
|
|
{
|
|
|
|
|
NPCData[] npcArray = JsonHelper.FromJson<NPCData>(json);
|
|
|
|
|
Dictionary<int, NPCData> npcDictionary = new Dictionary<int, NPCData>();
|
|
|
|
|
|
|
|
|
|
foreach (var npc in npcArray)
|
|
|
|
|
{
|
|
|
|
|
npcDictionary[npc.ID] = npc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return npcDictionary;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> JSON <20>ַ<EFBFBD><D6B7><EFBFBD>Ϊ Location <20><><EFBFBD><EFBFBD>
|
2024-11-30 23:32:17 +08:00
|
|
|
|
public Dictionary<int, LocationData> LocationParseJSON(string json)
|
2024-11-30 18:15:51 +08:00
|
|
|
|
{
|
|
|
|
|
LocationData[] locationArray = JsonHelper.FromJson<LocationData>(json);
|
|
|
|
|
Dictionary<int, LocationData> locationDictionary = new Dictionary<int, LocationData>();
|
|
|
|
|
|
|
|
|
|
foreach (var location in locationArray)
|
|
|
|
|
{
|
|
|
|
|
locationDictionary[location.ID] = location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return locationDictionary;
|
|
|
|
|
}
|
2024-12-04 16:37:51 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> JSON <20>ַ<EFBFBD><D6B7><EFBFBD>Ϊ Event <20><><EFBFBD><EFBFBD>
|
2024-11-30 23:32:17 +08:00
|
|
|
|
public Dictionary<int, EventData> EventParseJSON(string json)
|
2024-11-30 18:15:51 +08:00
|
|
|
|
{
|
2024-11-30 23:32:17 +08:00
|
|
|
|
EventData[] locationArray = JsonHelper.FromJson<EventData>(json);
|
|
|
|
|
Dictionary<int, EventData> locationDictionary = new Dictionary<int, EventData>();
|
2024-11-30 18:15:51 +08:00
|
|
|
|
|
2024-11-30 23:32:17 +08:00
|
|
|
|
foreach (var location in locationArray)
|
2024-11-30 18:15:51 +08:00
|
|
|
|
{
|
2024-11-30 23:32:17 +08:00
|
|
|
|
locationDictionary[location.ID] = location;
|
2024-11-30 18:15:51 +08:00
|
|
|
|
}
|
2024-11-30 23:32:17 +08:00
|
|
|
|
|
|
|
|
|
return locationDictionary;
|
2024-11-30 18:15:51 +08:00
|
|
|
|
}
|
2024-11-30 23:32:17 +08:00
|
|
|
|
|
2024-12-01 04:58:16 +08:00
|
|
|
|
public Dictionary<int, MatialData> MatialParseJSON(string json)
|
|
|
|
|
{
|
|
|
|
|
MatialData[] locationArray = JsonHelper.FromJson<MatialData>(json);
|
|
|
|
|
Dictionary<int, MatialData> locationDictionary = new Dictionary<int, MatialData>();
|
|
|
|
|
|
|
|
|
|
foreach (var location in locationArray)
|
|
|
|
|
{
|
|
|
|
|
locationDictionary[location.ID] = location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return locationDictionary;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Dictionary<int, SceneData> SceneParseJSON(string json)
|
|
|
|
|
{
|
|
|
|
|
SceneData[] locationArray = JsonHelper.FromJson<SceneData>(json);
|
|
|
|
|
Dictionary<int, SceneData> locationDictionary = new Dictionary<int, SceneData>();
|
|
|
|
|
|
|
|
|
|
foreach (var location in locationArray)
|
|
|
|
|
{
|
|
|
|
|
locationDictionary[location.ID] = location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return locationDictionary;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 22:36:41 +08:00
|
|
|
|
public Dictionary<int, IncidentSite> IncidentSiteParseJSON(string json)
|
|
|
|
|
{
|
|
|
|
|
IncidentSite[] locationArray = JsonHelper.FromJson<IncidentSite>(json);
|
|
|
|
|
Dictionary<int, IncidentSite> locationDictionary = new Dictionary<int, IncidentSite>();
|
|
|
|
|
|
|
|
|
|
foreach (var location in locationArray)
|
|
|
|
|
{
|
|
|
|
|
locationDictionary[location.ID] = location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return locationDictionary;
|
|
|
|
|
}
|
2024-12-01 23:00:40 +08:00
|
|
|
|
public Dictionary<int, NPC> NPCParseJSON(string json)
|
|
|
|
|
{
|
|
|
|
|
NPC[] locationArray = JsonHelper.FromJson<NPC>(json);
|
|
|
|
|
Dictionary<int, NPC> locationDictionary = new Dictionary<int, NPC>();
|
|
|
|
|
|
|
|
|
|
foreach (var location in locationArray)
|
|
|
|
|
{
|
|
|
|
|
locationDictionary[location.ID] = location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return locationDictionary;
|
|
|
|
|
}
|
2024-12-01 22:36:41 +08:00
|
|
|
|
|
2024-12-04 16:37:51 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
// <20><><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD><EFBFBD><EFBFBD>ID<49><44>ȡ<EFBFBD><C8A1>Ӧ<EFBFBD><D3A6>NPC<50><43><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public void GetNpcDataByID(int id)
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD>磬<EFBFBD><E7A3AC>ȡ NPC <20>ֵ<EFBFBD><D6B5>ж<EFBFBD>Ӧ ID <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (npcDictionary.ContainsKey(id))
|
|
|
|
|
{
|
|
|
|
|
NPCData npcData = npcDictionary[id];
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
foreach (var npc in npcDictionary)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"No NPC found with ID: {id}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-30 18:15:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>࣬<EFBFBD><E0A3AC><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD> JSON <20><><EFBFBD><EFBFBD>
|
|
|
|
|
public static class JsonHelper
|
|
|
|
|
{
|
|
|
|
|
public static T[] FromJson<T>(string json)
|
|
|
|
|
{
|
|
|
|
|
json = "{\"items\":" + json + "}";
|
|
|
|
|
Wrapper<T> wrapper = JsonUtility.FromJson<Wrapper<T>>(json);
|
|
|
|
|
return wrapper.items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
private class Wrapper<T>
|
|
|
|
|
{
|
|
|
|
|
public T[] items;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class NPCData
|
|
|
|
|
{
|
|
|
|
|
public int ID;
|
|
|
|
|
public string Note;
|
|
|
|
|
public string Name;
|
|
|
|
|
public int ActionMode;
|
|
|
|
|
public int Group;
|
|
|
|
|
public int GroupLeader;
|
|
|
|
|
public int IsLeadingNPC;
|
|
|
|
|
public string ICON;
|
|
|
|
|
public int WeightLimit;
|
|
|
|
|
public string Stats;
|
|
|
|
|
public string Skills;
|
|
|
|
|
public string ResPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class LocationData
|
|
|
|
|
{
|
|
|
|
|
public int ID;
|
|
|
|
|
public string Note;
|
|
|
|
|
public int Name;
|
|
|
|
|
public int Scene;
|
|
|
|
|
public string NpcRatio;
|
|
|
|
|
public string Oversee;
|
|
|
|
|
public string RoleLimit;
|
|
|
|
|
public int Level;
|
|
|
|
|
}
|
2024-11-30 23:32:17 +08:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class EventData
|
|
|
|
|
{
|
|
|
|
|
public int ID;
|
|
|
|
|
public string Note;
|
|
|
|
|
public int Name;
|
|
|
|
|
public string Role;
|
|
|
|
|
public string DisasterLocation;
|
|
|
|
|
}
|
2024-12-01 04:58:16 +08:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class MatialData
|
|
|
|
|
{
|
|
|
|
|
public int ID;
|
|
|
|
|
public string Note;
|
|
|
|
|
public int Type;
|
|
|
|
|
public int Name;
|
|
|
|
|
public int Weight;
|
|
|
|
|
public int Scene;
|
|
|
|
|
public string RoleLimit;
|
|
|
|
|
public string Icon;
|
|
|
|
|
public string ResPath;
|
|
|
|
|
public int ConsumableType;
|
|
|
|
|
public int Durations;
|
|
|
|
|
public string Attribute;
|
|
|
|
|
public string IsPickup;
|
|
|
|
|
public int PutInStore;
|
|
|
|
|
}
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class SceneData
|
|
|
|
|
{
|
|
|
|
|
public int ID;
|
|
|
|
|
public int Name;
|
|
|
|
|
public int Type;
|
|
|
|
|
public string IncidentType;
|
|
|
|
|
public string ObjList;
|
|
|
|
|
public string AreaList;
|
|
|
|
|
public int Storeroom;
|
|
|
|
|
}
|
2024-12-01 22:36:41 +08:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class IncidentSite
|
|
|
|
|
{
|
|
|
|
|
public int ID;
|
|
|
|
|
public string Note;
|
|
|
|
|
public int Name;
|
|
|
|
|
public int Scene;
|
|
|
|
|
public string Position;
|
|
|
|
|
public int Volume;
|
|
|
|
|
public string Difficulty;
|
|
|
|
|
public string SpecialEvent;
|
|
|
|
|
}
|
2024-12-01 04:58:16 +08:00
|
|
|
|
|
2024-12-01 23:00:40 +08:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class NPC
|
|
|
|
|
{
|
|
|
|
|
public int ID;
|
|
|
|
|
public string Note;
|
|
|
|
|
public string Name;
|
|
|
|
|
public string PlayScript;
|
|
|
|
|
public string ResPath;
|
|
|
|
|
public string State1;
|
|
|
|
|
public string StateRes1;
|
|
|
|
|
public string State2;
|
|
|
|
|
public string StateRes2;
|
|
|
|
|
public string Stats1;
|
|
|
|
|
public string Stats2;
|
|
|
|
|
}
|