Beispiel #1
0
        /// <summary>
        /// 生成一个指定路径的加载器并加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">资源唯一路径</param>
        /// <param name="completeHandler">加载完成回调</param>
        /// <param name="loadModel">加载模式(同步/异步) default=异步</param>
        /// <param name="loadAssetPath">加载资源路径模式(外部/Resources/StreamAsset ) default=ResourcesPath</param>
        protected static ByteLoader LoadAssetSync(string url, System.Action <BaseAbstracResourceLoader> onCompleteAct)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(ByteLoader)));
                return(null);
            }
            bool       isLoaderExit = false;
            ByteLoader byteLoader   = ResourcesLoaderMgr.GetOrCreateLoaderInstance <ByteLoader>(url, ref isLoaderExit);

            byteLoader.m_OnCompleteAct.Add(onCompleteAct);

            if (isLoaderExit && byteLoader.IsCompleted)
            {
                byteLoader.LoadassetModel = LoadAssetModel.Sync;                                                   //这里貌似没必要
                byteLoader.OnCompleteLoad(byteLoader.IsError, byteLoader.Description, byteLoader.ResultObj, true); //如果当前加载器已经完成加载 则手动触发事件
                return(byteLoader);
            }//如果当前加载器存在 且已经加载完成已经完成加载 则手动触发事件

            if (byteLoader.LoadassetModel == LoadAssetModel.Async)
            {
                Debug.LogEditorInfor(string.Format("有资源({0})正在异步加载过程中,同时有同步加载请求 ,则之前的加载逻辑作废!! ", url));
                byteLoader.ForceBreakLoaderProcess();
            }//有一个正在异步加载的加载器运行着
            byteLoader.LoadassetModel = LoadAssetModel.Sync;
            byteLoader.LoadByteAssetSync(url);
            return(byteLoader);
        }
Beispiel #2
0
        /// <summary>
        /// (同步)加载材质球资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="completeHandler"></param>
        /// <returns></returns>
        protected static MaterialLoader LoadAssetSync(Transform requestTarget, string url, System.Action <BaseAbstracResourceLoader> completeHandler)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(MaterialLoader)));
                return(null);
            }

            bool           isContainLoaders = false;
            MaterialLoader materialLoader   = ResourcesLoaderMgr.GetOrCreateLoaderInstance <MaterialLoader>(url, ref isContainLoaders);

            materialLoader.m_OnCompleteAct.Add(completeHandler);


            materialLoader.AddReference(requestTarget, url);
            if (isContainLoaders && materialLoader.IsCompleted)
            {
                materialLoader.LoadassetModel = LoadAssetModel.Sync; //这里貌似没必要(由于异步加载时候同步加载必定完成了)
                materialLoader.OnCompleteLoad(materialLoader.IsError, materialLoader.Description, materialLoader.ResultObj, materialLoader.IsCompleted);
                return(materialLoader);
            }
            if (materialLoader.LoadassetModel == LoadAssetModel.Async)
            {
                materialLoader.ForceBreakLoaderProcess();
            }
            materialLoader.m_LoadAssetCoroutine = null;
            materialLoader.LoadassetModel       = LoadAssetModel.Sync; //这里貌似没必要
            materialLoader.LoadMaterialAssetSync(url);
            return(materialLoader);
        }
