加载性能优化, 暂时放弃异步加载
This commit is contained in:
@@ -61,7 +61,7 @@ namespace Demo.Game
|
||||
Datas.Dispose();
|
||||
}
|
||||
|
||||
#region MyRegion
|
||||
#region Serialize
|
||||
|
||||
protected override bool IsImptSerialize => true;
|
||||
protected override IEnumerator CreateAndLoadingImptCacheFile(ToolFile scriptFile, ToolFile cacheFile)
|
||||
@@ -69,10 +69,10 @@ namespace Demo.Game
|
||||
yield return this.ParseScript2Expr(scriptFile.LoadAsText());
|
||||
using var stream = File.OpenWrite(cacheFile.GetFullPath());
|
||||
using var writer = new BinaryWriter(stream);
|
||||
writer.Write(Datas.Length);
|
||||
foreach (var i in Datas)
|
||||
writer.Write(Count);
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
writer.Write(i);
|
||||
writer.Write(Datas[i]);
|
||||
}
|
||||
}
|
||||
protected override IEnumerator LoadFromImptCacheFile(ToolFile cacheFile)
|
||||
@@ -80,7 +80,7 @@ namespace Demo.Game
|
||||
using var stream = File.OpenRead(cacheFile.GetFullPath());
|
||||
using var reader = new BinaryReader(stream);
|
||||
Count = reader.ReadInt32();
|
||||
Datas = new NativeArray<float>(Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
|
||||
Datas.ResizeArray(Mathf.Max(128, Count));
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Datas[i] = reader.ReadSingle();
|
||||
@@ -89,5 +89,16 @@ namespace Demo.Game
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[Setting, SerializeField] private List<float> d_Datas = new();
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
for (int i = 0; i < Count; i++)
|
||||
d_Datas.Add(Datas[i]);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user