修复天空盒更新中的错误逻辑
This commit is contained in:
@@ -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,17 +24,24 @@ 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)
|
||||||
{
|
{
|
||||||
RenderSettings.skybox = MaterialCache[data];
|
if (data < 0)
|
||||||
|
RenderSettings.skybox = null;
|
||||||
|
else
|
||||||
|
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;
|
{
|
||||||
SkyAssetBundle = x;
|
SkyAssetBundlePath = ab;
|
||||||
});
|
SkyAssetBundle = x;
|
||||||
|
SkyAssetBundleLoaderStatus--;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -67,21 +77,28 @@ 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)
|
||||||
{
|
{
|
||||||
var ir = SkyAssetBundle.LoadAssetAsync<Material>(sky);
|
IEnumerator Foo()
|
||||||
ir.completed += delegate
|
|
||||||
{
|
{
|
||||||
var mat = ir.asset as Material;
|
yield return new WaitUntil(() => SkyAssetBundle != null);
|
||||||
if (NameCache.TryGetValue(sky, out int id) == false)
|
var ir = SkyAssetBundle.LoadAssetAsync<Material>(sky);
|
||||||
|
ir.completed += delegate
|
||||||
{
|
{
|
||||||
id = NameCache.Count;
|
var mat = ir.asset as Material;
|
||||||
NameCache[sky] = id;
|
if (NameCache.TryGetValue(sky, out int id) == false)
|
||||||
}
|
{
|
||||||
MaterialCache[id] = mat;
|
id = NameCache.Count;
|
||||||
ManualAddEntry(time, id, default);
|
NameCache[sky] = id;
|
||||||
};
|
}
|
||||||
yield return ir;
|
MaterialCache[id] = mat;
|
||||||
|
ManualAddEntry(time, id, default);
|
||||||
|
SkyAssetBundleLoaderStatus--;
|
||||||
|
};
|
||||||
|
yield return ir;
|
||||||
|
}
|
||||||
|
SkyAssetBundleLoaderStatus++;
|
||||||
|
ConventionUtility.StartCoroutine(Foo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user