Beispiel #3
0
        /// <summary>
        /// (同步)生成一个指定路径的加载器并加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">资源唯一路径</param>
        /// <param name="completeHandler">加载完成回调</param>
        /// <param name="loadModel">加载模式(同步/异步) default=异步</param>
        /// <param name="loadAssetPath">加载资源路径模式(外部/Resources/StreamAsset ) default=ResourcesPath</param>
        public static FontLoader LoadFontAssetSync(string url, System.Action <BaseAbstracResourceLoader> completeHandler)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(FontLoader)));
                return(null);
            }
            bool       isContainLoaders = false;
            FontLoader fontLoader       = ResourcesLoaderMgr.GetOrCreateLoaderInstance <FontLoader>(url, ref isContainLoaders);

            fontLoader.m_OnCompleteAct.Add(completeHandler);

            fontLoader.AddReference(null, url);
            if (isContainLoaders && fontLoader.IsCompleted)
            {
                fontLoader.LoadassetModel = LoadAssetModel.Sync; //这里貌似没必要(由于异步加载时候同步加载必定完成了)
                fontLoader.OnCompleteLoad(fontLoader.IsError, fontLoader.Description, fontLoader.ResultObj, fontLoader.IsCompleted);
                return(fontLoader);
            }
            if (fontLoader.LoadassetModel == LoadAssetModel.Async)
            {
                fontLoader.ForceBreakLoaderProcess();
            }
            fontLoader.LoadassetModel       = LoadAssetModel.Sync; //这里貌似没必要(由于异步加载时候同步加载必定完成了)
            fontLoader.m_LoadAssetCoroutine = null;
            fontLoader.LoadFontAssetSync(url);
            return(fontLoader);
        }
        /// <summary>
        /// 加载Texture2D 图片
        /// </summary>
        /// <param name="url"></param>
        /// <param name="completeHandler"></param>
        /// <returns></returns>
        public static Teture2DLoader LoadTexture2DAssetAsync(Transform requestTarget, string url, System.Action <BaseAbstracResourceLoader> completeHandler)
        {
            Debug.LogError("TODO  Teture2DLoader 还不完善 需要继续测试 ");
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(Teture2DLoader)));
                return(null);
            }

            bool           isContainLoaders = false;
            Teture2DLoader texture2DLoader  = ResourcesLoaderMgr.GetOrCreateLoaderInstance <Teture2DLoader>(url, ref isContainLoaders);

            texture2DLoader.m_OnCompleteAct.Add(completeHandler);
            texture2DLoader.LoadassetModel = LoadAssetModel.Async; //这里貌似没必要(由于异步加载时候同步加载必定完成了)


            texture2DLoader.AddReference(requestTarget, url);
            if (isContainLoaders)
            {
                if (texture2DLoader.IsCompleted)
                {
                    texture2DLoader.OnCompleteLoad(texture2DLoader.IsError, texture2DLoader.Description, texture2DLoader.ResultObj, texture2DLoader.IsCompleted);
                }
                return(texture2DLoader);
            }


            texture2DLoader.m_LoadAssetCoroutine = EventCenter.Instance.StartCoroutine(texture2DLoader.LoadTexture2DAssetAsync(url));
            return(texture2DLoader);
        }
        /// <summary>
        ///  (同步)加载.text 文件 并以string 形式返回
        /// </summary>
        /// <param name="requestTarget">请求加载资源的对象</param>
        /// <param name="url"></param>
        /// <param name="completeHandler"></param>
        /// <returns></returns>
        public static TextAssetLoader LoadAssetSync(string url, System.Action <BaseAbstracResourceLoader> completeHandler)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(TextAsset)));
                return(null);
            }
            bool            isContainLoaders = false;
            TextAssetLoader textAssetLoader  = ResourcesLoaderMgr.GetOrCreateLoaderInstance <TextAssetLoader>(url, ref isContainLoaders);

            textAssetLoader.m_OnCompleteAct.Add(completeHandler);


            textAssetLoader.AddReference(null, url);
            if (isContainLoaders && textAssetLoader.IsCompleted)
            {
                textAssetLoader.LoadassetModel = LoadAssetModel.Sync;
                textAssetLoader.OnCompleteLoad(textAssetLoader.IsError, textAssetLoader.Description, textAssetLoader.ResultObj, textAssetLoader.IsCompleted);
                return(textAssetLoader);
            }

            if (textAssetLoader.LoadassetModel == LoadAssetModel.Async)
            {
                textAssetLoader.ForceBreakLoaderProcess();
            }
            textAssetLoader.LoadassetModel       = LoadAssetModel.Sync;
            textAssetLoader.m_LoadAssetCoroutine = null;
            textAssetLoader.LoadTextAssetSync(url);
            return(textAssetLoader);
        }
Beispiel #6
0
        public override void OnCompleteLoad(bool isError, string description, object result, bool iscomplete, float process = 1)
        {
            if (result != null)
            {
                ResultObj = null;
            }
            else
            {
                if (typeof(AssetBundle) == result.GetType())
                {
                    ResultObj = result as AssetBundle;
                }
                else
                {
                    Debug.LogInfor("加载场景 未知类型 " + result.GetType());
                    ResultObj = result;
                }
            }

            base.OnCompleteLoad(isError, description, ResultObj, iscomplete, process);
            if (m_BridgeLoader != null)
            {
                ResourcesLoaderMgr.DeleteLoader(typeof(BridgeLoader), m_ResourcesUrl, false);
            }
        }
        /// <summary>
        /// 加载资源的桥连接器 会根据配置路径加载优先级加载资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="onCompleteAct"></param>
        /// <param name="isloadSceneAsset"> 如果加载的是场景资源 则这里必须为true  否则为false</param>
        /// <returns></returns>
        private static BridgeLoader LoadAssetAsync(string url, System.Action <BaseAbstracResourceLoader> onCompleteAct, bool isloadSceneAsset)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(BridgeLoader)));
                return(null);
            }

            bool         isLoaderExit = false;
            BridgeLoader bridgeLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <BridgeLoader>(url, ref isLoaderExit);

            bridgeLoader.m_OnCompleteAct.Add(onCompleteAct);
            bridgeLoader.m_IsLoadSceneAsset = isloadSceneAsset;
            bridgeLoader.LoadassetModel     = LoadAssetModel.Async; //这里获得的加载器不需要特殊处理

            if (isLoaderExit)
            {
                if (bridgeLoader.IsCompleted)
                {
                    bridgeLoader.OnCompleteLoad(bridgeLoader.IsError, bridgeLoader.Description, bridgeLoader.ResultObj, true); //如果当前加载器已经完成加载 则手动触发事件
                }
                return(bridgeLoader);                                                                                          //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调
            }
            EventCenter.Instance.StartCoroutine(bridgeLoader.LoadAssetByPriorityAsync(url, bridgeLoader, isloadSceneAsset));
            EventCenter.Instance.StartCoroutine(bridgeLoader.LoadAssetAsync(url, bridgeLoader));
            return(bridgeLoader);
        }
