Exemplo n.º 1
0
        public void InitResMgr()
        {
            if (AssetBundlePathHelper.SimulationMode)
            {
                AssetBundleSettings.AssetBundleConfigFile = ConfigFileUtility.BuildEditorDataTable();
            }
            else
            {
                AssetBundleSettings.AssetBundleConfigFile.Reset();

                var outResult = new List <string>();

                // 未进行过热更
                if (AssetBundleSettings.LoadAssetResFromStreamingAssetsPath)
                {
                    ResKit.Architecture.Interface.GetUtility <IZipFileHelper>()
                    .GetFileInInner(ResDatas.FileName, outResult);
                }
                // 进行过热更
                else
                {
                    AssetBundlePathHelper.GetFileInFolder(AssetBundlePathHelper.PersistentDataPath, ResDatas.FileName,
                                                          outResult);
                }

                foreach (var outRes in outResult)
                {
                    AssetBundleSettings.AssetBundleConfigFile.LoadFromFile(outRes);
                }
            }
        }
Exemplo n.º 2
0
        public void GetFileInInner(string fileName, List <string> outResult)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            //Android 包内
            GetFileInZip(mZipFile, fileName, outResult);
            return;
#endif
            AssetBundlePathHelper.GetFileInFolder(AssetBundlePathHelper.StreamingAssetsPath, fileName, outResult);
        }
Exemplo n.º 3
0
        public static string AssetBundleName2Url(string name)
        {
            string retUrl = AssetBundlePathHelper.PersistentDataPath + "AssetBundles/" +
                            AssetBundlePathHelper.GetPlatformName() + "/" + name;

            if (File.Exists(retUrl))
            {
                return(retUrl);
            }

            return(AssetBundlePathHelper.StreamingAssetsPath + "AssetBundles/" +
                   AssetBundlePathHelper.GetPlatformName() + "/" + name);
        }
Exemplo n.º 4
0
        public static string AssetBundleUrl2Name(string url)
        {
            string retName = null;
            string parren  = AssetBundlePathHelper.StreamingAssetsPath + "AssetBundles/" +
                             AssetBundlePathHelper.GetPlatformName() + "/";

            retName = url.Replace(parren, "");

            parren = AssetBundlePathHelper.PersistentDataPath + "AssetBundles/" +
                     AssetBundlePathHelper.GetPlatformName() + "/";
            retName = retName.Replace(parren, "");
            return(retName);
        }
Exemplo n.º 5
0
        public IEnumerator InitResMgrAsync()
        {
            if (AssetBundlePathHelper.SimulationMode)
            {
                AssetBundleSettings.AssetBundleConfigFile = ConfigFileUtility.BuildEditorDataTable();
                yield return(null);
            }
            else
            {
                AssetBundleSettings.AssetBundleConfigFile.Reset();

                var outResult = new List <string>();

                var pathPrefix = AssetBundlePathHelper.PathPrefix;

                // 未进行过热更
                if (AssetBundleSettings.LoadAssetResFromStreamingAssetsPath)
                {
                    var streamingPath = Application.streamingAssetsPath + "/AssetBundles/" +
                                        AssetBundlePathHelper.GetPlatformName() + "/" + ResDatas.FileName;
                    outResult.Add(pathPrefix + streamingPath);
                }
                // 进行过热更
                else
                {
                    var persistentPath = Application.persistentDataPath + "/AssetBundles/" +
                                         AssetBundlePathHelper.GetPlatformName() + "/" + ResDatas.FileName;
                    outResult.Add(pathPrefix + persistentPath);
                }

                foreach (var outRes in outResult)
                {
                    Log.I(outRes);
                    yield return(AssetBundleSettings.AssetBundleConfigFile.LoadFromFileAsync(outRes));
                }

                yield return(null);
            }
        }
Exemplo n.º 6
0
 private static string GetPlatformName()
 {
     return(AssetBundlePathHelper.GetPlatformName());
 }
