public void LoadScene(string sceneName, LoadCallBackHandler CallBack) { string _scenePath = string.Format("{0}{1}", AssetPath, sceneName); HandlerParam HP = new HandlerParam(); HP.assetName = sceneName; HP.paramObj = null; if (Application.isEditor && !isDebug) { if (CallBack != null) { CallBack(HP); } SceneManager.LoadScene(HP.assetName); return; } string url = ResourcePathManager.Instance.GetLoadPath(_scenePath); url = Path.ChangeExtension(url, ResourcePathManager.abExtension); string _assetBundleName = Path.ChangeExtension(_scenePath, ResourcePathManager.abExtension).ToLower(); LoadABCallBack loadABCallBack = delegate(AssetBundleData assetBundleData) { HP.m_assetBundleData = assetBundleData; if (CallBack != null) { CallBack(HP); } SceneManager.LoadScene(HP.assetName); }; LoadAssetBundle.Instance.LoadScene(url, sceneName, _assetBundleName, loadABCallBack); }
/// <summary> /// 加载 AB 资源 /// </summary> /// <param name="url"></param> /// <param name="abCallBack"></param> /// <returns></returns> private IEnumerator LoadAB(string url, LoadABCallBack loadABCallBack, bool isDepends = false) { if (isDepends && IsLoading(url)) { yield break; } WWW www = new WWW(url); yield return(www); DelLoading(url); if (!string.IsNullOrEmpty(www.error)) { Debug.LogError(www.error); yield break; } AssetBundleData newAssetBundleData = AssetBundleManager.Instance.AddAssetBundle(url); //new AssetBundleData(); newAssetBundleData.m_AssetBundle = www.assetBundle; if (loadABCallBack != null) { loadABCallBack(newAssetBundleData); } yield break; }
//加载总依赖资源文件 AssetBundleManifest public IEnumerator LoadManifest() { if (!isLoadingAssetBundleMainfest) { isLoadingAssetBundleMainfest = true; LoadABCallBack loadABCallBack = delegate(AssetBundleData assetBundleData) { if (assetBundleData.m_AssetBundle != null) { assetBundleManifest = assetBundleData.m_AssetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); } }; string url = ResourcePathManager.Instance.CheckFilePath(ResourcePathManager.Instance.GetPersistentDataPath, "AssetBundle/AssetBundle"); yield return(Game.Instance.StartCoroutine(LoadAB(url, loadABCallBack))); } while (assetBundleManifest == null) { yield return(new WaitForEndOfFrame()); } yield break; }
public void LoadAsset(string bundleName, LoaderProgress progress, LoadABCallBack callback) { if (mAllAsset.ContainsKey(bundleName)) { mABMgr.LoadAB(bundleName, progress, callback); } else { Debug.Log("Dont contain the bundle ==" + bundleName); } }
public void LoadAsset(string bundleName,LoaderProgress progress,LoadABCallBack callback) { if (mAllAsset.ContainsKey (bundleName)) { mABMgr.LoadAB (bundleName, progress, callback); } else { Debug.Log ("Dont contain the bundle ==" + bundleName); } }
public void LoadAB(string bundleName, LoaderProgress progress, LoadABCallBack callback) { if (!mLoadHelper.ContainsKey(bundleName)) { IABRelationMgr loader = new IABRelationMgr(); loader.Initialize(bundleName, progress); mLoadHelper.Add(bundleName, loader); callback(mSceneName, bundleName); } else { Debug.Log("IABMgr contain bundle name ==" + bundleName); } }
/// <summary> /// 加载资源 /// </summary> /// <typeparam name="T">加载资源类型</typeparam> /// <param name="assetName">资源名</param> /// <param name="CallBack">加载回调</param> /// <param name="paramsArr">加载传递参数</param> /// <param name="useType">加载解包时,是否使用类型 T</param> public void LoadAsset <T>(string assetName, LoadCallBackHandler CallBack, System.Object paramsArr, bool useType = true, bool isAsync = true) where T : UnityEngine.Object { if (string.IsNullOrEmpty(assetName)) { Debug.LogWarning("Load AssetName is null " + assetName); return; } string _assetPath = string.Format("{0}{1}{2}", AssetPath, assetName, Extension); HandlerParam HP = new HandlerParam(); HP.assetName = Path.GetFileNameWithoutExtension(assetName); HP.paramObj = paramsArr; if (Application.isEditor && !isDebug) { _assetPath = string.Format("{0}{1}", "Assets/", _assetPath); LoadAsset <T>(_assetPath, CallBack, HP); return; } _assetPath = Path.ChangeExtension(_assetPath, ResourcePathManager.abExtension); string url = ResourcePathManager.Instance.GetLoadPath(_assetPath); url = url.ToLower(); string _assetBundleName = Path.ChangeExtension(_assetPath, ResourcePathManager.abExtension).ToLower(); // allassets/prefab/building/dige_ziyuan.unity3d // 加载资源回调 LoadABCallBack loadABCallBack = delegate(AssetBundleData assetBundleData) { HP.m_assetBundleData = assetBundleData; // 异步加载同时调用两次会卡死主线程 //.m_AssetBundle.LoadAssetAsync<T>(p_handleParam.assetName); HP.assetObj = assetBundleData.m_AssetBundle.LoadAsset <T>(HP.assetName); if (CallBack != null) { CallBack(HP); } }; Game.Instance.StartCoroutine(LoadAssetBundle.Instance.LoadAsset(url, loadABCallBack, _assetBundleName)); }
public static UnityEngine.Object LoadAssetbundle(string path, LoadABCallBack callBack = null, bool isUnloadAb = false) { AssetBundle assetBundle = AssetBundle.LoadFromFile(path); UnityEngine.Object obj = null; if (assetBundle != null) { string[] strs = assetBundle.GetAllAssetNames(); if (strs.Length > 0) { obj = assetBundle.LoadAsset(strs[0]); } if (callBack != null) { callBack(assetBundle, obj); } assetBundle.Unload(isUnloadAb); } return(obj); }
/// <summary> /// 加载资源 /// </summary> /// <param name="assetPath"></param> /// <param name="callBack"></param> /// <param name="assetBundleName"></param> /// <returns></returns> public IEnumerator LoadAsset(string assetPath, LoadABCallBack loadABCallBack, string assetBundleName) { while (IsLoading(assetPath)) { yield return(new WaitForEndOfFrame()); } { // 从管理器中获取加载数据 AssetBundleData assetBundleData = AssetBundleManager.Instance.GetAssetBundleData(assetPath); // 获取到的数据不为空就不再重新加载了 if (assetBundleData != null) { // 引用 +1 assetBundleData.Retain(); if (loadABCallBack != null) { loadABCallBack(assetBundleData); } yield break; // 已经有了直接返回 } } if (assetBundleManifest == null) { yield return(Game.Instance.StartCoroutine(LoadManifest())); } if (assetBundleManifest == null) { Debug.LogError("assetBundlManifest is"); yield break; } AddLoading(assetPath); // 加载依赖资源 // 获取依赖资源数据 string[] depends = assetBundleManifest.GetAllDependencies(assetBundleName); int count = depends.Length; if (count > 0) { AssetBundleManager.Instance.SetDepends(assetBundleName, depends); } List <string> urlList = new List <string>(); for (int i = 0; i < count; ++i) { string url = ResourcePathManager.Instance.CheckFilePath(ResourcePathManager.Instance.GetPersistentDataPath, "AssetBundle/" + depends[i]); url = url.ToLower(); AssetBundleData assetBundleData = AssetBundleManager.Instance.GetAssetBundleData(url); // 获取到的数据不为空就不再重新加载了 if (assetBundleData != null) { continue; } Game.Instance.StartCoroutine(LoadAB(url, null, true)); urlList.Add(url); AddLoading(url); } int index = 0; while (urlList.Count > 0) { index %= urlList.Count; if (!IsLoading(urlList[index])) { urlList.RemoveAt(index); } ++index; yield return(new WaitForEndOfFrame()); } LoadABCallBack CallBack = delegate(AssetBundleData assetBundleData) { loadABCallBack(assetBundleData); }; yield return(Game.Instance.StartCoroutine(LoadAB(assetPath, CallBack))); }
//AB.Unload 卸载 AssetBundl: //参数 false 只卸载 AssetBundl 资源,已经从 AssetBundle 资源中 Load 并且实例化出来的对象不会被释放 //参数 true 卸载 AssetBundl 的同时,也会把从 AssetBundl 资源中Load 并且实例化出来的对象一起销毁(很危险,慎用) public void LoadScene(string sceneAssetPath, string sceneName, string assetBundleName, LoadABCallBack loadABCallBack) { Game.Instance.StartCoroutine(LoadAsset(sceneAssetPath, loadABCallBack, assetBundleName)); }
public void LoadAB(string bundleName,LoaderProgress progress,LoadABCallBack callback) { if (!mLoadHelper.ContainsKey (bundleName)) { IABRelationMgr loader = new IABRelationMgr (); loader.Initialize (bundleName, progress); mLoadHelper.Add (bundleName, loader); callback (mSceneName, bundleName); } else { Debug.Log ("IABMgr contain bundle name ==" + bundleName); } }