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,40 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using Convention;
using UnityEngine;
namespace Demo.Game
{
public class SkyUpdatement : Updatement<Material>, IAssetBundleLoader
public class SkyUpdatement : Updatement<int>, IAssetBundleLoader
{
public static SkyUpdatement Make()
{
return new GameObject().AddComponent<SkyUpdatement>();
}
private readonly Dictionary<string, int> NameCache = new();
private readonly Dictionary<int, Material> MaterialCache = new();
public string SkyAssetBundlePath;
public AssetBundle SkyAssetBundle;
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(SkyAssetBundlePath))
return;
if (Cache < 0)
return;
if (Cache != data)
{
RenderSettings.skybox = data;
RenderSettings.skybox = MaterialCache[data];
Cache = data;
}
}
public override IEnumerator UnloadScript()
{
Cache = null;
Cache = -1;
if (string.IsNullOrEmpty(SkyAssetBundlePath) == false)
yield return this.UnloadAssetBundle(SkyAssetBundlePath);
SkyAssetBundlePath = "";
@@ -67,7 +73,13 @@ namespace Demo.Game
ir.completed += delegate
{
var mat = ir.asset as Material;
ManualAddEntry(time, mat, default);
if (NameCache.TryGetValue(sky, out int id) == false)
{
id = NameCache.Count;
NameCache[sky] = id;
}
MaterialCache[id] = mat;
ManualAddEntry(time, id, default);
};
yield return ir;
}