修复天空盒更新中的错误逻辑

This commit is contained in:
2025-12-04 16:53:05 +08:00
parent 710a9ccfe6
commit d8acbe6a52

View File

@@ -12,6 +12,7 @@ namespace Demo.Game
return new GameObject().AddComponent<SkyUpdatement>(); return new GameObject().AddComponent<SkyUpdatement>();
} }
private int SkyAssetBundleLoaderStatus = 0;
private readonly Dictionary<string, int> NameCache = new(); private readonly Dictionary<string, int> NameCache = new();
private readonly Dictionary<int, Material> MaterialCache = new(); private readonly Dictionary<int, Material> MaterialCache = new();
@@ -23,16 +24,23 @@ namespace Demo.Game
return begin; return begin;
} }
[Content, SerializeField] private int Cache; [Content, SerializeField] private int Cache = -1;
protected override IEnumerator DoSomethingDuringApplyScript()
{
yield return base.DoSomethingDuringApplyScript();
yield return new WaitUntil(() => SkyAssetBundleLoaderStatus == 0);
}
protected override void UpdateData(int data) protected override void UpdateData(int data)
{ {
if (string.IsNullOrEmpty(SkyAssetBundlePath)) if (string.IsNullOrEmpty(SkyAssetBundlePath))
return; return;
if (Cache < 0)
return;
if (Cache != data) if (Cache != data)
{ {
if (data < 0)
RenderSettings.skybox = null;
else
RenderSettings.skybox = MaterialCache[data]; RenderSettings.skybox = MaterialCache[data];
Cache = data; Cache = data;
} }
@@ -52,13 +60,15 @@ namespace Demo.Game
/// </summary> /// </summary>
/// <param name="ab"></param> /// <param name="ab"></param>
[Convention.RScript.Variable.Attr.Method] [Convention.RScript.Variable.Attr.Method]
public IEnumerator Load(string ab) public void Load(string ab)
{ {
yield return this.LoadAssetBundle(ab, x => SkyAssetBundleLoaderStatus++;
ConventionUtility.StartCoroutine(this.LoadAssetBundle(ab, x =>
{ {
SkyAssetBundlePath = ab; SkyAssetBundlePath = ab;
SkyAssetBundle = x; SkyAssetBundle = x;
}); SkyAssetBundleLoaderStatus--;
}));
} }
/// <summary> /// <summary>
@@ -67,8 +77,11 @@ namespace Demo.Game
/// <param name="time"></param> /// <param name="time"></param>
/// <param name="sky"></param> /// <param name="sky"></param>
[Convention.RScript.Variable.Attr.Method] [Convention.RScript.Variable.Attr.Method]
public IEnumerator Add(float time, string sky) public void Add(float time, string sky)
{ {
IEnumerator Foo()
{
yield return new WaitUntil(() => SkyAssetBundle != null);
var ir = SkyAssetBundle.LoadAssetAsync<Material>(sky); var ir = SkyAssetBundle.LoadAssetAsync<Material>(sky);
ir.completed += delegate ir.completed += delegate
{ {
@@ -80,8 +93,12 @@ namespace Demo.Game
} }
MaterialCache[id] = mat; MaterialCache[id] = mat;
ManualAddEntry(time, id, default); ManualAddEntry(time, id, default);
SkyAssetBundleLoaderStatus--;
}; };
yield return ir; yield return ir;
} }
SkyAssetBundleLoaderStatus++;
ConventionUtility.StartCoroutine(Foo());
}
} }
} }