Updatement数据优化, 性能优化

This commit is contained in:
2025-12-02 15:26:41 +08:00
parent 716a23fad2
commit f3f13f7051
4 changed files with 122 additions and 145 deletions

View File

@@ -1,41 +1,47 @@
using Convention;
using System.Collections;
using System.Collections.Generic;
using Convention;
using UnityEngine;
using UnityEngine.Rendering.LookDev;
namespace Demo.Game
{
public class MaterialUpdatement : Updatement<Material>, IAssetBundleLoader
public class MaterialUpdatement : Updatement<int>, IAssetBundleLoader
{
public static MaterialUpdatement Make()
{
return new GameObject().AddComponent<MaterialUpdatement>();
}
private readonly Dictionary<string, int> NameCache = new();
private readonly Dictionary<int, Material> MaterialCache = new();
public string MaterialAssetBundlePath = null;
public AssetBundle MaterialAssetBundle = null;
protected override Material Lerp(Material begin, Material end, float t)
protected override int Lerp(int begin, int end, float t)
{
return begin;
}
[Content, SerializeField] private Material Cache;
[Content, SerializeField] private int Cache;
protected override void UpdateData(Material data)
protected override void UpdateData(int data)
{
if (string.IsNullOrEmpty(MaterialAssetBundlePath))
return;
if (Cache < 0)
return;
if (Cache != data && Parent.TryGetComponent<MeshRenderer>(out var meshRenderer))
{
meshRenderer.material = data;
meshRenderer.material = MaterialCache[data];
Cache = data;
}
}
public override IEnumerator UnloadScript()
{
Cache = null;
Cache = -1;
if (string.IsNullOrEmpty(MaterialAssetBundlePath) == false)
yield return this.UnloadAssetBundle(MaterialAssetBundlePath);
MaterialAssetBundlePath = null;
@@ -66,7 +72,13 @@ namespace Demo.Game
ir.completed += x =>
{
var mat = ir.asset as Material;
ManualAddEntry(time, mat, default);
if (NameCache.TryGetValue(material, out int id) == false)
{
id = NameCache.Count;
NameCache[material] = id;
}
MaterialCache[id] = mat;
ManualAddEntry(time, id, default);
};
yield return ir;
}