修复天空盒更新中的错误逻辑
This commit is contained in:
@@ -12,6 +12,7 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<SkyUpdatement>();
|
||||
}
|
||||
|
||||
private int SkyAssetBundleLoaderStatus = 0;
|
||||
private readonly Dictionary<string, int> NameCache = new();
|
||||
private readonly Dictionary<int, Material> MaterialCache = new();
|
||||
|
||||
@@ -23,17 +24,24 @@ namespace Demo.Game
|
||||
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)
|
||||
{
|
||||
if (string.IsNullOrEmpty(SkyAssetBundlePath))
|
||||
return;
|
||||
if (Cache < 0)
|
||||
return;
|
||||
if (Cache != data)
|
||||
{
|
||||
RenderSettings.skybox = MaterialCache[data];
|
||||
if (data < 0)
|
||||
RenderSettings.skybox = null;
|
||||
else
|
||||
RenderSettings.skybox = MaterialCache[data];
|
||||
Cache = data;
|
||||
}
|
||||
}
|
||||
@@ -52,13 +60,15 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="ab"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public IEnumerator Load(string ab)
|
||||
public void Load(string ab)
|
||||
{
|
||||
yield return this.LoadAssetBundle(ab, x =>
|
||||
{
|
||||
SkyAssetBundlePath = ab;
|
||||
SkyAssetBundle = x;
|
||||
});
|
||||
SkyAssetBundleLoaderStatus++;
|
||||
ConventionUtility.StartCoroutine(this.LoadAssetBundle(ab, x =>
|
||||
{
|
||||
SkyAssetBundlePath = ab;
|
||||
SkyAssetBundle = x;
|
||||
SkyAssetBundleLoaderStatus--;
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,21 +77,28 @@ namespace Demo.Game
|
||||
/// <param name="time"></param>
|
||||
/// <param name="sky"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public IEnumerator Add(float time, string sky)
|
||||
public void Add(float time, string sky)
|
||||
{
|
||||
var ir = SkyAssetBundle.LoadAssetAsync<Material>(sky);
|
||||
ir.completed += delegate
|
||||
IEnumerator Foo()
|
||||
{
|
||||
var mat = ir.asset as Material;
|
||||
if (NameCache.TryGetValue(sky, out int id) == false)
|
||||
yield return new WaitUntil(() => SkyAssetBundle != null);
|
||||
var ir = SkyAssetBundle.LoadAssetAsync<Material>(sky);
|
||||
ir.completed += delegate
|
||||
{
|
||||
id = NameCache.Count;
|
||||
NameCache[sky] = id;
|
||||
}
|
||||
MaterialCache[id] = mat;
|
||||
ManualAddEntry(time, id, default);
|
||||
};
|
||||
yield return ir;
|
||||
var mat = ir.asset as Material;
|
||||
if (NameCache.TryGetValue(sky, out int id) == false)
|
||||
{
|
||||
id = NameCache.Count;
|
||||
NameCache[sky] = id;
|
||||
}
|
||||
MaterialCache[id] = mat;
|
||||
ManualAddEntry(time, id, default);
|
||||
SkyAssetBundleLoaderStatus--;
|
||||
};
|
||||
yield return ir;
|
||||
}
|
||||
SkyAssetBundleLoaderStatus++;
|
||||
ConventionUtility.StartCoroutine(Foo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user