Пример #1
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);
        }
Пример #2
0
        public static void UnLoadAsset(string url, bool isForceDelete = false)
        {
            ResourcesLoader resourcesLoader = ResourcesLoaderMgr.GetExitLoaderInstance <ResourcesLoader>(url);

            if (resourcesLoader == null)
            {
                return;
            }
            resourcesLoader.ReduceReference(resourcesLoader, isForceDelete);
        }
Пример #3
0
 /// <summary>
 /// 同步加载Resources 资源
 /// </summary>
 /// <param name="url"></param>
 /// <param name="resourcesLoader"></param>
 private void LoadAssetSync(string url, ResourcesLoader resourcesLoader)
 {
     m_ResourcesUrl = url;
     ResultObj      = Resources.Load(url);
     if (ResultObj == null)
     {
         resourcesLoader.OnCompleteLoad(true, string.Format("[ResourcesLoader]  Load Resource Asset Fail,Not Exit {0} ", url), null, true);
     }
     else
     {
         resourcesLoader.OnCompleteLoad(false, string.Format("[ResourcesLoader]  Load Resource Asset Success: {0}", url), ResultObj, true);
     }
 }
Пример #4
0
        /// <summary>
        ///只在编辑器下可用
        /// </summary>
        /// <param name="bridgeLoader"></param>
        /// <param name="url"></param>
        /// <param name="isloadScene"> 如果加载的是场景 则这里必须填true ,否则false</param>
        /// <returns></returns>
        private void LoadAssetByPriority_Editor(string url, BridgeLoader bridgeLoader, bool isloadSceneAsset)
        {
            LoadAssetPathEnum curLoadAssetPathEnum = ApplicationConfig.GetDefaultEditorLoadAssetPath();
            string            fileName             = System.IO.Path.GetFileNameWithoutExtension(url);

            if (curLoadAssetPathEnum == LoadAssetPathEnum.ResourcesPath)
            {
                bridgeLoader.m_ConnectLoader = ResourcesLoader.LoadResourcesAsset(url, LoadAssetModel.Sync, null, isloadSceneAsset);
                if (bridgeLoader.m_ConnectLoader.ResultObj != null)
                {
                    return;
                }
                else
                {
                    Debug.LogError("加载资源失败  url" + url);
                }
            }

            Debug.LogError("LoadAssetByPriority_Editor  Fail,  无法识别的模式 " + curLoadAssetPathEnum);
        }
Пример #5
0
        /// <summary>
        /// 异步加载Resources 资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="resourcesLoader"></param>
        /// <returns></returns>
        private IEnumerator LoadAssetAsync(string url, ResourcesLoader resourcesLoader)
        {
            m_ResourcesUrl = url;
            ResourceRequest resourcesRequest = Resources.LoadAsync(url);

            while (resourcesRequest.isDone == false)
            {
                Process = resourcesRequest.progress;
                yield return(null);
            }

            if (resourcesRequest.asset == null)
            {
                resourcesLoader.OnCompleteLoad(true, string.Format("[ResourcesLoader] Load Resource Asset Fail,Not Exit {0}", url), null, true);
            }
            else
            {
                resourcesLoader.OnCompleteLoad(false, string.Format("[ResourcesLoader]  Load Resource Asset Success: {0}", url), resourcesRequest.asset, true);
            }

            yield break;
        }
Пример #6
0
        /// <summary>
        /// 根据配置的路径加载优先级 选择合适的加载器加载资源  (可能存在加载不到资源的情况,目前只处理LoadAssetPathEnum.PersistentDataPath和PersistentDataPath.ResourcesPath)
        /// </summary>
        /// <param name="bridgeLoader"></param>
        /// <param name="url"></param>
        /// <param name="isloadScene"> 如果加载的是场景 则这里必须填true ,否则false</param>
        /// <returns></returns>
        private IEnumerator LoadAssetByPriorityAsync(string url, BridgeLoader bridgeLoader, bool isloadSceneAsset)
        {
            LoadAssetPathEnum curLoadAssetPathEnum = ApplicationConfig.Instance.GetFirstPriortyAssetPathEnum();  //加载的优先级
            string            fileName             = System.IO.Path.GetFileNameWithoutExtension(url);

            do
            {
                if (curLoadAssetPathEnum == LoadAssetPathEnum.PersistentDataPath)
                {
                    AssetBundleExitState assetBundleExitState;
                    string newUrl = HotUpdate.AssetBundleMgr.Instance.CheckIfAssetBundleAsset(url.ToLower(), out assetBundleExitState);

                    if (assetBundleExitState != AssetBundleExitState.None)
                    {
                        Debug.Log("[AssetBundler ]加载外部资源,且以AssetBundle 加载");
                        bridgeLoader.m_ConnectLoader = NewAssetBundleLoader3.LoadAssetBundleAsset(newUrl, fileName, LoadAssetModel.Async, assetBundleExitState, isloadSceneAsset);   //整体打包的资源
                    }
                    else
                    {
                        if (isloadSceneAsset == false)
                        {
                            Debug.Log("[byteLoader ]优先加载外部资源,但是不是AssetBundle 资源,则以Byte[] 尝试 加载");
                            string path = url;
                            if (url.StartsWith(ConstDefine.S_AssetBundleTopPath) == false)
                            {
                                path = ConstDefine.S_AssetBundleTopPath + url;
                            }
                            bridgeLoader.m_ConnectLoader = ByteLoader.LoadAsset(path, LoadAssetModel.Async, null);
                        }
                        else
                        {
                            //***场景资源不通过这种方式
                        }
                    }
                }
                else if (curLoadAssetPathEnum == LoadAssetPathEnum.ResourcesPath)
                {
                    Debug.Log("[RecourcsLoader ]  加载Resources 资源 " + url);
                    bridgeLoader.m_ConnectLoader = ResourcesLoader.LoadResourcesAsset(url, LoadAssetModel.Async, null, isloadSceneAsset);
                }

                while (bridgeLoader.m_ConnectLoader.IsCompleted == false)
                {
                    yield return(null);
                }

                if (curLoadAssetPathEnum == LoadAssetPathEnum.PersistentDataPath && (bridgeLoader.m_ConnectLoader.GetType() == typeof(NewAssetBundleLoader3)))
                {
                    NewAssetBundleLoader3 assetBundleLoader = bridgeLoader.m_ConnectLoader as NewAssetBundleLoader3;
                    if (assetBundleLoader.AssetLoaderResultInfor.GetAssetByUrl(assetBundleLoader.m_ResourcesUrl, fileName) != null)
                    {
                        yield break;
                    }
                }
                else
                {
                    if (bridgeLoader.m_ConnectLoader.ResultObj != null)
                    {
                        yield break;
                    }
                }
                //    bridgeLoader.m_ConnectLoader.ReduceReference(bridgeLoader.m_ConnectLoader, false);  //卸载这个加载器
                ApplicationConfig.Instance.GetNextLoadAssetPath(ref curLoadAssetPathEnum);
                continue;  //如果加载得到则返回否则继续尝试其他的加载方式
            } while (curLoadAssetPathEnum != LoadAssetPathEnum.None);
            Debug.LogError("如果加载成功不会执行到这里" + url);
            bridgeLoader.m_ConnectLoader = null;  //如果加载成功不会执行到这里
        }