ZUIManagerEditor.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. [CustomEditor(typeof(ZUIManager))]
  6. public class ZUIManagerEditor : Editor
  7. {
  8. SerializedProperty autoFindHolders;
  9. SerializedProperty allMenus;
  10. SerializedProperty animateFirstMenuAtStart;
  11. SerializedProperty allSideMenus;
  12. SerializedProperty allPopups;
  13. SerializedProperty escIsBack;
  14. void OnEnable()
  15. {
  16. autoFindHolders = serializedObject.FindProperty("AutoFindHolders");
  17. allMenus = serializedObject.FindProperty("AllMenus");
  18. animateFirstMenuAtStart = serializedObject.FindProperty("AnimateFirstMenuAtStart");
  19. allSideMenus = serializedObject.FindProperty("AllSideMenus");
  20. allPopups = serializedObject.FindProperty("AllPopups");
  21. escIsBack = serializedObject.FindProperty("EscIsBack");
  22. }
  23. public override void OnInspectorGUI()
  24. {
  25. //base.OnInspectorGUI();
  26. ZUIManager myZUIManager = target as ZUIManager;
  27. EditorGUILayout.Space();
  28. EditorGUILayout.PropertyField(autoFindHolders, new GUIContent("Auto Find Holders"));
  29. if (!autoFindHolders.boolValue)
  30. {
  31. #region Menus
  32. EditorGUILayout.LabelField("Menus", EditorStyles.boldLabel);
  33. EditorGUILayout.PropertyField(allMenus, true);
  34. EditorGUILayout.PropertyField(animateFirstMenuAtStart);
  35. //EditorGUILayout.LabelField("Tools", EditorStyles.boldLabel);
  36. if (GUILayout.Button("Update All Menus", GUILayout.Height(30)))
  37. {
  38. Undo.RecordObject(myZUIManager, "Update All Menus");
  39. myZUIManager.AllMenus = GetAllMenus();
  40. }
  41. if (GUILayout.Button("Activate All Menus", GUILayout.Height(30)))
  42. {
  43. foreach (Menu m in myZUIManager.AllMenus)
  44. {
  45. Undo.RecordObject(m.gameObject, "Activate All Menus");
  46. m.gameObject.SetActive(true);
  47. }
  48. }
  49. #endregion
  50. EditorGUILayout.Space();
  51. #region Pop-ups
  52. EditorGUILayout.LabelField("Pop-ups", EditorStyles.boldLabel);
  53. EditorGUILayout.PropertyField(allPopups, true);
  54. if (GUILayout.Button("Update All Pop-ups", GUILayout.Height(30)))
  55. {
  56. Undo.RecordObject(myZUIManager, "Update All Pop-ups");
  57. myZUIManager.AllPopups = GetAllPopups();
  58. }
  59. if (GUILayout.Button("Activate All Pop-ups", GUILayout.Height(30)))
  60. {
  61. foreach (Popup sM in myZUIManager.AllPopups)
  62. {
  63. Undo.RecordObject(sM.gameObject, "Activate All Pop-ups");
  64. sM.gameObject.SetActive(true);
  65. }
  66. }
  67. #endregion
  68. EditorGUILayout.Space();
  69. #region Side-menus
  70. EditorGUILayout.LabelField("Side-menus", EditorStyles.boldLabel);
  71. EditorGUILayout.PropertyField(allSideMenus, true);
  72. if (GUILayout.Button("Update All Side-menus", GUILayout.Height(30)))
  73. {
  74. Undo.RecordObject(myZUIManager, "Update All Side-menus");
  75. myZUIManager.AllSideMenus = GetAllSideMenus();
  76. }
  77. if (GUILayout.Button("Activate All Side-menus", GUILayout.Height(30)))
  78. {
  79. foreach (SideMenu sM in myZUIManager.AllSideMenus)
  80. {
  81. Undo.RecordObject(sM.gameObject, "Activate All Side-menus");
  82. sM.gameObject.SetActive(true);
  83. }
  84. }
  85. #endregion
  86. }
  87. EditorGUILayout.Space();
  88. #region General Settings
  89. EditorGUILayout.LabelField("General Settings", EditorStyles.boldLabel);
  90. if (autoFindHolders.boolValue)
  91. EditorGUILayout.PropertyField(animateFirstMenuAtStart);
  92. EditorGUILayout.PropertyField(escIsBack);
  93. if (!autoFindHolders.boolValue && GUILayout.Button("Update All", GUILayout.Height(30)))
  94. {
  95. Undo.RecordObject(myZUIManager, "Update All");
  96. myZUIManager.AllMenus = GetAllMenus();
  97. myZUIManager.AllPopups = GetAllPopups();
  98. myZUIManager.AllSideMenus = GetAllSideMenus();
  99. }
  100. #endregion
  101. serializedObject.ApplyModifiedProperties();
  102. }
  103. List<Menu> GetAllMenus()
  104. {
  105. List<Menu> menus = new List<Menu>();
  106. Canvas[] allCanvases = FindObjectsOfType<Canvas>();
  107. foreach (Canvas c in allCanvases)
  108. {
  109. menus.AddRange(GetMenusInCanvas(c.transform));
  110. }
  111. return menus;
  112. }
  113. List<Menu> GetMenusInCanvas(Transform canvas)
  114. {
  115. List<Menu> ts = new List<Menu>();
  116. foreach (Transform c in canvas)
  117. {
  118. Menu cMenu = c.GetComponent<Menu>();
  119. if (cMenu)
  120. ts.Add(cMenu);
  121. ts.AddRange(GetMenusInCanvas(c));
  122. }
  123. return ts;
  124. }
  125. List<SideMenu> GetAllSideMenus()
  126. {
  127. List<SideMenu> sideMenus = new List<SideMenu>();
  128. Canvas[] allCanvases = FindObjectsOfType<Canvas>();
  129. foreach (Canvas c in allCanvases)
  130. {
  131. sideMenus.AddRange(GetSideMenusInCanvas(c.transform));
  132. }
  133. return sideMenus;
  134. }
  135. List<SideMenu> GetSideMenusInCanvas(Transform canvas)
  136. {
  137. List<SideMenu> allSideMenus = new List<SideMenu>();
  138. foreach (Transform c in canvas)
  139. {
  140. SideMenu cSideMenu = c.GetComponent<SideMenu>();
  141. if (cSideMenu)
  142. allSideMenus.Add(cSideMenu);
  143. allSideMenus.AddRange(GetSideMenusInCanvas(c));
  144. }
  145. return allSideMenus;
  146. }
  147. List<Popup> GetAllPopups()
  148. {
  149. List<Popup> popups = new List<Popup>();
  150. Canvas[] allCanvases = FindObjectsOfType<Canvas>();
  151. foreach (Canvas c in allCanvases)
  152. {
  153. popups.AddRange(GetPopupsInCanvas(c.transform));
  154. }
  155. return popups;
  156. }
  157. List<Popup> GetPopupsInCanvas(Transform canvas)
  158. {
  159. List<Popup> allPopups = new List<Popup>();
  160. foreach (Transform c in canvas)
  161. {
  162. Popup cPopup = c.GetComponent<Popup>();
  163. if (cPopup)
  164. allPopups.Add(cPopup);
  165. allPopups.AddRange(GetPopupsInCanvas(c));
  166. }
  167. return allPopups;
  168. }
  169. }