protected IEnumerator Load(string assetBundleName, string assetName, Vector3 orgPos = default(Vector3), Action <GameObject> callback = null) { Debug.Log("Start to load " + assetName + " at frame " + Time.frameCount); // Load asset from assetBundle. AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. GameObject prefab = request.GetAsset <GameObject> (); if (prefab == null) { Debug.LogError(assetName + "isn't loaded successfully at frame " + Time.frameCount); } else { Debug.Log(assetName + "is loaded successfully at frame " + Time.frameCount); GameObject go = Instantiate(prefab, orgPos, Quaternion.identity) as GameObject; if (callback != null) { callback(go); } } }
public static IEnumerator LoadAsyncObject(string path, string assetName = null) { if (path == null) { yield break; } if (m_AssetBundleDict.ContainsKey(path)) { yield break; } AssetBundleLoadAssetOperation request = ResourceLoader.LoadAsync(path, assetName); if (request == null) { Debug.LogError("ResourceLoader.LoadAsync is error. resPath = " + path); yield return(null); } yield return(request); UnityEngine.Object gameObject = request.GetAsset <UnityEngine.Object>(); m_AssetBundleDict.Add(path, gameObject); if (!m_AssetBundleReferenceCount.ContainsKey(path)) { m_AssetBundleReferenceCount.Add(path, 0); } }
protected IEnumerator InstantiateTextAsync(string assetBundleName, string assetName) { // This is simply to get the elapsed time for this phase of AssetLoading. float startTime = Time.realtimeSinceStartup; // Load asset from assetBundle. AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request));//开启协程; string error; LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(assetBundleName, out error); if (bundle != null) { showText.text = bundle.m_AssetBundle.LoadAsset <TextAsset>(assetName).text; } // Calculate and display the elapsed time. float elapsedTime = Time.realtimeSinceStartup - startTime; Debug.Log(assetName + (bundle == null ? " was not" : " was") + " loaded successfully in " + elapsedTime + " seconds"); //yield return null; }
protected IEnumerator InstantiateGameObjectAsync(string assetBundleName, string assetName) { // This is simply to get the elapsed time for this phase of AssetLoading. float startTime = Time.realtimeSinceStartup; // Load asset from assetBundle. AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request));//开启协程; // Get the asset. GameObject prefab = request.GetAsset <GameObject>();//转为GameObject对象; if (prefab != null) { GameObject.Instantiate(prefab); } // Calculate and display the elapsed time. float elapsedTime = Time.realtimeSinceStartup - startTime; Debug.Log(assetName + (prefab == null ? " was not" : " was") + " loaded successfully in " + elapsedTime + " seconds"); }
public IEnumerator LoadGameObjectAsync(string assetBundleName, string assetName, System.Action <GameObject> result) { if (string.IsNullOrEmpty(assetBundleName) || string.IsNullOrEmpty(assetName)) { Debug.LogWarning("assetBundleName or assetName is empty"); result(null); yield break; } if (!isInitialized) { yield return(StartCoroutine(Initialize())); } AssetBundleLoadAssetOperation r = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject)); if (r == null) { result(null); yield break; } yield return(StartCoroutine(r)); GameObject obj = r.GetAsset <GameObject>(); result(obj); }
// Load asset from the given assetBundle. static public AssetBundleLoadAssetOperation LoadAssetAsync (string assetBundleName, string assetName, System.Type type) { AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return null; } // @TODO: Now we only get the main object from the first asset. Should consider type also. Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetBundleLoadAssetOperationSimulation (target); } else #endif { LoadAssetBundle (assetBundleName); operation = new AssetBundleLoadAssetOperationFull (assetBundleName, assetName, type); m_InProgressOperations.Add (operation); } return operation; }
public static void LoadDataFile(eLoadDataPriority priority, string strFileName, DataFileLoaderFunc completeFunc, Action startFunc = null, Action endFunc = null) { AssetBundleLoadAssetOperation operation = AssetBundleManager.LoadAssetAsync("setting_data", strFileName, typeof(TextAsset)); if (operation == null) { if (completeFunc != null) { completeFunc(null); } return; } if (DATA_LOAD_MODE == eDataLoadMode.Coroutine) { ++CoroutineRunningCount; //Debug.LogError(" ++ Coroutine running Added : " + CoroutineRunningCount.ToString()); } else { startloadCount++; } if (startFunc != null) { startFunc(); } Instance.StartCoroutine(LoadDataFile(priority, operation, completeFunc, endFunc)); }
protected IEnumerator InstantiateSpriteAsync(string assetBundleName, string assetName, LoadBundleAssetCallback <Sprite> callBack, Hashtable param) { if (_ResFromBundle) { AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(Sprite)); if (request == null) { Debug.LogError("Failed AssetBundleLoadAssetOperation on " + assetName + " from the AssetBundle " + assetBundleName + "."); yield break; } yield return(StartCoroutine(request)); Sprite resData = request.GetAsset <Sprite>(); if (callBack != null) { callBack.Invoke(assetName, resData, param); } } else { Sprite resData = Resources.Load <Sprite>(assetBundleName); if (callBack != null) { callBack.Invoke(assetName, resData, param); } } }
public static void LoadAllAssetPostHook(ref AssetBundleLoadAssetOperation __result, string assetBundleName, Type type, string manifestAssetBundleName = null) { //BepInLogger.Log($"{assetBundleName} : {type.FullName} : {manifestAssetBundleName ?? ""}"); if (assetBundleName == "sound/data/systemse/brandcall/00.unity3d" || assetBundleName == "sound/data/systemse/titlecall/00.unity3d") { string dir = $"{Paths.PluginPath}\\introclips"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var files = Directory.GetFiles(dir, "*.wav"); if (files.Length == 0) { return; } List <UnityEngine.Object> loadedClips = new List <UnityEngine.Object>(); foreach (string path in files) { loadedClips.Add(AssetLoader.LoadAudioClip(path, AudioType.WAV)); } __result = new AssetBundleLoadAssetOperationSimulation(loadedClips.ToArray()); } }
public void CreateBoneList(GameObject obj, string assetBundleName, string assetName) { this.dictBone.Clear(); if (!AssetBundleCheck.IsFile(assetBundleName, assetName)) { Debug.LogWarning((object)("読み込みエラー\r\nassetBundleName:" + assetBundleName + "\tassetName:" + assetName)); } else { AssetBundleLoadAssetOperation loadAssetOperation = AssetBundleManager.LoadAsset(assetBundleName, assetName, typeof(TextAsset), (string)null); if (loadAssetOperation.IsEmpty()) { Debug.LogError((object)("読み込みエラー\r\nassetName:" + assetName)); } else { string[,] data; YS_Assist.GetListString(loadAssetOperation.GetAsset <TextAsset>().get_text(), out data); int length1 = data.GetLength(0); int length2 = data.GetLength(1); if (length1 != 0 && length2 != 0) { for (int index = 0; index < length1; ++index) { GameObject loop = obj.get_transform().FindLoop(data[index, 0]); if (Object.op_Implicit((Object)loop)) { this.dictBone[data[index, 0]] = loop; } } } AssetBundleManager.UnloadAssetBundle(assetBundleName, true, (string)null, false); } } }
IEnumerator DownloadAsync() { var prefabObject = this.fallbackPrefab; var succeeded = false; #if !UNITY_EDITOR if (this.isActive && !string.IsNullOrEmpty(this.downloadUrl) && !string.IsNullOrEmpty(this.bundleName) && !string.IsNullOrEmpty(this.prefabName)) { AssetBundleManager.SetSourceAssetBundleURL(this.downloadUrl); var initializeOperation = AssetBundleManager.Initialize(); if (initializeOperation != null) { yield return(StartCoroutine(initializeOperation)); AssetBundleLoadAssetOperation loadOperation = null; try { loadOperation = AssetBundleManager.LoadAssetAsync( this.bundleName, this.prefabName, typeof(GameObject)); } catch { } if (loadOperation != null) { yield return(StartCoroutine(loadOperation)); var loadedPrefab = loadOperation.GetAsset <GameObject>(); if (loadedPrefab != null) { prefabObject = loadedPrefab; succeeded = true; } } } } #else succeeded = true; #endif this.LoadedPrefab = prefabObject; if (this.Downloaded != null) { this.Downloaded( this, new global::BundleDownloadedEventArgs() { DownloadSucceeded = succeeded } ); } yield break; }
protected IEnumerator Load(string assetBundleName, string assetName) { Debug.Log("Start to load " + assetName + " at frame " + Time.frameCount); // Load asset from assetBundle. AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. GameObject prefab = request.GetAsset <GameObject> (); if (prefab) { Debug.Log(assetName + " prefab is loaded successfully at frame " + Time.frameCount); if (prefab != null) { GameObject.Instantiate(prefab); } } }
protected IEnumerator LoadSound <T>(string assetBundleName, string assetName, Action <AudioClip> callback = null) where T : UnityEngine.Object { //Debug.Log("Start to load " + assetName + " at frame " + Time.frameCount); assetBundleName = assetBundleName.ToLower(); // Load asset from assetBundle. AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(AudioClip)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. AudioClip audio = request.GetAsset <AudioClip>(); if (audio == null) { Debug.LogError(assetName + "isn't loaded successfully at frame " + Time.frameCount); } else { if (callback != null) { callback(audio); } } }
public void LoadAsync(LoadSuccess onLoadSuccess, LoadError onLoadError) { try { // Load asset from assetBundle. string fileName = System.IO.Path.GetFileNameWithoutExtension(_path); AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(_bundle, fileName, typeof(UnityEngine.Object)); if (request == null) { return; } TaskProvider.Instance.RunTask(request, () => { _asset = request.GetAsset <UnityEngine.Object>(); IsLoaded = true; if (_asset is ILoadableObject) { (_asset as ILoadableObject).LoadAsync(onLoadSuccess, onLoadError); } else { onLoadSuccess(); } }); } catch (Exception e) { onLoadError(new LoadException(e.ToString(), e)); } }
public static AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { AssetBundleLoadAssetOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return(null); } UnityEngine.Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { assetBundleName = RemapVariantName(assetBundleName); LoadAssetBundleAsync(assetBundleName, true, true); operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type); m_InProgressOperations.Add(operation); } return(operation); }
protected IEnumerator LoadOther <T>(string assetBundleName, string assetName, Vector3 oriPos, Action <T> callback = null) where T : UnityEngine.Object { #if dev Debug.Log("Start to load " + assetName + " at frame " + Time.frameCount); #endif assetBundleName = assetBundleName.ToLower(); // Load asset from assetBundle. AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(T)); if (request == null) { yield break; } yield return(StartCoroutine(request)); #if dev Debug.Log("finish request " + assetName + " at frame " + Time.frameCount); #endif // Get the asset. T prefab = request.GetAsset <T>(); if (prefab == null) { Debug.LogError(assetName + "isn't loaded successfully at frame " + Time.frameCount); } else { if (callback != null) { callback(Instantiate(prefab, oriPos, Quaternion.identity)); } } }
public override IEnumerator DownloadData() { yield return(StartCoroutine(data.GetAudio(1))); Debug.Log(data.audioBundle); AssetBundleLoadAssetOperation request = BundleManager.LoadAssetAsync(data.audioBundle[0], data.audioBundle[1], typeof(AudioClip)); if (request == null) { yield break; } yield return(StartCoroutine(request)); data.introAudio = request.GetAsset <AudioClip>(); request = BundleManager.LoadAssetAsync(data.audioBundle[2], data.audioBundle[3], typeof(AudioClip)); if (request == null) { yield break; } yield return(StartCoroutine(request)); data.detailAudio = request.GetAsset <AudioClip>(); BundleManager.UnloadBundle(data.audioBundle[0]); //Debug.Log(data.introAudio + " - " + data.detailAudio); }
protected IEnumerator InstantiateGameObjectAsync(string assetBundleName, string assetName, LoadBundleAssetCallback <GameObject> callBack, Hashtable param) { if (_ResFromBundle) { AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject)); if (request == null) { Debug.LogError("Failed AssetBundleLoadAssetOperation on " + assetName + " from the AssetBundle " + assetBundleName + "."); yield break; } yield return(StartCoroutine(request)); GameObject prefab = request.GetAsset <GameObject>(); var instanceGO = GameObject.Instantiate(prefab); if (callBack != null) { callBack.Invoke(assetName, instanceGO, param); } } else { //Debug.Log("LoadPrefab:" + assetBundleName); GameObject prefab = Resources.Load <GameObject>(assetBundleName); var instanceGO = GameObject.Instantiate(prefab); if (callBack != null) { callBack.Invoke(assetName, instanceGO, param); } } }
protected IEnumerator LoadScritableAsync(string bundleName, string assetName, Action <ScriptableObject> action) { float startTime = Time.realtimeSinceStartup; AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(bundleName, assetName, typeof(ScriptableObject)); if (request == null) { Debug.LogError("Failed AssetBundleLoadAssetOperation on " + assetName + " from the AssetBundle " + bundleName + "."); yield break; } yield return(StartCoroutine(request)); ScriptableObject obj = request.GetAsset <ScriptableObject>(); if (obj != null) { if (action != null) { action(obj); } } else { Debug.LogError("Failed to GetAsset from request"); } float elapsedTime = Time.realtimeSinceStartup - startTime; Debug.Log(assetName + (obj == null ? " was not" : " was") + " loaded successfully in " + elapsedTime + " seconds"); yield return(null); }
public static IEnumerator LoadJsonDataG(string assetBundleName, string assetName, System.Action <JsonData> result) { if (string.IsNullOrEmpty(assetBundleName) || string.IsNullOrEmpty(assetName)) { Debug.LogWarning("assetBundleName or assetName is empty"); result(null); yield break; } //if (!isInitialized) // yield return StartCoroutine(Initialize()); AssetBundleLoadAssetOperation r = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(Object)); if (r == null) { result(null); yield break; } //yield return StartCoroutine(r); TextAsset txt = r.GetAsset <TextAsset>(); if (!txt) { result(null); yield break; } JsonReader jReader = new JsonReader(txt.text); JsonData jData = JsonMapper.ToObject(jReader); result(jData); }
protected override void LoadSourceDataAsync(Action <IStaticDataDirectorySource <TData> > onLoadSuccess, LoadError onLoadFailed) { AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(_bundleName, _path, typeof(UnityEngine.Object)); if (request == null) { onLoadFailed(new LoadException(string.Format("Failed to load source data at path {0}", _path))); return; } TaskProvider.Instance.RunTask(request, () => { Object requestResult = request.GetAsset <UnityEngine.Object>(); IStaticDataDirectorySource <TData> source = requestResult as IStaticDataDirectorySource <TData>; if (source == null) { onLoadFailed(new LoadException(string.Format("Failed to cast loaded data source at path '{0}' into source type {1} and data type {2}", _path, typeof(IStaticDataDirectorySource), typeof(TData)))); } else { onLoadSuccess(source); } }); }
private IEnumerator OnLoadAssetList(PreloadFileModel model, CallBackWithPercent cb) { List <string> list = model.fileList; for (int i = 0; i < list.Count; i++) { string path = list[i]; string bundleName = path.ToLower(); string assetName = path + ".prefab"; AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(bundleName, assetName, typeof(UnityEngine.Object)); if (request != null) { yield return(StartCoroutine(request)); GameObject obj = request.GetAsset <UnityEngine.GameObject>(); _cachePrefabs.Add(bundleName, new ABPrefabInfo(obj)); } else { SampleDebuger.LogError("bundle ++" + bundleName + "++ can't loading"); } cb(i + 1, list.Count); } }
private IEnumerator LoadTextureCoroutine(string[] paths, Action <Texture2D[], string[]> callback) { var textures = new Texture2D[paths.Length]; for (int i = 0; i < paths.Length; i++) { var pathParts = paths[i].Split('/'); var assetBundleName = pathParts[0].ToLower(); var assetName = pathParts[pathParts.Length - 1]; if (!LoaderManager.Instance.IsReady) { yield return(null); } AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(Texture2D)); if (request == null) { Debug.LogError("Failed AssetBundleLoadAssetOperation on " + assetName + " from the AssetBundle " + assetBundleName + "."); yield break; } yield return(StartCoroutine(request)); textures[i] = request.GetAsset <Texture2D>(); } callback.Invoke(textures, paths); }
protected IEnumerator InstantiateImageAsync(string assetBundleName, string assetName) { // This is simply to get the elapsed time for this phase of AssetLoading. float startTime = Time.realtimeSinceStartup; // Load asset from assetBundle. AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request));//开启协程; string error; LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(assetBundleName, out error); if (bundle != null) { texture_ = bundle.m_AssetBundle.LoadAsset <Texture2D>(assetName); //用GUI显示; Sprite st = Sprite.Create(texture_, new Rect(0, 0, texture_.width, texture_.height), Vector2.zero); showImage.sprite = st; //用UI Image显示; } // Calculate and display the elapsed time. float elapsedTime = Time.realtimeSinceStartup - startTime; Debug.Log(assetName + (bundle == null ? " was not" : " was") + " loaded successfully in " + elapsedTime + " seconds"); }
// Load asset from the given assetBundle. public AssetBundleLoadAssetOperation ABM_10_LoadAssetAsync (string assetBundleName, string assetName, System.Type type) { Debug.Log ("------------ABM_10_LoadAssetAsync----------------------assetBundleName ="+assetBundleName+" assetName= "+assetName +" type="+type); AssetBundleLoadAssetOperation operation = null; /* #if UNITY_EDITOR if (ABM_00_SimulateAssetBundleInEditor) { Debug.Log ("------------ABM_10_LoadAssetAsync----------■------------ABM_00_SimulateAssetBundleInEditor ="+ABM_00_SimulateAssetBundleInEditor+" assetBundleName="+assetBundleName+" assetName= "+assetName +" type="+type); string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.Log ("------------ABM_10_LoadAssetAsync--------■-------------ABM_00_SimulateAssetBundleInEditor ="+ABM_00_SimulateAssetBundleInEditor+" assetBundleName="+assetBundleName+" assetName= "+assetName +" assetPaths.Length="+assetPaths.Length); Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return null; } // @TODO: Now we only get the main object from the first asset. Should consider type also. Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetBundleLoadAssetOperationSimulation (target); Debug.Log ("------------ABM_10_LoadAssetAsync---------■------------ABM_00_SimulateAssetBundleInEditor ="+ABM_00_SimulateAssetBundleInEditor+" assetBundleName="+assetBundleName+" assetName= "+assetName +" target"+target+" operation"+operation); } else #endif */ { Debug.Log ("------------ABM_10_LoadAssetAsync-----------else----------- assetBundleName="+assetBundleName+" assetName= "+assetName ); ABM_03_LoadAssetBundle (assetBundleName); operation = new AssetBundleLoadAssetOperationFull (assetBundleName, assetName, type); m_InProgressOperations.Add (operation); } Debug.Log ("------------ABM_10_LoadAssetAsync------------------ assetBundleName="+assetBundleName+" assetName= "+assetName +" operation="+operation); return operation; }
/// <summary> /// 从url异步加载一个资源 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="assetBundleName"></param> /// <param name="assetName"></param> /// <param name="onAssetLoad"></param> public void LoadAssetFromUrlAsync <T>(string assetBundleName, string assetName, UnityAction <T> onAssetLoad) where T : UnityEngine.Object { #if UNITY_EDITOR if (canSimulation && SimulateAssetBundleInEditor) { simuationLoader.LoadAssetAsync(assetBundleName, assetName, (x) => { onAssetLoad((T)x); }); return; } #endif LoadMenu(() => { if (isDownLanding) { m_LoadObjectQueue.Enqueue(new Tuple <string, string, UnityAction <UnityEngine.Object> >(assetBundleName, assetName, (x) => onAssetLoad((T)x))); return; } else { isDownLanding = true; onAssetLoad += (x) => { //activeLoader.UnloadAssetBundle(assetBundleName); isDownLanding = false; }; AssetBundleLoadAssetOperation operation = activeLoader.LoadAssetAsync(assetBundleName, assetName, typeof(T)); StartCoroutine(WaitLoadObject(operation, onAssetLoad)); } }); }
public Object LoadResource(string levelName) { Object obj = null; #if UNITY_EDITOR if (AssetBundleManager.SimulateAssetBundleInEditor) { AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(ASSET_BUNDLE_RESOURCES, levelName, typeof(Object)); if (request == null) { Debug.Log("LoadResource error:" + levelName); return(null); } obj = request.GetAsset <Object>(); } else #endif { string error; LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(ASSET_BUNDLE_RESOURCES, out error); if (bundle == null || !string.IsNullOrEmpty(error)) { Debug.Log("LoadResource error:" + levelName + " >> " + error); return(null); } obj = bundle.m_AssetBundle.LoadAsset <Object>(levelName); } return(obj); }
protected IEnumerator InstantiatePrefabtAsync(string assetBundleName, string assetName, UnityAction <GameObject> loadDoneCallback, UnityAction loadErrorCallback) { AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. var obj = request.GetAsset <GameObject>(); if (obj != null) { // GameObject.Instantiate(obj); if (loadDoneCallback != null) { loadDoneCallback(GameObject.Instantiate(obj)); } else { GameObject.Instantiate(obj); } } else if (loadErrorCallback != null) { loadErrorCallback(); } }
protected IEnumerator InstantiateSpritetAsync(Image image, string assetBundleName, string assetName, UnityAction loadDoneCallback = null, UnityAction loadErrorCallback = null) { AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(Sprite)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. var text = request.GetAsset <Sprite>(); //Debug.Log ("Has sprite? " + (text != null)); if (text != null && image != null) { image.sprite = text; if (loadDoneCallback != null) { loadDoneCallback(); } } else if (loadErrorCallback != null) { loadErrorCallback(); } }
protected IEnumerator InstantiateTextureAsync(Image image, string assetBundleName, string assetName, UnityAction loadDoneCallback = null, UnityAction loadErrorCallback = null) { AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(Texture2D)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. var text = request.GetAsset <Texture2D>(); //Debug.Log ("Has sprite? " + (text != null)); if (text != null) { var sprite = Sprite.Create(text, new Rect(0, 0, text.width, text.height), new Vector2(0.5f, 0.5f)); image.sprite = sprite; if (loadDoneCallback != null) { loadDoneCallback(); } } else if (loadErrorCallback != null) { loadErrorCallback(); } }
public static AssetBundleLoadOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type) { Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle"); AssetBundleLoadOperation operation = null; assetBundleName = RemapVariantName(assetBundleName); LoadAssetBundle(assetBundleName); operation = new AssetBundleLoadAssetOperation(assetBundleName, assetName, type); _operations.Add(operation); return operation; }
// Load asset from the given assetBundle. public static 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; }