static public LoadAssetAsync ( string assetBundleName, string assetName, System.Type type ) : AssetBundleLoadAssetOperation | ||
assetBundleName | string | |
assetName | string | |
type | System.Type | |
return | AssetBundleLoadAssetOperation |
public IEnumerator InstantiateObjectAsync(AssetsTableScriptableObject.AssetEntry assetEntry, System.Action <Object> callback) { if (string.IsNullOrEmpty(assetEntry.AssetBundleName) || string.IsNullOrEmpty(assetEntry.AssetName)) { if (assetEntry.DefaultAssetRef != null) { callback(Instantiate(assetEntry.DefaultAssetRef)); } yield break; } AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetEntry.AssetBundleName, assetEntry.AssetName, typeof(Object)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. Object prefab = request.GetAsset <Object>(); if (prefab != null) { callback(Instantiate(prefab)); } else { callback(null); } }
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(); } }
IEnumerator CreateCardEnumrator(string typeName, string fileName, Image sprImg) { while (AssetBundleManager.AssetBundleManifestObject == null) { yield return(null); } string assetBundleName = "assets/jewel-s-free101j/image/" + typeName + "/" + fileName + ".png"; string assetName = fileName; AssetBundleLoadAssetOperation request; // Load asset from assetBundle. request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(Texture2D)); if (request == null) { yield break; } webCoroutine = StartCoroutine(request); yield return(webCoroutine); webCoroutine = null; Texture2D tex = request.GetAsset <Texture2D>(); Sprite spr = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 1.0f); spr.name = tex.name; AssetBundleManager.UnloadAssetBundle(assetBundleName); sprImg.sprite = spr; }
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"); }
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 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); }
IEnumerator LoadAsset() { /* * var request = AssetBundleManager.LoadAssetAsync("ab_ui_prefabs_logincenter", "Center", typeof(GameObject)); * if (request == null) * yield break; * * yield return StartCoroutine(request); * * GameObject prefab = request.GetAsset<GameObject>(); * * if (prefab != null) * GameObject.Instantiate(prefab, transform); */ var request = AssetBundleManager.LoadAssetAsync("ab_ui_prefabs_version", "version", typeof(TextAsset)); if (request == null) { yield break; } yield return(StartCoroutine(request)); string text = request.GetAsset <TextAsset> ().text.Trim(); transform.Find("version").GetComponent <UILabel>().text = text; bool wechat = AnysdkMgr.GetInstance().CheckWechat(); bool native = AnysdkMgr.isNative(); bool guest = !native || text.EndsWith("S"); btnLogin.SetActive(wechat); btnGuest.SetActive(guest); }
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; }
IEnumerator m_LoadAsset <T>(string assetbundleName, string assetName, Action <T> callBack) where T : UnityEngine.Object { if (callBack == null) { yield break; } assetbundleName = assetbundleName.ToLower(); string assetKey = string.Concat(assetbundleName, "_", assetName); if (assets.ContainsKey(assetKey)) { callBack(assets[assetKey] as T); yield break; } var type = typeof(T); var request = AssetBundleManager.LoadAssetAsync(assetbundleName, assetName, type); if (request == null) { yield break; } while (!request.IsDone()) { yield return(null); } assets[assetKey] = request.GetAsset <T>(); callBack(assets[assetKey] as T); AssetBundleManager.UnloadAssetBundle(assetbundleName); }
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); } } }
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 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)); } } }
private static IEnumerable LoadUIAsset(string assetName, Action <RectTransform> assignPrefab) { var request = AssetBundleManager.LoadAssetAsync("z_ui2", assetName, typeof(GameObject)); if (request == null) { SuperController.LogError($"Keybindings: Request for {assetName} in z_ui2 assetbundle failed"); yield break; } yield return(request); var go = request.GetAsset <GameObject>(); if (go == null) { SuperController.LogError($"Keybindings: Failed to load asset {assetName} GameObject"); yield break; } var rectTransform = go.GetComponent <RectTransform>(); if (rectTransform == null) { SuperController.LogError($"Keybindings: Failed to get asset {assetName} RectTransform"); yield break; } assignPrefab(rectTransform); }
static public IEnumerator LoadDatabase(List <string> packages) { if (m_SkinsDict == null) { m_SkinsDict = new Dictionary <string, Skin>(); foreach (string s in packages) { AssetBundleLoadAssetOperation op = AssetBundleManager.LoadAssetAsync(s, "skin", typeof(GameObject)); yield return(CoroutineHandler.StartStaticCoroutine(op)); Skin c = op.GetAsset <GameObject>().GetComponent <Skin>(); if (c != null) { m_SkinsDict.Add(c.skinName, c); m_skinNameList.Add(c.skinName); overlapCharNameList.Add(c.characterName); } } for (int i = 0; i < overlapCharNameList.Count; i++) { if (!m_charNameList.Contains(overlapCharNameList[i])) { m_charNameList.Add(overlapCharNameList[i]); } } m_Loaded = true; } }
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 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 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 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 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)); } }
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(); } }
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 override IEnumerator OnSetupAvatar() { string resPath = null; int roleKey = PlayerData.roleType; RoleKeyCfg roleKeyCfg = roleKeyCfgLoader.GetConfig(roleKey); string skeletonName = roleKeyCfg.ShowBone; resPath = string.Format("models/skeleton_{0}.bundle", skeletonName); var request = AssetBundleManager.LoadAssetAsync(resPath, skeletonName + "_skeleton", typeof(GameObject)); AutoUnloadAsset(request); yield return(request); if (request == null) { yield break; } GameObject prefab = request.GetAsset <GameObject>(); Profiler.BeginSample("EntityInstantiate"); playerSkeleton = Instantiate(prefab) as GameObject; Profiler.EndSample(); OnBodyChange(); SetAvatar(playerSkeleton); }
protected IEnumerator LoadScript(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) { string tempStr = bundle.m_AssetBundle.LoadAsset <TextAsset>(assetName).text; luaenv.DoString(tempStr); } float elapsedTime = Time.realtimeSinceStartup - startTime; Debug.Log(assetName + (bundle == null ? " was not" : " was") + " loaded successfully in " + elapsedTime + " seconds"); }
protected IEnumerator LoadUIAtlas(string assetBundleName, string assetName, UISprite setSprite = null, string spriteName = "") { 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> (); Debug.Log(assetName + (prefab == null ? " isn't" : " is") + " loaded successfully at frame " + Time.frameCount); if (setSprite != null && prefab != null && spriteName != "") { UIAtlas atlas = prefab.GetComponent <UIAtlas> (); setSprite.atlas = atlas; setSprite.spriteName = spriteName; } }