Skip to content

Instantly share code, notes, and snippets.

@enpel
Created April 3, 2015 02:22
Show Gist options
  • Save enpel/85af6c287a7018db8cd0 to your computer and use it in GitHub Desktop.
Save enpel/85af6c287a7018db8cd0 to your computer and use it in GitHub Desktop.
NGUIのUIPanel以下のDepthをまとめて操作
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment