Edited at

UIPanel以下のUIWidgetのdepthを全部まとめて操作したい!!!

More than 3 years have passed since last update.

わかるで?

using UnityEngine;

using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class UIPanelDepthEditor: EditorWindow {

[MenuItem("Window/UIPanelDepthEditor")]
public static void ShowWindow() {
EditorWindow win = EditorWindow.GetWindow<UIPanelDepthEditor>();
win.title = "UIPanelDepthEditor";

}

void OnInspectorUpdate() {
// reset collection
}

UnityEngine.Object target = null;

void OnGUI() {

bool isPanel = false;
GUILayout.BeginVertical ();

var replaceObj = EditorGUILayout.ObjectField( "ObjectField", target, typeof( Transform ), true );
if (replaceObj != null)
{
target = replaceObj;
}

GUILayout.BeginHorizontal();
{

EditorGUILayout.PrefixLabel("Depth");

if (GUILayout.Button("-10", GUILayout.MinWidth(46f)))
{
DepthControll((Transform)replaceObj,-10);
}
if (GUILayout.Button("Back", GUILayout.MinWidth(46f)))
{
DepthControll((Transform)replaceObj,-1);
}

var text = "";
if (replaceObj != null)
{
var panel = ((Transform)replaceObj).GetComponent<UIPanel>();
if (panel != null)
{
text = panel.depth.ToString();
isPanel = true;
}
else
{
var widget = ((Transform)replaceObj).GetComponent<UIWidget>();
text = widget.depth.ToString();
}

}

EditorGUILayout.TextArea(text);

if (GUILayout.Button("Forward", GUILayout.MinWidth(40f)))
{
DepthControll((Transform)replaceObj,1);
}

if (GUILayout.Button("+10", GUILayout.MinWidth(40f)))
{
DepthControll((Transform)replaceObj,10);
}
}
GUILayout.EndHorizontal();
if (!isPanel)
EditorGUILayout.HelpBox ("これはUIPanelじゃないです", MessageType.Warning);
EditorGUILayout.HelpBox ("UIPanel以下のUIWidgetをまとめてDepth操作する。\n ちょっと重たい", MessageType.Info);
GUILayout.EndVertical();
}

void DepthControll(Transform obj,int depth)
{
foreach(var child in obj.gameObject.transform)
{
var item = child as Transform;
var widget = item.GetComponent<UIWidget>();
if (widget!= null)
widget.depth += depth;
else
{
var panel = item.GetComponent<UIPanel>();
if(panel != null)
panel.depth += depth;
}
DepthControll(item,depth);

}
}
}