112 lines
3.4 KiB
C#
112 lines
3.4 KiB
C#
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<GridLayoutGroup> gridLayoutGroups = new List<GridLayoutGroup>();
|
|
List<HorizontalLayoutGroup> horizontalLayoutGroups = new List<HorizontalLayoutGroup>();
|
|
List<VerticalLayoutGroup> verticalLayoutGroups = new List<VerticalLayoutGroup>();
|
|
foreach (var go in Selection.gameObjects)
|
|
{
|
|
gridLayoutGroups = go.transform.TryFindChildDeeps<GridLayoutGroup>();
|
|
horizontalLayoutGroups = go.transform.TryFindChildDeeps<HorizontalLayoutGroup>();
|
|
verticalLayoutGroups = go.transform.TryFindChildDeeps<VerticalLayoutGroup>();
|
|
}
|
|
|
|
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("完成!");
|
|
}
|
|
}
|
|
} |