GameNodeInspector.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. #if UNITY_EDITOR
  4. using UnityEditor;
  5. #endif
  6. namespace XRTool.Util
  7. {
  8. [InitializeOnLoad]
  9. [CustomEditor(typeof(GameNode))]
  10. public class GameNodeInspector : Editor
  11. {
  12. public override void OnInspectorGUI()
  13. {
  14. base.OnInspectorGUI();
  15. if (GUILayout.Button("保存场景"))
  16. {
  17. var tar = target as GameNode;
  18. if (tar)
  19. {
  20. var local = (target as GameNode).transform.Find("Local");
  21. for (int i = 0; i < local.childCount; i++)
  22. {
  23. SaveScene(local.GetChild(i));
  24. }
  25. }
  26. }
  27. if (GUILayout.Button("清空场景"))
  28. {
  29. SceneConfMgr.Instance.ClearSceneObj(SceneManager.GetActiveScene().name);
  30. }
  31. }
  32. [MenuItem("GameObject/XRTool/SaveScene", priority = 4)]
  33. public static void SaveScene()
  34. {
  35. GameObject obj = Selection.activeGameObject;
  36. if (obj)
  37. {
  38. string scene = SceneManager.GetActiveScene().name;
  39. string path = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(obj);
  40. if (!string.IsNullOrEmpty(path))
  41. {
  42. SceneConfMgr.Instance.SaveSceens(scene, obj.transform.parent, obj.transform, path);
  43. }
  44. else
  45. {
  46. UnityLog.Instance.LogError(obj + " is not prefab!Cant save");
  47. }
  48. }
  49. }
  50. public static void SaveScene(Transform parent)
  51. {
  52. string scene = SceneManager.GetActiveScene().name;
  53. if (parent.childCount > 0)
  54. {
  55. for (int i = 0; i < parent.childCount; i++)
  56. {
  57. string path = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(parent.GetChild(i).gameObject);
  58. if (path.Contains("Resources"))
  59. {
  60. int index = path.LastIndexOf("Resources");
  61. path = path.Substring((index+= "Resources".Length + 1), path.Length-index-1);
  62. if (!string.IsNullOrEmpty(path))
  63. {
  64. SceneConfMgr.Instance.SaveSceens(scene, parent, parent.GetChild(i), path);
  65. }
  66. else
  67. {
  68. UnityLog.Instance.LogError(parent.GetChild(i) + " is not prefab!Cant save");
  69. }
  70. }
  71. else
  72. {
  73. UnityLog.Instance.LogError(parent.GetChild(i) + " is not in Resources!");
  74. }
  75. }
  76. }
  77. else
  78. {
  79. UnityLog.Instance.Log(parent + " is not child !will not save");
  80. }
  81. }
  82. }
  83. }