Beispiel #1
0
        // Hotfix测试---用于侧测试资源模块的热修复
        //public void TestHotfix()
        //{
        //    Logger.Log("********** AssetBundleManager : Call TestHotfix in cs...");
        //}
#endif

        public IEnumerator Initialize()
        {
#if UNITY_EDITOR
            if (AssetBundleConfig.IsEditorMode)
            {
                yield break;
            }
#endif

            manifest          = new Manifest();
            assetsPathMapping = new AssetsPathMapping();
            // 说明:同时请求资源可以提高加载速度
            var manifestRequest = RequestAssetBundleAsync(manifest.AssetbundleName);
            var pathMapRequest  = RequestAssetBundleAsync(assetsPathMapping.AssetbundleName);

            yield return(manifestRequest);

            var assetbundle = manifestRequest.assetbundle;
            manifest.LoadFromAssetbundle(assetbundle);
            assetbundle.Unload(false);
            manifestRequest.Dispose();

            yield return(pathMapRequest);

            assetbundle = pathMapRequest.assetbundle;
            var mapContent = assetbundle.LoadAsset <TextAsset>(assetsPathMapping.AssetName);
            if (mapContent != null)
            {
                assetsPathMapping.Initialize(mapContent.text);
            }
            assetbundle.Unload(true);
            pathMapRequest.Dispose();

            yield break;
        }
        public IEnumerator Initialize()
        {
#if UNITY_EDITOR
            if (AssetBundleConfig.IsEditorMode)
            {
                yield break;
            }
#endif

            manifest = new Manifest();
            assetsPathMapping = new AssetsPathMapping();
            // 说明:同时请求资源可以提高加载速度
            var manifestRequest = RequestAssetBundleAsync(manifest.AssetbundleName);
            var pathMapRequest = RequestAssetBundleAsync(assetsPathMapping.AssetbundleName);

            yield return manifestRequest;
            var assetbundle = manifestRequest.assetbundle;
            manifest.LoadFromAssetbundle(assetbundle);
            assetbundle.Unload(false);
            manifestRequest.Dispose();

            yield return pathMapRequest;
            assetbundle = pathMapRequest.assetbundle;
            var mapContent = assetbundle.LoadAsset<TextAsset>(assetsPathMapping.AssetName);
            if (mapContent != null)
            {
                assetsPathMapping.Initialize(mapContent.text);
            }
            assetbundle.Unload(true);
            pathMapRequest.Dispose();

            // 设置所有公共包为常驻包
            var start = DateTime.Now;
            var allAssetbundleNames = manifest.GetAllAssetBundleNames();
            foreach (var curAssetbundleName in allAssetbundleNames)
            {
                if (string.IsNullOrEmpty(curAssetbundleName))
                {
                    continue;
                }

                int count = 0;
                foreach (var checkAssetbundle in allAssetbundleNames)
                {
                    if (checkAssetbundle == curAssetbundleName || string.IsNullOrEmpty(checkAssetbundle))
                    {
                        continue;
                    }

                    var allDependencies = manifest.GetAllDependencies(checkAssetbundle);
                    if (Array.IndexOf(allDependencies, curAssetbundleName) >= 0)
                    {
                        count++;
                        if (count >= 2)
                        {
                            break;
                        }
                    }
                }

                // 说明:设置被依赖数量为1的AB包为常驻包的理由详细情况见AssetBundleAsyncLoader.cs那一大堆注释
                // TODO:1)目前已知Unity5.3版本和Unity5.5版本没问题,其它试过的几个版本都有问题,如果你使用的版本也有问题,需要修改这里的宏
                //       2)整套AB包括压缩格式可能都要重新设计,这个以后有时间再去尝试
#if !UNITY_5_3 && !UNITY_5_5
                if (count >= 1)
#else
                if (count >= 2)
#endif
                {
                    SetAssetBundleResident(curAssetbundleName, true);
                }
            }
            Logger.Log(string.Format("AssetBundleResident Initialize use {0}ms", (DateTime.Now - start).Milliseconds));
            IsInitialized = true;
            yield break;
        }