Beispiel #8
0
        /// <summary>
        /// WWW 方式异步加载资源
        /// </summary>
        /// <param name="topPath">资源相对目录前的绝对目录</param>
        /// <param name="url">资源相对目录</param>
        /// <param name="onCompleteAct"></param>
        /// <returns></returns>
        public static WWWLoader WWWLoadAsset(string topPath, LoadAssetModel loadModel, string url, System.Action <BaseAbstracResourceLoader> onCompleteAct)
        {
            if (loadModel != LoadAssetModel.Async)
            {
                Debug.LogError("WWWLoader  只支持异步加载资源");
                return(null);
            }
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(WWWLoader)));
                return(null);
            }
            bool isLoaderExit = false;

            Debug.LogInfor("WWWLoadAsset  url=" + url);


            WWWLoader wwwLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <WWWLoader>(url, ref isLoaderExit);

            wwwLoader.m_OnCompleteAct.Add(onCompleteAct);

            if (isLoaderExit)
            {
                if (wwwLoader.IsCompleted)
                {
                    wwwLoader.OnCompleteLoad(wwwLoader.IsError, wwwLoader.Description, wwwLoader.ResultObj, true); //如果当前加载器已经完成加载 则手动触发事件
                }
                return(wwwLoader);                                                                                 //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调
            }
            wwwLoader.m_TopPath            = topPath;
            wwwLoader.m_LoadAssetCoroutine = EventCenter.Instance.StartCoroutine(wwwLoader.LoadAssetAsync(topPath, url, wwwLoader));
            return(wwwLoader);
        }
Beispiel #9
0
        /// <summary>
        /// 加载精灵图片
        /// </summary>
        /// <param name="url"></param>
        /// <param name="completeHandler"></param>
        /// <returns></returns>
        protected static PrefabLoader LoadAssetAsync(Transform requestTarget, string url, System.Action <BaseAbstracResourceLoader> completeHandler)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(PrefabLoader)));
                if (completeHandler != null)
                {
                    completeHandler(null);
                }
                return(null);
            }

            bool         isContainLoaders = false;
            PrefabLoader prefabloader     = ResourcesLoaderMgr.GetOrCreateLoaderInstance <PrefabLoader>(url, ref isContainLoaders);

            prefabloader.m_OnCompleteAct.Add(completeHandler);
            prefabloader.LoadassetModel = LoadAssetModel.Async; //这里貌似没必要(由于异步加载时候同步加载必定完成了)


            prefabloader.AddReference(requestTarget, url);
            if (isContainLoaders)
            {
                if (prefabloader.IsCompleted)
                {
                    prefabloader.OnCompleteLoad(prefabloader.IsError, prefabloader.Description, prefabloader.ResultObj, prefabloader.IsCompleted);
                }
                return(prefabloader);
            }


            prefabloader.m_LoadAssetCoroutine = EventCenter.Instance.StartCoroutine(prefabloader.LoadPrefabAssetAsync(url));
            return(prefabloader);
        }
Beispiel #10
0
        /// <summary>
        /// 生成一个指定路径的加载器并加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">资源唯一路径</param>
        /// <param name="completeHandler">加载完成回调</param>
        /// <param name="loadAssetPath">加载资源路径模式(外部/Resources/StreamAsset ) default=ResourcesPath</param>
        public static ShaderLoader LoadAssetAsync(string url, System.Action <BaseAbstracResourceLoader> completeHandler)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(ShaderLoader)));
                return(null);
            }
            bool         isContainLoaders = false;
            ShaderLoader shaderLoader     = ResourcesLoaderMgr.GetOrCreateLoaderInstance <ShaderLoader>(url, ref isContainLoaders);

            shaderLoader.m_OnCompleteAct.Add(completeHandler);
            shaderLoader.LoadassetModel = LoadAssetModel.Async; //这里貌似没必要(由于异步加载时候同步加载必定完成了)

            shaderLoader.AddReference(null, url);
            if (isContainLoaders)
            {
                if (shaderLoader.IsCompleted)
                {
                    shaderLoader.OnCompleteLoad(shaderLoader.IsError, shaderLoader.Description, shaderLoader.ResultObj, shaderLoader.IsCompleted);
                }
                return(shaderLoader);
            }

            shaderLoader.m_LoadAssetCoroutine = EventCenter.Instance.StartCoroutine(shaderLoader.LoadShaderAssetAsync(url));
            return(shaderLoader);
        }
