using UnityEngine; using UnityEngine.SceneManagement; #if UNITY_EDITOR using UnityEditor; #endif namespace XRTool.Util { [InitializeOnLoad] [CustomEditor(typeof(GameNode))] public class GameNodeInspector : Editor { public override void OnInspectorGUI() { base.OnInspectorGUI(); if (GUILayout.Button("保存场景")) { var tar = target as GameNode; if (tar) { var local = (target as GameNode).transform.Find("Local"); for (int i = 0; i < local.childCount; i++) { SaveScene(local.GetChild(i)); } } } if (GUILayout.Button("清空场景")) { SceneConfMgr.Instance.ClearSceneObj(SceneManager.GetActiveScene().name); } } [MenuItem("GameObject/XRTool/SaveScene", priority = 4)] public static void SaveScene() { GameObject obj = Selection.activeGameObject; if (obj) { string scene = SceneManager.GetActiveScene().name; string path = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(obj); if (!string.IsNullOrEmpty(path)) { SceneConfMgr.Instance.SaveSceens(scene, obj.transform.parent, obj.transform, path); } else { UnityLog.Instance.LogError(obj + " is not prefab!Cant save"); } } } public static void SaveScene(Transform parent) { string scene = SceneManager.GetActiveScene().name; if (parent.childCount > 0) { for (int i = 0; i < parent.childCount; i++) { string path = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(parent.GetChild(i).gameObject); if (path.Contains("Resources")) { int index = path.LastIndexOf("Resources"); path = path.Substring((index+= "Resources".Length + 1), path.Length-index-1); if (!string.IsNullOrEmpty(path)) { SceneConfMgr.Instance.SaveSceens(scene, parent, parent.GetChild(i), path); } else { UnityLog.Instance.LogError(parent.GetChild(i) + " is not prefab!Cant save"); } } else { UnityLog.Instance.LogError(parent.GetChild(i) + " is not in Resources!"); } } } else { UnityLog.Instance.Log(parent + " is not child !will not save"); } } } }