码迷,mamicode.com
首页 > 编程语言 > 详细

一键展开关闭unity的 Inspector面板上的所有组件

时间:2015-12-13 15:37:46      阅读:1404      评论:0      收藏:0      [点我收藏+]

标签:

孙广东  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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!