Beispiel #11
0
        /// <summary>
        /// 加载Resources 资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="onCompleteAct"></param>
        ///  <param name="isloadScene"> 如果加载的是场景 则这里必须填true ,否则false</param>
        /// <returns></returns>
        protected static ResourcesLoader LoadResourcesAssetSync(string url, System.Action <BaseAbstracResourceLoader> onCompleteAct, bool isloadScene = false)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(WWWLoader)));
                return(null);
            }
            bool            isLoaderExit    = false;
            ResourcesLoader resourcesLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <ResourcesLoader>(url, ref isLoaderExit);

            resourcesLoader.m_OnCompleteAct.Add(onCompleteAct);

            if (isLoaderExit && resourcesLoader.IsCompleted)
            {
                resourcesLoader.LoadassetModel = LoadAssetModel.Sync;                                                                  //这里貌似没必要(由于异步加载时候同步加载必定完成了)
                resourcesLoader.OnCompleteLoad(resourcesLoader.IsError, resourcesLoader.Description, resourcesLoader.ResultObj, true); //如果当前加载器已经完成加载 则手动触发事件
                return(resourcesLoader);                                                                                               //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调
            }

            if (resourcesLoader.LoadassetModel == LoadAssetModel.Async)
            {
                resourcesLoader.ForceBreakLoaderProcess();
            }
            resourcesLoader.LoadassetModel       = LoadAssetModel.Sync; //这里貌似没必要(由于异步加载时候同步加载必定完成了)
            resourcesLoader.m_LoadAssetCoroutine = null;
            resourcesLoader.LoadAssetSync(url, resourcesLoader);
            return(resourcesLoader);
        }
Beispiel #12
0
        /// <summary>
        /// (同步)加载声音资源
        /// </summary>
        /// <param name="requestTarget"></param>
        /// <param name="url"></param>
        /// <param name="completeHandler"></param>
        /// <returns></returns>
        protected static AudioLoader LoadAudioClipSync(Transform requestTarget, string url, System.Action <BaseAbstracResourceLoader> completeHandler)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(AudioLoader)));
                return(null);
            }
            bool        isContainLoaders = false;
            AudioLoader audiolLoader     = ResourcesLoaderMgr.GetOrCreateLoaderInstance <AudioLoader>(url, ref isContainLoaders);

            audiolLoader.m_OnCompleteAct.Add(completeHandler);

            audiolLoader.AddReference(requestTarget, url);
            if (isContainLoaders && audiolLoader.IsCompleted)
            {
                audiolLoader.LoadassetModel = LoadAssetModel.Sync;
                audiolLoader.OnCompleteLoad(audiolLoader.IsError, audiolLoader.Description, audiolLoader.ResultObj, audiolLoader.IsCompleted);
                return(audiolLoader);
            }
            if (audiolLoader.LoadassetModel == LoadAssetModel.Sync)
            {
                audiolLoader.ForceBreakLoaderProcess();
            }
            audiolLoader.LoadassetModel       = LoadAssetModel.Sync;
            audiolLoader.m_LoadAssetCoroutine = null;
            audiolLoader.LoadAudioClicpAssetSync(url);
            return(audiolLoader);
        }
Beispiel #13
0
 public override void OnCompleteLoad(bool isError, string description, object result, bool iscomplete, float process = 1)
 {
     base.OnCompleteLoad(isError, description, result, iscomplete, process);
     ResultObj = result as Shader;
     if (m_BridgeLoader != null)
     {
         ResourcesLoaderMgr.DeleteLoader(typeof(BridgeLoader), m_ResourcesUrl, false);
     }
 }
