using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class HierarchyUIValidator : MonoBehaviour {
public static bool enable = true;
static HierarchyUIValidator() {
EditorApplication.hierarchyWindowItemOnGUI += HierarchyOnGUI;
}
[MenuItem("UI/Validator")]
static void Switch() {
enable = !enable;
Menu.SetChecked("UI/Validator", enable);
}
private static void HierarchyOnGUI(int instanceID, Rect selectionRect) {
if (!enable) return;
Color defaultColor = GUI.color;
var go = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (go == null) return;
var index = 0;
bool yRotated = go.transform.localRotation.y != 0;
bool zMoved = go.transform.localPosition.z != 0;
if (yRotated || zMoved) {
if (go.activeInHierarchy) {
GUI.Label(selectionRect, go.name.Substring(0, 1), LabelStyle(Color.green));
if (zMoved) {
GUI.color = Color.cyan;
GUI.Label(CreateRect(selectionRect, index++), "P");
//var icon = EditorGUIUtility.IconContent("d_ToolHandleLocal").image;
//GUI.Label(CreateRect(selectionRect, index++), icon);
}
if (yRotated) {
GUI.color = Color.green;
GUI.Label(CreateRect(selectionRect, index++), "R");
//var icon = EditorGUIUtility.IconContent("d_RotateTool On").image;
//GUI.Label(CreateRect(selectionRect, index++), icon);
}
}
}
GUI.color = defaultColor;
}
private static GUIStyle LabelStyle(Color color) {
return new GUIStyle(((GUIStyle)"Label")) {
padding =
{
left = EditorStyles.label.padding.left+16,
top = EditorStyles.label.padding.top + 1
},
normal =
{
textColor = color
}
};
}
private static Rect CreateRect(Rect selectionRect, int index) {
var rect = new Rect(selectionRect);
rect.x += rect.width - 20 - (10 * index);
rect.width = 18;
return rect;
}
}