You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
using System.IO; |
|
using Cysharp.Threading.Tasks; |
|
using Newtonsoft.Json; |
|
using Sirenix.OdinInspector; |
|
using Sirenix.Serialization; |
|
using Tools.ExcelResolver; |
|
using UnityEngine; |
|
using UnityEngine.AddressableAssets; |
|
|
|
public class Test : MonoBehaviour |
|
{ |
|
private void Start() |
|
{ |
|
Debug.Log($"start time: {Time.time}"); |
|
// LoadMonsterUtil().Forget(); // 0.26s |
|
// LoadMonsters().Forget(); // 0.57s |
|
LoadJson().Forget(); // 0.1s |
|
} |
|
|
|
private async UniTaskVoid LoadMonsterUtil() |
|
{ |
|
await Addressables.LoadAssetAsync<monsterUtil>("Assets/_Project/ScriptableObject/Excel/monster/_monsterUtil.asset"); |
|
Debug.Log($"加载MonsterUtil成功{Time.time}"); |
|
} |
|
|
|
private async UniTaskVoid LoadMonsters() |
|
{ |
|
await Addressables.LoadAssetsAsync<monster>("monster", null); |
|
Debug.Log($"加载Monster成功{Time.time}"); |
|
} |
|
|
|
private async UniTaskVoid LoadJson() |
|
{ |
|
var json = await Addressables.LoadAssetAsync<TextAsset>("Assets/TestData.json"); |
|
Debug.Log($"成功获取到json文件 {Time.time}"); |
|
var monsterUtil = JsonConvert.DeserializeObject<monsterUtil>(json.text); |
|
Debug.Log($"反序列化成功 {Time.time}"); |
|
} |
|
|
|
|
|
public monsterUtil monsterUtil; |
|
|
|
[Button] |
|
private void DataToJson() |
|
{ |
|
var settings = new JsonSerializerSettings |
|
{ |
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore // 忽略循环引用 |
|
}; |
|
var json = JsonConvert.SerializeObject(monsterUtil, settings); |
|
var testDataPath = Application.dataPath + "/TestData.json"; |
|
File.WriteAllText(testDataPath, json); |
|
} |
|
}
|
|
|