Beispiel #14
0
        public static void UnLoadAsset(string url, bool isForceDelete = false)
        {
            ResourcesLoader resourcesLoader = ResourcesLoaderMgr.GetExitLoaderInstance <ResourcesLoader>(url);

            if (resourcesLoader == null)
            {
                return;
            }
            resourcesLoader.ReduceReference(resourcesLoader, isForceDelete);
        }
        /// <summary>
        /// 卸载指定的资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="requestTarget">为null 则卸载加载时候请求的对象</param>
        public static void UnLoadAsset(string url, bool isForceDelete = false)
        {
            TextAssetLoader textAssetLoader = ResourcesLoaderMgr.GetExitLoaderInstance <TextAssetLoader>(url);

            if (textAssetLoader == null)
            {
                //Debug.LogError("无法获取指定类型的加载器 " + typeof(TextAssetLoader));
                return;
            }
            textAssetLoader.ReduceReference(textAssetLoader, isForceDelete);
        }
Beispiel #16
0
        /// <summary>
        /// 同步加载资源 (这里处理的是最外层的AssetBundle ,当前资源依赖的AssetBundle 处理在LoadDepdenceAssetBundleAsync)
        /// </summary>
        /// <param name="url"></param>
        protected void LoadAssetBundleSync(string url, string assetFileName, AssetBundleExitState assetBundleState, bool isloadScene)
        {
            m_ResourcesUrl = url;
            if (System.IO.Path.GetExtension(m_ResourcesUrl) != ConstDefine.AssetBundleExtensionName)
            {
                m_ResourcesUrl += ConstDefine.AssetBundleExtensionName;  //组合上扩展名
            }
            #region  加载依赖的资源
            string[] dependenceAssets = AssetBundleMgr.Instance.S_AssetBundleManifest.GetAllDependencies(m_ResourcesUrl); //获取所有的依赖文件
            List <NewAssetBundleLoader3> allDependenceAssetLoader = new List <NewAssetBundleLoader3>();                   //所有依赖文件的加载器
            foreach (var item in dependenceAssets)
            {
                bool isLoaderExit = false;
                NewAssetBundleLoader3 subAssetBundleLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <NewAssetBundleLoader3>(item, ref isLoaderExit);
                if (isLoaderExit && subAssetBundleLoader.IsCompleted)
                {
                    Debug.LogEditorInfor("LoadAssetBundleASync Exit ," + item);
                    continue;  //已经存在了 则继续
                }
                allDependenceAssetLoader.Add(subAssetBundleLoader);
                LoadDepdenceAssetBundleSync(item, subAssetBundleLoader, assetBundleState);
            } //递归加载资源的依赖项


            for (int dex = 0; dex < allDependenceAssetLoader.Count; ++dex)
            {
                if (allDependenceAssetLoader[dex].IsError)
                {
                    Debug.LogError("[AssetBundleLoader] LoadAssetBundleSync  Fail, 依赖的 AssetBundle 资源不存在 " + allDependenceAssetLoader[dex].m_ResourcesUrl);
                    OnCompleteLoad(false, string.Format("[AssetBundleLoader] LoadAssetBundle Fail,AssetBundle Path= {0}", allDependenceAssetLoader[dex].m_ResourcesUrl), null, true);
                    break;
                }
            } //判断依赖项是否加载完成
            #endregion


            #region   AssetBundle  同步加载
            AssetLoaderResultInfor.LoadedAssetBundle = AssetBundle.LoadFromFile(S_AssetBundleTopPath + m_ResourcesUrl);
            if (AssetLoaderResultInfor.LoadedAssetBundle == null)
            {
                ResultObj = null;
                OnCompleteLoad(true, string.Format("同步加载本地AssetBundle 失败{0}", url), null, true, 1);
                return;
            }
            LoadAndRecordAsset(AssetLoaderResultInfor, assetBundleState, isloadScene);

            OnCompleteLoad(AssetLoaderResultInfor.LoadedAssetBundle == null, string.Format("[AssetBundleLoader] LoadAssetBundleSuccess  {0}", m_ResourcesUrl), null, true);
            #endregion

            Debug.LogInfor("加载AssetBundle  成功");
        }
Beispiel #17
0
        /// <summary>
        /// 减少引用计数  (新增在减少引用计数的时候 如果资源没有加载完 则强制结束并释放资源)
        /// </summary>
        /// <param name="loader"></param>
        /// <param name="isForcesDelete"></param>
        public virtual void ReduceReference(BaseAbstracResourceLoader loader, bool isForcesDelete)
        {
            if (loader.IsCompleted == false)
            {
                Debug.LogEditorInfor(string.Format("资源(TypeLoader={0})在加载过程中被中断  url={1}", this.GetType(), m_ResourcesUrl));
                isForcesDelete = true;
                loader.ForceBreakLoaderProcess();
            }  //被中断的加载器

            --ReferCount;
            if (ReferCount <= 0 || isForcesDelete)
            {
                ResourcesLoaderMgr.DeleteLoader(loader.GetType(), m_ResourcesUrl, false);
            }//引用计数为0时候开始回收资源
        }
