Exemplo n.º 1
0
        /// <summary>
        /// 同步场景资源配置
        /// </summary>
        static void SyncSceneAssetConfig(AssetBundleBuildData.SceneBuild.Element element, ResourcesManifestData data
                                         , bool is_write)
        {
            string localPath = EditorCommon.AbsoluteToRelativePath(element.ScenePath);

            localPath = localPath.ToLower();

            // 场景文件与配置文件
            string[] files = new string[] { localPath, SceneConfig.GetSceneConfigPath(localPath).ToLower() };
            foreach (var path in files)
            {
                string key = EditorCommon.ConvertToAssetBundleName(path);
                ResourcesManifestData.AssetBundle ab_data;
                if (data.AssetBundles.TryGetValue(key, out ab_data))
                {
                    if (is_write)
                    {
                        ab_data.IsCompress    = element.IsCompress;
                        ab_data.IsNative      = element.IsNative;
                        ab_data.IsPermanent   = false;
                        ab_data.IsStartupLoad = false;
                    }
                    else
                    {
                        element.IsCompress = ab_data.IsCompress;
                        element.IsNative   = ab_data.IsNative;
                    }
                }
            }
        }
        /// <summary>
        ///   删除配置文件
        /// </summary>
        public static void DeleteSceneConfig(string scene_path)
        {
            var file_name = SceneConfig.GetSceneConfigPath(scene_path);

            if (File.Exists(file_name))
            {
                File.Delete(file_name);
            }
        }
        static void SaveAll()
        {
            UnityEngine.SceneManagement.Scene sc = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
            if (!sc.IsValid())
            {
                return;
            }

            SceneConfig data = new SceneConfig();

            data.Data.LevelName = sc.name;

            GameObject[] array = GameObject.FindGameObjectsWithTag(SERIALIZE_SCENE_OBJECT_TAG);
            if (array == null)
            {
                return;
            }

            for (int i = 0; i < array.Length; ++i)
            {
                UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(array[i]);
                string             path         = AssetDatabase.GetAssetPath(parentObject);
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }

                var transform = array[i].transform;
                var parent    = transform.parent;

                //写入数据
                var obj = new SceneConfigData.SceneObject();
                obj.AssetName  = path;
                obj.Position   = transform.position;
                obj.Scale      = transform.lossyScale;
                obj.Rotation   = transform.rotation;
                obj.ParentName = parent != null?
                                 Common.CalcTransformHierarchyPath(parent) : "";

                data.Data.SceneObjects.Add(obj);
            }

            data.Save(SceneConfig.GetSceneConfigPath(sc.path));
            AssetDatabase.Refresh();
        }
        /// <summary>
        ///   生成所有场景配置文件
        /// </summary>
        public static bool GenerateAllSceneConfig(AssetBundleBuildData.SceneBuild scene_rules)
        {
            RecordDefaultOpenScene();

            bool  cancel  = false;
            float total   = (float)scene_rules.Scenes.Count;
            float current = 0;

            for (int i = 0; i < scene_rules.Scenes.Count; ++i)
            {
                var scene = scene_rules.Scenes[i].ScenePath;
                if (scene_rules.Scenes[i].IsBuild)
                {
                    CopySceneToBackup(scene);
                    GenerateSceneConfig(scene);
                    //设置场景配置文件
                    AssetBundleNameTool.SetAssetBundleName(SceneConfig.GetSceneConfigPath(scene));
                    //设置场景文件
                    AssetBundleNameTool.SetAssetBundleName(scene);
                }
                else
                {
                    DeleteSceneConfig(scene);
                    AssetBundleNameTool.ClearAssetBundleName(scene);
                }

                current += 1.0f;
                float progress = current / total;
                if (EditorUtility.DisplayCancelableProgressBar("正在生成场景配置数据", "Change " + scene, progress))
                {
                    cancel = true;
                    break;
                }
            }
            EditorUtility.ClearProgressBar();

            return(!cancel);
        }
Exemplo n.º 5
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();
        }