using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.UI; namespace HK.Editor { public class UILayoutToolEditor : UnityEditor.Editor { [MenuItem("GameObject/ZTool/Layout/Close GridLayoutGroup",false,0)] static void CloseGridLayoutGroup() { Check(0, false); } [MenuItem("GameObject/ZTool/Layout/Open GridLayoutGroup",false,1)] static void OpenGridLayoutGroup() { Check(0, true); } [MenuItem("GameObject/ZTool/Layout/Close HorizontalLayoutGroup",false,10)] static void CloseHorizontalLayoutGroup() { Check(1, false); } [MenuItem("GameObject/ZTool/Layout/Open HorizontalLayoutGroup",false,11)] static void OpenHorizontalLayoutGroup() { Check(1, true); } [MenuItem("GameObject/ZTool/Layout/Close VerticalLayoutGroup",false,20)] static void CloseVerticalLayoutGroup() { Check(2, false); } [MenuItem("GameObject/ZTool/Layout/Open VerticalLayoutGroup",false,21)] static void OpenVerticalLayoutGroup() { Check(2, true); } [MenuItem("GameObject/ZTool/Layout/Close AllLayout",false,30)] static void CloseAllLayout() { Check(3, false); } [MenuItem("GameObject/ZTool/Layout/Open AllLayout",false,31)] static void OpenAllLayout() { Check(3, true); } static void Check(int index, bool isEnable) { List gridLayoutGroups = new List(); List horizontalLayoutGroups = new List(); List verticalLayoutGroups = new List(); foreach (var go in Selection.gameObjects) { gridLayoutGroups = go.transform.TryFindChildDeeps(); horizontalLayoutGroups = go.transform.TryFindChildDeeps(); verticalLayoutGroups = go.transform.TryFindChildDeeps(); } if (index == 0) { foreach (var layoutGroup in gridLayoutGroups) { layoutGroup.enabled = isEnable; } } else if (index == 1) { foreach (var layoutGroup in horizontalLayoutGroups) { layoutGroup.enabled = isEnable; } } else if (index == 2) { foreach (var layoutGroup in verticalLayoutGroups) { layoutGroup.enabled = isEnable; } } else if (index == 3) { foreach (var layoutGroup in gridLayoutGroups) { layoutGroup.enabled = isEnable; } foreach (var layoutGroup in horizontalLayoutGroups) { layoutGroup.enabled = isEnable; } foreach (var layoutGroup in verticalLayoutGroups) { layoutGroup.enabled = isEnable; } } Debug.Log("完成!"); } } }