private void CheckSceneInfo(bool revert) { sceneCFG = FindObjectOfType <SceneCFG>(); if (sceneCFG != null) { GameObject root = sceneCFG.gameObject; PrefabInstanceStatus prefabType = PrefabUtility.GetPrefabInstanceStatus(root); if (prefabType == PrefabInstanceStatus.NotAPrefab) { GameObject.DestroyImmediate(root); sceneCFG = null; } else { //重置为已存储的数据 if (revert) { PrefabUtility.RevertPrefabInstance(root, InteractionMode.AutomatedAction); } } } if (sceneCFG == null) { string path = getSceneAssetPrefix() + "/sceneInfo.prefab"; GameObject go = AssetDatabase.LoadAssetAtPath <GameObject>(path); if (go != null) { GameObject root = (GameObject)PrefabUtility.InstantiatePrefab(go); //root=PrefabUtility.ConnectGameObjectToPrefab(root, go); sceneCFG = root.GetComponent <SceneCFG>(); } } }
private void CreateSceneInfo() { GameObject root = new GameObject("SceneInfo"); //root.hideFlags = HideFlags.HideInHierarchy; sceneCFG = root.AddComponent <SceneCFG>(); Scene scene = EditorSceneManager.GetActiveScene(); if (scene.IsValid() == false) { EditorSceneManager.MarkSceneDirty(scene); } string path = getSceneAssetPrefix() + "/SceneInfo.prefab"; if (Directory.Exists(getSceneAssetPrefix()) == false) { Directory.CreateDirectory(getSceneAssetPrefix()); } PrefabUtility.SaveAsPrefabAsset(root, path); }