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.

40 lines
1.2 KiB

using System.IO;
using Cysharp.Threading.Tasks;
using Newtonsoft.Json;
5 months ago
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using Tools.ExcelResolver;
5 months ago
using UnityEngine;
4 months ago
using UnityEngine.AddressableAssets;
5 months ago
public class Test : MonoBehaviour
{
private async void Start()
5 months ago
{
Debug.Log(Time.time);
await Addressables.LoadAssetsAsync<monsterUtil>("default", util =>
{
Debug.Log(util.Data[1].name);
});
Debug.Log(Time.time);
// TextAsset a = await Addressables.LoadAssetAsync<TextAsset>("Assets/StreamingAssetsdata.json");
// Debug.Log($"成功获取到json文件 {Time.time}");
// monsterUtil b = JsonConvert.DeserializeObject<monsterUtil>(a.text);
// Debug.Log($"反序列化成功 {Time.time}");
}
public monsterUtil monsterUtil;
string streamingAssetsPath = Application.streamingAssetsPath + "data.json";
[Button]
private void DataToJson()
{
var settings = new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore // 忽略循环引用
};
var json = JsonConvert.SerializeObject(monsterUtil, settings);
File.WriteAllText(streamingAssetsPath, json);
5 months ago
}
}