Tanoda
CanvasGroupActivator.cs
Go to the documentation of this file.
1
5
6using UnityEditor;
7
9{
10 public class CanvasGroupActivator : EditorWindow
11 {
12 [MenuItem("Window/UI/Extensions/Canvas Groups Activator")]
13 public static void InitWindow()
14 {
15 EditorWindow.GetWindow<CanvasGroupActivator>();
16 }
17
18 CanvasGroup[] canvasGroups;
19
20 void OnEnable()
21 {
22 ObtainCanvasGroups();
23 }
24
25 void OnFocus()
26 {
27 ObtainCanvasGroups();
28 }
29
30 void ObtainCanvasGroups()
31 {
32 canvasGroups = GameObject.FindObjectsOfType<CanvasGroup>();
33 }
34
35 void OnGUI()
36 {
37 if (canvasGroups == null)
38 {
39 return;
40 }
41
42 GUILayout.Space(10f);
43 GUILayout.Label("Canvas Groups");
44
45 for (int i = 0; i < canvasGroups.Length; i++)
46 {
47 if (canvasGroups[i] == null) { continue; }
48
49 bool initialActive = false;
50 if (canvasGroups[i].alpha == 1.0f)
51 initialActive = true;
52
53 bool active = EditorGUILayout.Toggle(canvasGroups[i].name, initialActive);
54 if (active != initialActive)
55 {
56 //If deactivated and initially active
57 if (!active && initialActive)
58 {
59 //Deactivate this
60 canvasGroups[i].alpha = 0f;
61 canvasGroups[i].interactable = false;
62 canvasGroups[i].blocksRaycasts = false;
63 }
64 //If activated and initially deactivate
65 else if (active && !initialActive)
66 {
67 //Deactivate all others and activate this
68 HideAllGroups();
69
70 canvasGroups[i].alpha = 1.0f;
71 canvasGroups[i].interactable = true;
72 canvasGroups[i].blocksRaycasts = true;
73 }
74 }
75 }
76
77 GUILayout.Space(5f);
78
79 if (GUILayout.Button("Show All"))
80 {
81 ShowAllGroups();
82 }
83
84 if (GUILayout.Button("Hide All"))
85 {
86 HideAllGroups();
87 }
88 }
89
90 void ShowAllGroups()
91 {
92 foreach (var group in canvasGroups)
93 {
94 if (group != null)
95 {
96 group.alpha = 1.0f;
97 group.interactable = true;
98 group.blocksRaycasts = true;
99 }
100 }
101 }
102
103 void HideAllGroups()
104 {
105 foreach (var group in canvasGroups)
106 {
107 if (group != null)
108 {
109 group.alpha = 0;
110 group.interactable = false;
111 group.blocksRaycasts = false;
112 }
113 }
114 }
115 }
116}
Credit Erdener Gonenc - @PixelEnvision.