Beispiel #1
0
        static void BuildAssetBundles()
        {
            var outputPath = Application.streamingAssetsPath + "/AssetBundles/" + ResKitUtil.GetPlatformName();

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.ChunkBasedCompression,
                                            EditorUserBuildSettings.activeBuildTarget);

            AssetDatabase.Refresh();
        }
Beispiel #2
0
        private void Load()
        {
            if (ResMgr.IsSimulationModeLogic)
            {
#if UNITY_EDITOR
                var assetBundleNames = UnityEditor.AssetDatabase.GetAllAssetBundleNames();

                foreach (var assetBundleName in assetBundleNames)
                {
                    var assetPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);

                    var assetBundleData = new AssetBundleData
                    {
                        Name = assetBundleName,
                        DependencyBundleNames =
                            UnityEditor.AssetDatabase.GetAssetBundleDependencies(assetBundleName, false)
                    };

                    foreach (var assetPath in assetPaths)
                    {
                        var assetData = new AssetData
                        {
                            OwnerBundleName = assetBundleName,
                            // 通过路径获取名字
                            Name = assetPath
                                   .Split('/').Last()
                                   .Split('.').First()
                        };

                        assetBundleData.AssetDataList.Add(assetData);
                    }

                    AssetBundleDatas.Add(assetBundleData);
                }
#endif
            }
            else
            {
                var mainBundle =
                    AssetBundle.LoadFromFile(ResKitUtil.FullPathForAssetBundle(ResKitUtil.GetPlatformName()));

                mManifest = mainBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
            }
        }
Beispiel #3
0
        public IEnumerator InitResMgrAsync()
        {
#if UNITY_EDITOR
            if (Res.SimulateAssetBundleInEditor)
            {
                ResKit.ResDatas = EditorRuntimeAssetDataCollector.BuildDataTable();
                yield return(null);
            }
            else
#endif
            {
                ResKit.ResDatas.Reset();

                var    outResult  = new List <string>();
                string pathPrefix = "";
#if UNITY_EDITOR || UNITY_IOS
                pathPrefix = "file://";
#endif
                // 未进行过热更
                if (ResKit.LoadResFromStreammingAssetsPath)
                {
                    string streamingPath = Application.streamingAssetsPath + "/AssetBundles/" +
                                           ResKitUtil.GetPlatformName() + "/" + ResKit.ResDatas.FileName;
                    outResult.Add(pathPrefix + streamingPath);
                }
                // 进行过热更
                else
                {
                    string persistenPath = Application.persistentDataPath + "/AssetBundles/" +
                                           ResKitUtil.GetPlatformName() + "/" + ResKit.ResDatas.FileName;
                    outResult.Add(pathPrefix + persistenPath);
                }

                foreach (var outRes in outResult)
                {
                    Debug.Log(outRes);
                    yield return(ResKit.ResDatas.LoadFromFileAsync(outRes));
                }

                yield return(null);
            }
        }
Beispiel #4
0
        public IEnumerator InitResMgrAsync()
        {
#if UNITY_EDITOR
            if (Res.SimulateAssetBundleInEditor)
            {
                EditorRuntimeAssetDataCollector.BuildDataTable();
                yield return(null);
            }
            else
#endif
            {
                ResDatas.Instance.Reset();

                var outResult = new List <string>();

                // 未进行过热更
                if (ResKit.LoadResFromStreammingAssetsPath)
                {
                    outResult.Add(Application.streamingAssetsPath + "/AssetBundles/" + ResKitUtil.GetPlatformName() + "/asset_bindle_config.bin");
                }
                // 进行过热更
                else
                {
                    outResult.Add(Application.persistentDataPath + "/AssetBundles/" + ResKitUtil.GetPlatformName() + "/asset_bindle_config.bin");
                }

                foreach (var outRes in outResult)
                {
                    Debug.Log(outRes);
                    yield return(ResDatas.Instance.LoadFromFileAsync(outRes));
                }

                yield return(null);
            }

            ResDatas.Instance.SwitchLanguage("cn");
        }