/// <summary>
        ///   打包AssetBundle
        /// </summary>
        public static void BuildAllAssetBundlesToTarget(BuildTarget target
                                                        , BuildAssetBundleOptions options)
        {
            string manifest_file             = EditorCommon.BUILD_PATH + "/" + Common.MAIN_MANIFEST_FILE_NAME;
            AssetBundleManifest old_manifest = Common.LoadMainManifestByPath(manifest_file);

            if (!Directory.Exists(EditorCommon.BUILD_PATH))
            {
                Directory.CreateDirectory(EditorCommon.BUILD_PATH);
            }
            BuildPipeline.BuildAssetBundles(EditorCommon.BUILD_PATH, options, target);
            AssetDatabase.Refresh();

            AssetBundleManifest new_manifest = Common.LoadMainManifestByPath(manifest_file);

            ComparisonAssetBundleManifest(old_manifest, new_manifest);
            ExportResourcesManifestFile(new_manifest);

            string            resoures_manifest_file = EditorCommon.BUILD_PATH + "/" + Common.RESOURCES_MANIFEST_FILE_NAME;
            ResourcesManifest resoureces_manifest    = Common.LoadResourcesManifestByPath(resoures_manifest_file);

            CompressAssetBundles(resoureces_manifest, ref resoureces_manifest);
            resoureces_manifest.Save(resoures_manifest_file);
            CopyNativeAssetBundleToStreamingAssets(resoureces_manifest);
            EditorUtility.ClearProgressBar();
            AssetDatabase.Refresh();
        }
예제 #2
0
        /// <summary>
        ///   保存数据
        /// </summary>
        private bool SaveData()
        {
            if (Manifest != null)
            {
                return(Manifest.Save(EditorCommon.RESOURCES_MANIFEST_FILE_PATH));
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// 根据AssetBundle导出ResourcesManifest文件
        /// </summary>
        public static void ExportResourcesManifestFile(AssetBundleManifest manifest)
        {
            ResourcesManifest info = new ResourcesManifest();

            //读取所有AssetBundle
            string        root_dir = EditorCommon.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;
                    }
                }
            }

            //保存ResourcesInfo
            info.Save(EditorCommon.RESOURCES_MANIFEST_FILE_PATH);

            AssetDatabase.Refresh();
        }