性能优化(缓存优化, ddt优化, 有效)

This commit is contained in:
2025-12-09 11:18:11 +08:00
parent 85b505fe7e
commit 5ab19e39f2
8 changed files with 111 additions and 688 deletions

View File

@@ -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
}
}