예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        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();
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <summary>
        /// 根据AssetBundle导出ResourcesManifest文件
        /// </summary>
        public static void ExportResourcesManifestFile(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            = XFramework.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            = XFramework.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
            string resources_manifest_file = EditorCommon.BUILD_PATH + "/" + Common.RESOURCES_MANIFEST_FILE_NAME;

            info.Save(resources_manifest_file);

            AssetDatabase.Refresh();
        }