_xiaofang/xiaofang/Assets/Script/JSONReader/AreaReader.cs

96 lines
3.0 KiB
C#
Raw Normal View History

2024-11-30 18:15:51 +08:00
//using System.Collections.Generic;
//using UnityEngine;
//public class AreaReader : MonoBehaviour
//{
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> JSON <20><><EFBFBD>ݴ洢<DDB4><E6B4A2> Resources <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
// public TextAsset jsonFile; // <20><> Unity <20><EFBFBD><E0BCAD><EFBFBD>н<EFBFBD><D0BD>ļ<EFBFBD><C4BC><EFBFBD>ק<EFBFBD><D7A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
// void Start()
// {
// // <20><><EFBFBD><EFBFBD> JSON <20><><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>
// Dictionary<int, LocationData> locationDictionary = ParseJSON(jsonFile.text);
// // <20><><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
// foreach (var location in locationDictionary)
// {
// Debug.Log("ID: " + location.Key);
// Debug.Log("Note: " + location.Value.Note);
// Debug.Log("Name: " + location.Value.Name);
// Debug.Log("Scene: " + location.Value.Scene);
// Debug.Log("NpcRatio: " + location.Value.NpcRatio);
// Debug.Log("Oversee: " + location.Value.Oversee);
// Debug.Log("RoleLimit: " + location.Value.RoleLimit);
// Debug.Log("Level: " + location.Value.Level);
// // <20><>ӡ RoleLimit <20>ֶε<D6B6><CEB5><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>
// if (!string.IsNullOrEmpty(location.Value.RoleLimit))
// {
// Debug.Log("RoleLimit (split by '|'): ");
// string[] roleLimitParts = location.Value.RoleLimit.Split('|');
// foreach (var part in roleLimitParts)
// {
// Debug.Log(part); // <20><>ӡÿ<D3A1><C3BF> RoleLimit <20><><EFBFBD><EFBFBD>
// }
// }
// // <20><><EFBFBD><EFBFBD> NpcRatio <20><> Oversee <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>Ĵ<EFBFBD><C4B4><EFBFBD>
// if (!string.IsNullOrEmpty(location.Value.NpcRatio))
// {
// Debug.Log("NpcRatio: " + location.Value.NpcRatio);
// }
// if (!string.IsNullOrEmpty(location.Value.Oversee))
// {
// Debug.Log("Oversee: " + location.Value.Oversee);
// }
// }
// }
// // <20><><EFBFBD><EFBFBD> JSON <20>ַ<EFBFBD><D6B7><EFBFBD>
// Dictionary<int, LocationData> ParseJSON(string json)
// {
// // ʹ<><CAB9> Unity <20><> JsonUtility <20><><EFBFBD><EFBFBD> JSON
// 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;
// }
//}
//// <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)
// {
// // Ϊ<><CEAA>ʹ JsonUtility <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 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 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;
//}