Beispiel #3
0
        public IEnumerator Initialize()
        {
#if UNITY_EDITOR
            if (AssetBundleConfig.IsEditorMode)
            {
                yield break;
            }
#endif

            manifest          = new Manifest();
            assetsPathMapping = new AssetsPathMapping();
            // 说明:同时请求资源可以提高加载速度
            var manifestRequest = RequestAssetBundleAsync(manifest.AssetbundleName);
            var pathMapRequest  = RequestAssetBundleAsync(assetsPathMapping.AssetbundleName);

            yield return(manifestRequest);

            var assetbundle = manifestRequest.assetbundle;
            manifest.LoadFromAssetbundle(assetbundle);
            assetbundle.Unload(false);
            manifestRequest.Dispose();

            yield return(pathMapRequest);

            assetbundle = pathMapRequest.assetbundle;
            var mapContent = assetbundle.LoadAsset <TextAsset>(assetsPathMapping.AssetName);
            if (mapContent != null)
            {
                assetsPathMapping.Initialize(mapContent.text);
            }
            assetbundle.Unload(true);
            pathMapRequest.Dispose();

            // 设置所有公共包为常驻包
            var start = DateTime.Now;
            var allAssetbundleNames = manifest.GetAllAssetBundleNames();
            foreach (var curAssetbundleName in allAssetbundleNames)
            {
                if (string.IsNullOrEmpty(curAssetbundleName))
                {
                    continue;
                }

                int count = 0;
                foreach (var checkAssetbundle in allAssetbundleNames)
                {
                    if (checkAssetbundle == curAssetbundleName || string.IsNullOrEmpty(checkAssetbundle))
                    {
                        continue;
                    }

                    var allDependencies = manifest.GetAllDependencies(checkAssetbundle);
                    if (Array.IndexOf(allDependencies, curAssetbundleName) >= 0)
                    {
                        count++;
                        if (count >= 2)
                        {
                            break;
                        }
                    }
                }

                if (count >= 2)
                {
                    SetAssetBundleResident(curAssetbundleName, true);
                }
            }
            Logger.Log(string.Format("AssetBundleResident Initialize use {0}ms", (DateTime.Now - start).Milliseconds));
            yield break;
        }
Beispiel #4
0
        public IEnumerator Initialize()
        {
//#if UNITY_EDITOR
//            if (AssetBundleConfig.IsEditorMode)
//            {
//                yield break;
//            }
//#endif

            manifest          = new Manifest();
            assetsPathMapping = new AssetsPathMapping();
            // 说明:同时请求资源可以提高加载速度
            var manifestRequest = RequestAssetBundleAsync(manifest.AssetbundleName);
            var pathMapRequest  = RequestAssetBundleAsync(assetsPathMapping.AssetbundleName);

            yield return(manifestRequest);

            var assetbundle = manifestRequest.assetbundle;

            manifest.LoadFromAssetbundle(assetbundle);
            assetbundle.Unload(false);
            manifestRequest.Dispose();

            yield return(pathMapRequest);

            assetbundle = pathMapRequest.assetbundle;
            var mapContent = assetbundle.LoadAsset <TextAsset>(assetsPathMapping.AssetName);

            if (mapContent != null)
            {
                assetsPathMapping.Initialize(mapContent.text);
            }
            assetbundle.Unload(true);
            pathMapRequest.Dispose();

            {
                idpManifest          = new Manifest();
                idpAssetsPathMapping = new AssetsPathMapping();
                var idpManifestRequest = RequestIndependentAssetBundleAsync(idpManifest.AssetbundleName);
                var idpPathMapRequest  = RequestIndependentAssetBundleAsync(idpAssetsPathMapping.AssetbundleName);

                yield return(idpManifestRequest);

                assetbundle = idpManifestRequest.assetbundle;
                idpManifest.LoadFromAssetbundle(assetbundle);
                assetbundle.Unload(false);
                idpManifestRequest.Dispose();

                yield return(idpPathMapRequest);

                assetbundle = idpPathMapRequest.assetbundle;
                mapContent  = assetbundle.LoadAsset <TextAsset>(idpAssetsPathMapping.AssetName);
                if (mapContent != null)
                {
                    idpAssetsPathMapping.Initialize(mapContent.text);
                }
                assetbundle.Unload(true);
                idpPathMapRequest.Dispose();
            }

            // 设置所有公共包为常驻包
            var start = DateTime.Now;

            string path = "";

            if (Core.Resource.FileUtil.FileExist("dependencies_res.txt", ref path))
            {
                byte[] bs  = Core.Resource.FileUtil.LoadResourceByWWW(path);
                string res = System.Text.Encoding.Default.GetString(bs);

                string[] strList2 = res.Split('\n');
                for (int i = 0; i <= strList2.Length - 1; i++)
                {
                    string[] strList = strList2[i].Split('\t');
                    if (strList[0] != "")
                    {
                        SetAssetBundleResident(strList[0], true);
                    }
                }
            }
            else
            {
                Debug.LogError("打开 dependencies_res.txt 路径失败!");
            }
            Debug.Log(string.Format("AssetBundleResident Initialize use {0}ms", (DateTime.Now - start).Milliseconds));
            IsInitialized = true;
            yield break;
        }