标签:
孙广东 2015.12.11
using UnityEngine; using System.Collections.Generic; using System.Collections; using UnityEditor; using System.Reflection; using System; /// <summary> /// 描述:全部 展开/收起 Inspector面板的所有组件、 /// author: 孙广东 /// todo 还可以深度定制,添加两个按钮切换 /// </summary> //[CustomEditor(typeof(Transform))] public class InspectorManagerEditor : Editor { #region ===字段=== #endregion #region ===Unity事件=== 快捷键: Ctrl + Shift + M /Ctrl + Shift + Q 实现 // 显示两个可以点击的Button [MenuItem("DajiaGame/InspectorManager/全部展开组件... %#&m")] static void Expansion() { var type = typeof(EditorWindow).Assembly.GetType("UnityEditor.InspectorWindow"); var window = EditorWindow.GetWindow(type); FieldInfo info = type.GetField("m_Tracker", BindingFlags.NonPublic | BindingFlags.Instance); ActiveEditorTracker tracker = info.GetValue(window) as ActiveEditorTracker; for (int i = 0; i < tracker.activeEditors.Length; i++) { ////可以通过名子单独判断组件展开或不展开 //if (tracker.activeEditors[i].target.GetType().Name != "NewBehaviourScript") //{ //这里1就是展开,0就是合起来 tracker.SetVisible(i, 1); //} } } [MenuItem("DajiaGame/InspectorManager/全部收起组件... %#&n")] static void Shrinkage() { var type = typeof(EditorWindow).Assembly.GetType("UnityEditor.InspectorWindow"); var window = EditorWindow.GetWindow(type); FieldInfo info = type.GetField("m_Tracker", BindingFlags.NonPublic | BindingFlags.Instance); ActiveEditorTracker tracker = info.GetValue(window) as ActiveEditorTracker; for (int i = 0; i < tracker.activeEditors.Length; i++) { //这里1就是展开,0就是合起来 tracker.SetVisible(i, 0); } } #endregion #region ===方法=== #endregion }
一键展开关闭unity的 Inspector面板上的所有组件
标签:
原文地址:http://blog.csdn.net/u010019717/article/details/50268111