Beispiel #18
0
        public static void UnLoadAsset(string url, object requestTarget = null)
        {
            MaterialLoader materialLoader = ResourcesLoaderMgr.GetExitLoaderInstance <MaterialLoader>(url);

            if (materialLoader == null)
            {
                //Debug.LogError("无法获取指定类型的加载器 " + typeof(materialLoader));
                return;
            }
            if (requestTarget == null)
            {
                requestTarget = materialLoader.m_RequesterTarget;
            }

            materialLoader.ReduceReference(materialLoader, false);
        }
Beispiel #19
0
        /// <summary>
        /// (同步加载)加载AssetBundle 资源
        /// </summary>
        /// <param name="url">相对于AseetBundle 资源存放路径的路径 (如果是打包成整个预制体则是整个预制体的路径)</param>
        /// <param name="assetFileName">实际加载AssetBundle 时候的文件名称(考虑到加载整个AssetBundle 中一个资源的情况)</param>
        /// <param name="onCompleteAct">加载完成回调</param>
        ///  <param name="isloadSceneAsset"> 如果加载的是场景 则这里必须填true ,否则false</param>
        /// <returns></returns>
        private static NewAssetBundleLoader3 LoadAssetBundleAssetSync(string url, string assetFileName, AssetBundleExitState assetBundleState, bool isloadSceneAsset)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(NewAssetBundleLoader3)));
                return(null);
            }

            if (assetBundleState == AssetBundleExitState.None)
            {
                Debug.LogError("LoadAssetBundleAssetSync Fail,Not AssetBundle Asset" + url + "    assetFileName=" + assetFileName);
                return(null);
            }

            Debug.LogInfor("LoadAssetBundleAsset  url=" + url + "    assetFileName=" + assetFileName);
            bool isLoaderExit = false;
            NewAssetBundleLoader3 assetBundleLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <NewAssetBundleLoader3>(url, ref isLoaderExit);

            if (isLoaderExit && assetBundleLoader.IsCompleted)
            {
                assetBundleLoader.LoadassetModel = LoadAssetModel.Sync;

                //*** 判断当前资源是否加载了
                if (string.IsNullOrEmpty(assetFileName) == false && assetBundleLoader.AssetLoaderResultInfor.m_AllNeedLoadAssetRecord.Contains(assetFileName) == false)
                {
                    assetBundleLoader.AssetLoaderResultInfor.m_AllNeedLoadAssetRecord.Add(assetFileName);
                }
                assetBundleLoader.LoadAndRecordAsset(assetBundleLoader.AssetLoaderResultInfor, assetBundleState, isloadSceneAsset); //加载已经加载的AssetBundle 中的资源

                assetBundleLoader.OnCompleteLoad(assetBundleLoader.IsError, assetBundleLoader.Description, null, true);             //如果当前加载器已经完成加载 则手动触发事件
                return(assetBundleLoader);                                                                                          //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调
            }
            if (assetBundleLoader.LoadassetModel == LoadAssetModel.Async)
            {
                assetBundleLoader.ForceBreakLoaderProcess();
            } //结束之前的加载进程

            assetBundleLoader.LoadassetModel = LoadAssetModel.Sync;
            assetBundleLoader.AssetLoaderResultInfor.SetAssetName(url, assetBundleState);
            assetBundleLoader.m_LoadAssetCoroutine = null;
            if (string.IsNullOrEmpty(assetFileName) == false)
            {
                assetBundleLoader.AssetLoaderResultInfor.m_AllNeedLoadAssetRecord.Add(assetFileName);
            }
            assetBundleLoader.LoadAssetBundleSync(url, assetFileName, assetBundleState, isloadSceneAsset);
            return(assetBundleLoader);
        }
