1.全阶段异步加载与AB包预加载2.node加载无效的问题依然存在
This commit is contained in:
@@ -11,18 +11,8 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<PrefabRootObject>();
|
||||
}
|
||||
|
||||
private List<IEnumerator> AssetBundleLoadings = new();
|
||||
private List<string> AssetBundles = new();
|
||||
private List<GameObject> Prefabs = new();
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
{
|
||||
yield return base.LoadScript(script);
|
||||
foreach (var loading in AssetBundleLoadings)
|
||||
{
|
||||
yield return loading;
|
||||
}
|
||||
}
|
||||
private readonly List<string> AssetBundles = new();
|
||||
private readonly List<GameObject> Prefabs = new();
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
{
|
||||
@@ -45,36 +35,31 @@ namespace Demo.Game
|
||||
<param name=""ab""></param>
|
||||
<param name=""prefab""></param>
|
||||
")]
|
||||
public void Load(string ab, string prefab)
|
||||
public IEnumerator Load(string ab, string prefab)
|
||||
{
|
||||
IEnumerator Foo()
|
||||
AssetBundle assetBundle = null;
|
||||
yield return this.LoadAssetBundle(ab, x => assetBundle = x);
|
||||
GameObject prefabObject = null;
|
||||
if (assetBundle != null)
|
||||
{
|
||||
AssetBundle assetBundle = null;
|
||||
yield return this.LoadAssetBundle(ab, x => assetBundle = x);
|
||||
GameObject prefabObject = null;
|
||||
if (assetBundle != null)
|
||||
var ir = assetBundle.LoadAssetAsync<GameObject>(prefab);
|
||||
yield return ir;
|
||||
if (ir.asset != null)
|
||||
{
|
||||
var ir = assetBundle.LoadAssetAsync<GameObject>(prefab);
|
||||
yield return ir;
|
||||
if (ir.asset != null)
|
||||
{
|
||||
prefabObject = Instantiate(ir.asset as GameObject);
|
||||
Prefabs.Add(prefabObject);
|
||||
prefabObject.transform.SetParent(transform);
|
||||
AssetBundles.Add(ab);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Load Prefab failed", this);
|
||||
}
|
||||
prefabObject = Instantiate(ir.asset as GameObject);
|
||||
Prefabs.Add(prefabObject);
|
||||
prefabObject.transform.SetParent(transform);
|
||||
AssetBundles.Add(ab);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Load AssetBundle failed", this);
|
||||
Debug.LogError($"Load Prefab failed", this);
|
||||
}
|
||||
}
|
||||
|
||||
AssetBundleLoadings.Add(Foo());
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Load AssetBundle failed", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user