/// <summary>
        ///
        /// </summary>
        void LoadData()
        {
            asset_bundle_build_ = new AssetBundleBuild();
            if (!asset_bundle_build_.Load(EditorCommon.ASSETBUNDLE_BUILD_RULE_FILE_PATH))
            {
                if (EditorUtility.DisplayDialog("初始化打包配置文件", "当前打包配置文件不存在, 需要生成默认配置文件!", "生成"))
                {
                    float total = 0;
                    if (Directory.Exists(EditorCommon.SCENE_START_PATH))
                    {
                        string[] files = Directory.GetFiles(EditorCommon.SCENE_START_PATH, "*.unity", SearchOption.AllDirectories);
                        total += files.Length;
                    }
                    if (Directory.Exists(asset_bundle_build_.BuildStartFullPath))
                    {
                        string[] dirs = Directory.GetDirectories(asset_bundle_build_.BuildStartFullPath, "*", SearchOption.AllDirectories);
                        total += dirs.Length;
                    }

                    float current = 0f;
                    asset_bundle_build_.GenerateDefaultData((name) =>
                    {
                        //进度条提示
                        current       += 1.0f;
                        float progress = current / total;
                        EditorUtility.DisplayProgressBar("初始化打包配置文件", "正在初始化 " + name, progress);
                    });

                    EditorUtility.ClearProgressBar();
                    Build();
                }
            }
            else
            {
                if (EditorUtility.DisplayDialog("更新打包配置文件", "是否需要更新打包配置文件!(不执行更新可能会导致资源变更无法被正确识别)", "更新", "不更新"))
                {
                    float total = 0;
                    if (Directory.Exists(EditorCommon.SCENE_START_PATH))
                    {
                        string[] files = Directory.GetFiles(EditorCommon.SCENE_START_PATH, "*.unity", SearchOption.AllDirectories);
                        total += files.Length;
                    }
                    if (Directory.Exists(asset_bundle_build_.BuildStartFullPath))
                    {
                        string[] dirs = Directory.GetDirectories(asset_bundle_build_.BuildStartFullPath, "*", SearchOption.AllDirectories);
                        total += dirs.Length;
                    }

                    float current = 0f;
                    asset_bundle_build_.MatchData((name) =>
                    {
                        //进度条提示
                        current       += 1.0f;
                        float progress = current / total;
                        EditorUtility.DisplayProgressBar("更新打包配置文件", "正在更新 " + name, progress);
                    });
                    EditorUtility.ClearProgressBar();
                }

                Build();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 void LoadData()
 {
     asset_bundle_build_ = new AssetBundleBuild();
     asset_bundle_build_.Load(AssetBundleBuild.FILE_FULL_NAME);
     Build();
 }
        /// <summary>
        /// 根据AssetBundle导出ResourcesManifest文件
        /// </summary>
        public static ResourcesManifest ExportResourcesManifestFile(AssetBundleBuild build, AssetBundleManifest manifest)
        {
            ResourcesManifest info = new ResourcesManifest();

            //读取所有AssetBundle
            string        root_dir = EditorCommon.BUILD_PATH + "/";
            List <string> scenes   = new List <string>();

            if (manifest != null)
            {
                //读取主AssetBundle
                ResourcesManifestData.AssetBundle desc = new ResourcesManifestData.AssetBundle();
                desc.AssetBundleName = Common.MAIN_MANIFEST_FILE_NAME;
                desc.Size            = zcode.FileHelper.GetFileSize(root_dir + Common.MAIN_MANIFEST_FILE_NAME);
                info.Data.AssetBundles.Add(Common.MAIN_MANIFEST_FILE_NAME, desc);

                //读取其它AssetBundle
                foreach (var name in manifest.GetAllAssetBundles())
                {
                    desc = new ResourcesManifestData.AssetBundle();
                    desc.AssetBundleName = name;
                    desc.Size            = zcode.FileHelper.GetFileSize(root_dir + name);
                    AssetBundle ab = AssetBundle.LoadFromFile(root_dir + name);
                    foreach (var asset in ab.GetAllAssetNames())
                    {
                        desc.Assets.Add(asset);
                    }
                    foreach (var scene in ab.GetAllScenePaths())
                    {
                        desc.Scenes.Add(scene);
                        scenes.Add(scene);
                    }
                    ab.Unload(false);

                    info.Data.AssetBundles.Add(name, desc);
                }
            }

            //读取所有Scene信息
            for (int i = 0; i < scenes.Count; ++i)
            {
                ResourcesManifestData.Scene scene_desc = new ResourcesManifestData.Scene();
                scene_desc.SceneLevelName  = Path.GetFileNameWithoutExtension(scenes[i]);
                scene_desc.ScenePath       = scenes[i];
                scene_desc.SceneConfigPath = SceneConfig.GetSceneConfigPath(scenes[i]);
                info.Data.Scenes.Add(scene_desc.SceneLevelName, scene_desc);
            }

            //读取旧的ResourcesInfo,同步其它额外的数据
            ResourcesManifest old_info = new ResourcesManifest();

            old_info.Load(EditorCommon.RESOURCES_MANIFEST_FILE_PATH);
            if (old_info.Data != null && old_info.Data.AssetBundles.Count > 0)
            {
                foreach (var desc in old_info.Data.AssetBundles.Values)
                {
                    if (info.Data.AssetBundles.ContainsKey(desc.AssetBundleName))
                    {
                        info.Data.AssetBundles[desc.AssetBundleName].IsNative    = desc.IsNative;
                        info.Data.AssetBundles[desc.AssetBundleName].IsPermanent = desc.IsPermanent;
                    }
                }
            }

            //同步数据至ResourcesManifestData
            if (build != null)
            {
                build.SyncConfigTo(info.Data);
            }

            //保存ResourcesInfo
            string resources_manifest_file = EditorCommon.BUILD_PATH + "/" + Common.RESOURCES_MANIFEST_FILE_NAME;

            info.Save(resources_manifest_file);

            if (AssetBundleBrowseWindow.Instance != null)
            {
                AssetBundleBrowseWindow.Instance.LoadData(info);
            }

            AssetDatabase.Refresh();

            return(info);
        }