private IEnumerator _CreateFromAB(string abPath, string resName, ObjCallback callback) { if (string.IsNullOrEmpty(resName)) { resName = GetResName(abPath); } yield return(StartCoroutine(_LoadAB(abPath, null, true))); ABInfo abInfo; if (!mAssetBundles.TryGetValue(abPath.ToLower(), out abInfo)) { yield break; } GameObject go = abInfo.ab.LoadAsset(resName, typeof(GameObject)) as GameObject; if (go == null) { yield break; } go = Instantiate(go) as GameObject; ABRef abRef = go.AddComponent <ABRef>(); abRef.SetABPath(abPath); if (callback != null) { callback(go); } }
/// <summary> /// 加载ab,取出资源并实例化,callback传出 /// </summary> public Coroutine CreateFromAB(string abPath, string resName, ObjCallback callback = null) { return(StartCoroutine(_CreateFromAB(abPath, resName, callback))); }
/// <summary> /// 加载ab,并取出资源,callback传出资源 /// </summary> public Coroutine LoadAssetFromAB <T>(string abPath, string resName, GameObject go, ObjCallback callback = null) { return(StartCoroutine(_LoadAssetFromAB(abPath, resName, go, typeof(T), callback))); }
private IEnumerator _LoadAssetFromAB(string abPath, string resName, GameObject go, System.Type type, ObjCallback callback) { if (string.IsNullOrEmpty(resName)) { resName = GetResName(abPath); } //yield return Utils.StartConroutine(_LoadAB(abPath, null, true)); yield return(StartCoroutine(_LoadAB(abPath, null, true))); ABInfo abInfo; if (!mAssetBundles.TryGetValue(abPath, out abInfo)) { yield break; } UnityEngine.Object asset = abInfo.ab.LoadAsset(resName, type); if (asset == null) { yield break; } if (go == null) { yield break; } ABRef abRef = go.GetComponent <ABRef>(); if (abRef == null) { abRef = go.AddComponent <ABRef>(); } abRef.SetABPath(abPath); if (callback != null) { callback(asset); } }