IEnumerator OnLoadAsset(string abname, string assetName, Action <GameObject> callback = null) { // Load asset from assetBundle. string abName = abname.ToLower() + ".unity3d"; AssetBundleAssetOperation request = ResourceManager.LoadAssetAsync(abName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. GameObject prefab = request.GetAsset <GameObject>(); if (null != prefab) { GameObject.Instantiate(prefab); } if (null != callback) { callback(prefab); } UnloadAssetBundle(abName); }
IEnumerator OnLoadUIAsset(string abname, string assetName, LuaFunction func) { // Load asset from assetBundle. string abName = abname.ToLower() + ".unity3d"; AssetBundleAssetOperation request = ResourceManager.LoadAssetAsync(abName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. GameObject prefab = request.GetAsset <GameObject>(); if (func != null) { func.Call(prefab); func.Dispose(); func = null; } UnloadAssetBundle(abName); }
IEnumerator OnCreatePanel(string name) { string assetName = name + "Panel"; // Load asset from assetBundle. string abName = name.ToLower() + ".unity3d"; AssetBundleAssetOperation request = ResourceManager.LoadAssetAsync(abName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. GameObject prefab = request.GetAsset <GameObject>(); if (Parent.FindChild(name) != null || prefab == null) { yield break; } GameObject go = Instantiate(prefab) as GameObject; go.name = assetName; go.layer = LayerMask.NameToLayer("UI"); go.transform.SetParent(Parent); go.transform.localScale = Vector3.one; go.transform.localPosition = Vector3.zero; go.AddComponent <BaseLua>(); ResourceManager.UnloadAssetBundle(abName); Debug.LogWarning("CreatePanel::>> " + name + " " + prefab); }
// Load asset from the given assetBundle. static public AssetBundleAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { AssetBundleAssetOperation operation = null; LoadAssetBundle(assetBundleName); operation = new AssetBundleLoadAssetOperation(assetBundleName, assetName, type); m_InProgressOperations.Add(operation); //添加进处理中列表,等Update处理 return(operation); }
static int LoadAssetAsync(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 3); string arg0 = LuaScriptMgr.GetLuaString(L, 1); string arg1 = LuaScriptMgr.GetLuaString(L, 2); Type arg2 = LuaScriptMgr.GetTypeObject(L, 3); AssetBundleAssetOperation o = ResourceManager.LoadAssetAsync(arg0, arg1, arg2); LuaScriptMgr.Push(L, o); return(1); }