Beispiel #20
0
        /// <summary>
        /// 加载AssetBundle 资源
        /// </summary>
        /// <param name="url">相对于AseetBundle 资源存放路径的路径 (如果是打包成整个预制体则是整个预制体的路径)</param>
        /// <param name="assetFileName">实际加载AssetBundle 时候的文件名称(考虑到加载整个AssetBundle 中一个资源的情况)</param>
        /// <param name="onCompleteAct">加载完成回调</param>
        ///  <param name="isloadSceneAsset"> 如果加载的是场景 则这里必须填true ,否则false</param>
        /// <returns></returns>
        private static NewAssetBundleLoader3 LoadAssetBundleAssetAsync(string url, string assetFileName, AssetBundleExitState assetBundleState, bool isloadSceneAsset)
        {
            if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(assetFileName))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(NewAssetBundleLoader3)));
                return(null);
            }

            if (assetBundleState == AssetBundleExitState.None)
            {
                Debug.LogError("LoadAssetBundleAssetSync Fail,Not AssetBundle Asset" + url + "    assetFileName=" + assetFileName);
                return(null);
            }

            Debug.LogInfor("LoadAssetBundleAsset  url=" + url + "    assetFileName=" + assetFileName);
            bool isLoaderExit = false;
            NewAssetBundleLoader3 assetBundleLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <NewAssetBundleLoader3>(url, ref isLoaderExit);

            assetBundleLoader.LoadassetModel = LoadAssetModel.Async; //这里貌似没必要(由于异步加载时候同步加载必定完成了)

            if (isLoaderExit)
            {
                if (assetBundleLoader.IsCompleted)
                {
                    assetBundleLoader.LoadAndRecordAsset(assetBundleLoader.AssetLoaderResultInfor, assetBundleState, isloadSceneAsset);
                    assetBundleLoader.OnCompleteLoad(assetBundleLoader.IsError, assetBundleLoader.Description, null, true);  //如果当前加载器已经完成加载 则手动触发事件
                }
                else
                {
                    assetBundleLoader.AssetLoaderResultInfor.m_AllNeedLoadAssetRecord.Add(assetFileName); //记录需要加载这个指定的资源
                }
                return(assetBundleLoader);                                                                //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调
            }
            assetBundleLoader.AssetLoaderResultInfor.SetAssetName(url, assetBundleState);
            assetBundleLoader.AssetLoaderResultInfor.m_AllNeedLoadAssetRecord.Add(assetFileName);  //记录需要加载这个指定的资源
            assetBundleLoader.m_LoadAssetCoroutine = EventCenter.Instance.StartCoroutine(assetBundleLoader.LoadAssetBundleASync(url, assetFileName, assetBundleState, isloadSceneAsset));
            return(assetBundleLoader);
        }
Beispiel #21
0
        /// <summary>
        /// 同步加载资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="onCompleteAct"></param>
        /// <param name="isloadSceneAsset"></param>
        /// <returns></returns>
        private static BridgeLoader LoadAssetSync(string url, System.Action <BaseAbstracResourceLoader> onCompleteAct, bool isloadSceneAsset)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(BridgeLoader)));
                return(null);
            }
            bool         isLoaderExit = false;
            BridgeLoader bridgeLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <BridgeLoader>(url, ref isLoaderExit);

            bridgeLoader.m_OnCompleteAct.Add(onCompleteAct);
            bridgeLoader.m_IsLoadSceneAsset = isloadSceneAsset;

            if (isLoaderExit && bridgeLoader.IsCompleted)
            {
                bridgeLoader.LoadassetModel = LoadAssetModel.Sync;
                bridgeLoader.OnCompleteLoad(bridgeLoader.IsError, bridgeLoader.Description, bridgeLoader.ResultObj, true); //如果当前加载器已经完成加载 则手动触发事件
                return(bridgeLoader);                                                                                      //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调
            }
            if (bridgeLoader.LoadassetModel == LoadAssetModel.Async)
            {
                bridgeLoader.ForceBreakLoaderProcess();
            }
            bridgeLoader.LoadassetModel = LoadAssetModel.Sync;
#if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                bridgeLoader.LoadAssetByPriority_Editor(url, bridgeLoader, isloadSceneAsset);
                bridgeLoader.LoadAssetSync(url, bridgeLoader);
                return(bridgeLoader);
            }//编辑器下非运行状态特殊处理
#endif

            bridgeLoader.LoadAssetByPrioritySync(url, bridgeLoader, isloadSceneAsset);
            bridgeLoader.LoadAssetSync(url, bridgeLoader);
            return(bridgeLoader);
        }
Beispiel #22
0
        /// <summary>
        /// (异步)生成一个指定路径的加载器并加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">资源唯一路径</param>
        /// <param name="completeHandler">加载完成回调</param>
        /// <param name="loadModel">加载模式(同步/异步) default=异步</param>
        /// <param name="loadAssetPath">加载资源路径模式(外部/Resources/StreamAsset ) default=ResourcesPath</param>
        protected static ByteLoader LoadAssetAsync(string url, System.Action <BaseAbstracResourceLoader> onCompleteAct)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(ByteLoader)));
                return(null);
            }
            bool       isLoaderExit = false;
            ByteLoader byteLoader   = ResourcesLoaderMgr.GetOrCreateLoaderInstance <ByteLoader>(url, ref isLoaderExit);

            byteLoader.m_OnCompleteAct.Add(onCompleteAct);
            byteLoader.LoadassetModel = LoadAssetModel.Async; //这里貌似没必要(由于异步加载时候同步加载必定完成了)

            if (isLoaderExit)
            {
                if (byteLoader.IsCompleted)
                {
                    byteLoader.OnCompleteLoad(byteLoader.IsError, byteLoader.Description, byteLoader.ResultObj, true); //如果当前加载器已经完成加载 则手动触发事件
                }
                return(byteLoader);                                                                                    //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调
            }
            byteLoader.LoadByteAssetASync(url);
            return(byteLoader);
        }
