示例#1
0
        /// <summary>
        /// 根据不同的加载路径生成不同的资源路径
        /// </summary>
        /// <param name="url"></param>
        /// <param name="loadPathEnum"></param>
        /// <param name="isFileAbsolutelyPath">是否是绝对路径  (使用IO.File 加载时候必须)</param>
        /// <returns></returns>
        public static PathResultEnum GetAssetPathOfLoadAssetPath(ref string url, LoadAssetPathEnum loadPathEnum, bool isFileAbsolutelyPath, AssetTypeTag assetType = AssetTypeTag.None)
        {
            if (string.IsNullOrEmpty(url))
            {
                Debug.LogError("无法识别的路径 " + url);
                return(PathResultEnum.Invalid);
            }

            switch (loadPathEnum)
            {
            case LoadAssetPathEnum.PersistentDataPath:
                url = ConstDefine.S_PersistentDataPath + url;
                return(PathResultEnum.Valid);

            case LoadAssetPathEnum.ResourcesPath:
                //if (assetType == AssetTypeTag.ShaderAsset)
                //    return PathResultEnum.Valid;  //Shade 路径不处理
                if (isFileAbsolutelyPath)
                {
                    url = ConstDefine.S_ResourcesPath + url;
                }
                return(PathResultEnum.Valid);

            //case LoadAssetPathEnum.StreamingAssetsPath:
            //    return PathResultEnum.Valid;
            //case LoadAssetPathEnum.EditorAssetDataPath:
            //    return PathResultEnum.Valid;
            default:
                break;
            }

            Debug.LogError("没有配置的路径");
            return(PathResultEnum.Invalid);
        }
 /// <summary>Oa
 /// 根据当前的加载路径获取下一个第一级优先级的路径枚举
 /// </summary>
 /// <param name="curAssetPath">返回是否</param>
 /// <returns></returns>
 public void GetNextLoadAssetPath(ref LoadAssetPathEnum curAssetPath)
 {
     for (int dex = 0; dex < m_LoadAssetPathOfPriority.Count - 1; ++dex)
     {
         if (m_LoadAssetPathOfPriority[dex].m_AssetPathEnum == curAssetPath)
         {
             curAssetPath = m_LoadAssetPathOfPriority[dex + 1].m_AssetPathEnum;
             return;
         }
     }
     curAssetPath = LoadAssetPathEnum.None;
 }
示例#3
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);
        }
示例#4
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;  //如果加载成功不会执行到这里
        }