性能优化(缓存优化, ddt优化, 有效)
This commit is contained in:
@@ -5,6 +5,7 @@ using UnityEngine;
|
||||
using System;
|
||||
using Unity.Collections;
|
||||
using UnityEngine.Rendering;
|
||||
using System.IO;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
@@ -59,5 +60,34 @@ namespace Demo.Game
|
||||
if (Datas.IsCreated)
|
||||
Datas.Dispose();
|
||||
}
|
||||
|
||||
#region MyRegion
|
||||
|
||||
protected override bool IsImptSerialize => true;
|
||||
protected override IEnumerator CreateAndLoadingImptCacheFile(ToolFile scriptFile, ToolFile cacheFile)
|
||||
{
|
||||
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(i);
|
||||
}
|
||||
}
|
||||
protected override IEnumerator LoadFromImptCacheFile(ToolFile cacheFile)
|
||||
{
|
||||
using var stream = File.OpenWrite(cacheFile.GetFullPath());
|
||||
using var reader = new BinaryReader(stream);
|
||||
int length = reader.ReadInt32();
|
||||
Datas = new NativeArray<float>(length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
Datas[i] = reader.ReadSingle();
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user