Exemplo n.º 7
0
        public override bool LoadSync()
        {
            if (!CheckLoadAble())
            {
                return(false);
            }

            if (string.IsNullOrEmpty(AssetBundleName))
            {
                return(false);
            }


            Object obj = null;

            if (AssetBundlePathHelper.SimulationMode && !string.Equals(mAssetName, "assetbundlemanifest"))
            {
                var resSearchKeys = ResSearchKeys.Allocate(AssetBundleName, null, typeof(AssetBundle));

                var abR = ResMgr.Instance.GetRes <AssetBundleRes>(resSearchKeys);
                resSearchKeys.Recycle2Cache();

                var assetPaths = AssetBundlePathHelper.GetAssetPathsFromAssetBundleAndAssetName(abR.AssetName, mAssetName);
                if (assetPaths.Length == 0)
                {
                    Log.E("Failed Load Asset:" + mAssetName);
                    OnResLoadFaild();
                    return(false);
                }

                HoldDependRes();

                State = ResState.Loading;

                if (AssetType != null)
                {
                    obj = AssetBundlePathHelper.LoadAssetAtPath(assetPaths[0], AssetType);
                }
                else
                {
                    obj = AssetBundlePathHelper.LoadAssetAtPath <Object>(assetPaths[0]);
                }
            }
            else
            {
                var resSearchKeys = ResSearchKeys.Allocate(AssetBundleName, null, typeof(AssetBundle));
                var abR           = ResMgr.Instance.GetRes <AssetBundleRes>(resSearchKeys);
                resSearchKeys.Recycle2Cache();


                if (abR == null || !abR.AssetBundle)
                {
                    Log.E("Failed to Load Asset, Not Find AssetBundleImage:" + AssetBundleName);
                    return(false);
                }

                HoldDependRes();

                State = ResState.Loading;

                if (AssetType != null)
                {
                    obj = abR.AssetBundle.LoadAsset(mAssetName, AssetType);
                }
                else
                {
                    obj = abR.AssetBundle.LoadAsset(mAssetName);
                }
            }

            UnHoldDependRes();

            if (obj == null)
            {
                Log.E("Failed Load Asset:" + mAssetName + ":" + AssetType + ":" + AssetBundleName);
                OnResLoadFaild();
                return(false);
            }

            mAsset = obj;

            State = ResState.Ready;
            return(true);
        }
Exemplo n.º 8
0
        public override IEnumerator DoLoadAsync(System.Action finishCallback)
        {
            if (RefCount <= 0)
            {
                OnResLoadFaild();
                finishCallback();
                yield break;
            }


            //Object obj = null;
            var resSearchKeys = ResSearchKeys.Allocate(AssetBundleName, null, typeof(AssetBundle));
            var abR           = ResMgr.Instance.GetRes <AssetBundleRes>(resSearchKeys);

            resSearchKeys.Recycle2Cache();

            if (AssetBundlePathHelper.SimulationMode && !string.Equals(mAssetName, "assetbundlemanifest"))
            {
                var assetPaths = AssetBundlePathHelper.GetAssetPathsFromAssetBundleAndAssetName(abR.AssetName, mAssetName);
                if (assetPaths.Length == 0)
                {
                    Log.E("Failed Load Asset:" + mAssetName);
                    OnResLoadFaild();
                    finishCallback();
                    yield break;
                }

                //确保加载过程中依赖资源不被释放:目前只有AssetRes需要处理该情况
                HoldDependRes();
                State = ResState.Loading;

                // 模拟等一帧
                yield return(new WaitForEndOfFrame());

                UnHoldDependRes();

                if (AssetType != null)
                {
                    mAsset = AssetBundlePathHelper.LoadAssetAtPath(assetPaths[0], AssetType);
                }
                else
                {
                    mAsset = AssetBundlePathHelper.LoadAssetAtPath <Object>(assetPaths[0]);
                }
            }
            else
            {
                if (abR == null || abR.AssetBundle == null)
                {
                    Log.E("Failed to Load Asset, Not Find AssetBundleImage:" + AssetBundleName);
                    OnResLoadFaild();
                    finishCallback();
                    yield break;
                }


                HoldDependRes();

                State = ResState.Loading;

                AssetBundleRequest abQ = null;

                if (AssetType != null)
                {
                    abQ = abR.AssetBundle.LoadAssetAsync(mAssetName, AssetType);
                    mAssetBundleRequest = abQ;

                    yield return(abQ);
                }
                else
                {
                    abQ = abR.AssetBundle.LoadAssetAsync(mAssetName);
                    mAssetBundleRequest = abQ;

                    yield return(abQ);
                }

                mAssetBundleRequest = null;

                UnHoldDependRes();

                if (!abQ.isDone)
                {
                    Log.E("Failed Load Asset:" + mAssetName);
                    OnResLoadFaild();
                    finishCallback();
                    yield break;
                }

                mAsset = abQ.asset;
            }

            State = ResState.Ready;

            finishCallback();
        }