Example #1
0
        void OnGUI()
        {
            if (m_DebugMenu == null)
            {
                return;
            }

            // Contrary to the menu in the player, here we always render the menu wether it's enabled or not. This is a separate window so user can manage it however they want.
            EditorGUI.BeginChangeCheck();
            int debugMenuCount  = m_DebugMenu.menuCount;
            int activeMenuIndex = m_DebugMenu.activeMenuIndex;

            using (new EditorGUILayout.HorizontalScope())
            {
                for (int i = 0; i < debugMenuCount; ++i)
                {
                    GUIStyle style = EditorStyles.miniButtonMid;
                    if (i == 0)
                    {
                        style = EditorStyles.miniButtonLeft;
                    }
                    if (i == debugMenuCount - 1)
                    {
                        style = EditorStyles.miniButtonRight;
                    }
                    if (GUILayout.Toggle(i == activeMenuIndex, new GUIContent(m_DebugMenu.GetDebugMenu(i).name), style))
                    {
                        activeMenuIndex = i;
                    }
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                m_DebugMenu.activeMenuIndex = activeMenuIndex;
            }

            using (new EditorGUILayout.VerticalScope())
            {
                DebugMenu activeMenu  = m_DebugMenu.GetDebugMenu(m_DebugMenu.activeMenuIndex);
                bool      needRepaint = false;
                for (int i = 0; i < activeMenu.itemCount; ++i)
                {
                    needRepaint = needRepaint || activeMenu.GetDebugMenuItem(i).drawer.OnEditorGUI();
                }

                if (needRepaint)
                {
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                }
            }
        }
Example #2
0
        public void AddDebugItem <ItemType>(string debugMenuName, string name, Func <object> getter, Action <object> setter = null, bool dynamicDisplay = false, DebugItemDrawer drawer = null)
        {
            DebugMenu debugMenu = GetDebugMenu(debugMenuName);

            // If the menu does not exist, create a generic one. This way, users don't have to explicitely create a new DebugMenu class if they don't need any particular overriding of default behavior.
            if (debugMenu == null)
            {
                debugMenu = new DebugMenu(debugMenuName);
                m_DebugMenus.Add(debugMenu);
            }

            if (debugMenu != null)
            {
                debugMenu.AddDebugMenuItem <ItemType>(name, getter, setter, dynamicDisplay, drawer);
            }
        }
Example #3
0
 DebugMenuManager()
 {
     LookUpDebugMenuClasses();
     m_PersistentDebugMenu = new DebugMenu("Persistent");
     m_DebugMenuUI         = new DebugMenuUI(this);
 }