Beispiel #23
0
 public static void UnLoadScene(string url)
 {
     ResourcesLoaderMgr.DeleteLoader(typeof(SceneLoader), url, true);
 }
Beispiel #24
0
        /// <summary>
        /// 加载当前AssetBundle 依赖的资源(注意 : 这里加载成功之后不能直接生成)
        /// </summary>
        /// <param name="url"></param>
        /// <param name="assetBundleLoade"></param>
        /// <returns></returns>
        protected virtual IEnumerator LoadDepdenceAssetBundleAsync(string url, NewAssetBundleLoader3 depdebceAssetBundleLoader)
        {
            Debug.Log("LoadDepdenceAssetBundleAsync  url=" + url);
            depdebceAssetBundleLoader.m_ResourcesUrl = url;
            if (System.IO.Path.GetExtension(depdebceAssetBundleLoader.m_ResourcesUrl) != ConstDefine.AssetBundleExtensionName)
            {
                depdebceAssetBundleLoader.m_ResourcesUrl += ConstDefine.AssetBundleExtensionName;                                                   //组合上扩展名
            }
            string[] dependenceAssets = AssetBundleMgr.Instance.S_AssetBundleManifest.GetAllDependencies(depdebceAssetBundleLoader.m_ResourcesUrl); //获取所有的依赖文件
            List <NewAssetBundleLoader3> allDependenceAssetLoader = new List <NewAssetBundleLoader3>();                                             //所有依赖文件的加载器

            foreach (var item in dependenceAssets)
            {
                bool isLoaderExit = false;
                NewAssetBundleLoader3 subAssetBundleLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <NewAssetBundleLoader3>(item, ref isLoaderExit);

                if (isLoaderExit && subAssetBundleLoader.IsCompleted)
                {
                    Debug.LogEditorInfor("LoadDepdenceAssetBundleAsync Exit ," + item);
                    continue;
                }
                allDependenceAssetLoader.Add(subAssetBundleLoader);
                Debug.Log("LoadDepdenceAssetBundleAsync  allDependenceAssetLoader   item=" + item);
                EventCenter.Instance.StartCoroutine(LoadDepdenceAssetBundleAsync(item, subAssetBundleLoader));
            } //递归加载资源的依赖项


            for (int dex = 0; dex < allDependenceAssetLoader.Count; ++dex)
            {
                while (allDependenceAssetLoader[dex].IsCompleted == false)
                {
                    yield return(null);
                }

                if (allDependenceAssetLoader[dex].IsError)
                {
                    Debug.LogError("[AssetBundleLoader] LoadDepdenceAssetBundleAsync  Fail, 依赖的 AssetBundle " + url + " 资源不存在 " + allDependenceAssetLoader[dex].m_ResourcesUrl);
                    OnCompleteLoadDepdenceAsset(allDependenceAssetLoader[dex], false,
                                                string.Format("[AssetBundleLoader] LoadAssetBundle Fail,AssetBundle Path={0}" + allDependenceAssetLoader[dex].m_ResourcesUrl), null, true);
                    yield break;
                }
            } //判断依赖项是否加载完成


            #region  AssetBundleCreateRequest 加载
            string fileAbsolutelyPath = string.Format("{0}{1}", S_AssetBundleTopPath, url);  //当先需要下载的资源的绝对路径

            AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(fileAbsolutelyPath);
            yield return(request);

            if (request.isDone)
            {
                Debug.Log("LoadDepdenceAssetBundleAsync Success  depdebceAssetBundleLoader.m_ResourcesUrl=" + depdebceAssetBundleLoader.m_ResourcesUrl);
                depdebceAssetBundleLoader.AssetLoaderResultInfor.LoadedAssetBundle = request.assetBundle;
            }
            else
            {
                depdebceAssetBundleLoader.AssetLoaderResultInfor.LoadedAssetBundle = null;
                Debug.LogError("LoadDepdenceAssetBundleAsync  FailAA==  " + url);
                Debug.LogError("LoadDepdenceAssetBundleAsync  Failbb==  " + fileAbsolutelyPath);
            }
            depdebceAssetBundleLoader.OnCompleteLoad(depdebceAssetBundleLoader.AssetLoaderResultInfor.LoadedAssetBundle == null, string.Format("[AssetBundleLoader] Load DepdenceAssetBundel Success {0}", depdebceAssetBundleLoader.m_ResourcesUrl), null, true);

            #endregion

            //Debug.LogInfor("加载AssetBundle  成功");
            yield break;
        }