111 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			C#
		
	
			
		
		
	
	
			111 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			C#
		
	
using UnityEditor;
 | 
						|
 | 
						|
namespace UnityEngine.UI.Extensions
 | 
						|
{
 | 
						|
    public class CanvasGroupActivator : EditorWindow
 | 
						|
    {
 | 
						|
        [MenuItem("Window/UI/Extensions/Canvas Groups Activator")]
 | 
						|
        public static void InitWindow()
 | 
						|
        {
 | 
						|
            EditorWindow.GetWindow<CanvasGroupActivator>();
 | 
						|
        }
 | 
						|
 | 
						|
        CanvasGroup[] canvasGroups;
 | 
						|
 | 
						|
        void OnEnable()
 | 
						|
        {
 | 
						|
            ObtainCanvasGroups();
 | 
						|
        }
 | 
						|
 | 
						|
        void OnFocus()
 | 
						|
        {
 | 
						|
            ObtainCanvasGroups();
 | 
						|
        }
 | 
						|
 | 
						|
        void ObtainCanvasGroups()
 | 
						|
        {
 | 
						|
            canvasGroups = GameObject.FindObjectsOfType<CanvasGroup>();
 | 
						|
        }
 | 
						|
 | 
						|
        void OnGUI()
 | 
						|
        {
 | 
						|
            if (canvasGroups == null)
 | 
						|
            {
 | 
						|
                return;
 | 
						|
            }
 | 
						|
 | 
						|
            GUILayout.Space(10f);
 | 
						|
            GUILayout.Label("Canvas Groups");
 | 
						|
 | 
						|
            for (int i = 0; i < canvasGroups.Length; i++)
 | 
						|
            {
 | 
						|
                if (canvasGroups[i] == null) { continue; }
 | 
						|
 | 
						|
                bool initialActive = false;
 | 
						|
                if (canvasGroups[i].alpha == 1.0f)
 | 
						|
                    initialActive = true;
 | 
						|
 | 
						|
                bool active = EditorGUILayout.Toggle(canvasGroups[i].name, initialActive);
 | 
						|
                if (active != initialActive)
 | 
						|
                {
 | 
						|
                    //If deactivated and initially active
 | 
						|
                    if (!active && initialActive)
 | 
						|
                    {
 | 
						|
                        //Deactivate this
 | 
						|
                        canvasGroups[i].alpha = 0f;
 | 
						|
                        canvasGroups[i].interactable = false;
 | 
						|
                        canvasGroups[i].blocksRaycasts = false;
 | 
						|
                    }
 | 
						|
                    //If activated and initially deactive
 | 
						|
                    else if (active && !initialActive)
 | 
						|
                    {
 | 
						|
                        //Deactivate all others and activate this
 | 
						|
                        HideAllGroups();
 | 
						|
 | 
						|
                        canvasGroups[i].alpha = 1.0f;
 | 
						|
                        canvasGroups[i].interactable = true;
 | 
						|
                        canvasGroups[i].blocksRaycasts = true;
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
 | 
						|
            GUILayout.Space(5f);
 | 
						|
 | 
						|
            if (GUILayout.Button("Show All"))
 | 
						|
            {
 | 
						|
                ShowAllGroups();
 | 
						|
            }
 | 
						|
 | 
						|
            if (GUILayout.Button("Hide All"))
 | 
						|
            {
 | 
						|
                HideAllGroups();
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        void ShowAllGroups()
 | 
						|
        {
 | 
						|
            foreach (var group in canvasGroups)
 | 
						|
            {
 | 
						|
                if (group != null)
 | 
						|
                {
 | 
						|
                    group.alpha = 1.0f;
 | 
						|
                    group.interactable = true;
 | 
						|
                    group.blocksRaycasts = true;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        void HideAllGroups()
 | 
						|
        {
 | 
						|
            foreach (var group in canvasGroups)
 | 
						|
            {
 | 
						|
                if (group != null)
 | 
						|
                {
 | 
						|
                    group.alpha = 0;
 | 
						|
                    group.interactable = false;
 | 
						|
                    group.blocksRaycasts = false;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |