Ejemplo n.º 1
0
        public void OnGUI()
        {
            if (m_Control == null)
            {
                m_ShowRawBytes = true;
            }

            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            m_ShowRawBytes = GUILayout.Toggle(m_ShowRawBytes, Contents.showRawMemory, EditorStyles.toolbarButton,
                                              GUILayout.Width(150));

            // If we have multiple state buffers to choose from, add dropdown that allows
            // selecting which buffer to display.
            if (m_StateBuffers.Length > 1)
            {
                var selectedBuffer = (BufferSelector)EditorGUILayout.IntPopup((int)m_SelectedStateBuffer, m_BufferChoices,
                                                                              m_BufferChoiceValues, EditorStyles.toolbarPopup);
                if (selectedBuffer != m_SelectedStateBuffer)
                {
                    m_SelectedStateBuffer = selectedBuffer;
                    m_ControlTree         = null;
                }
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if (m_ShowRawBytes)
            {
                DrawHexDump();
            }
            else
            {
                if (m_ControlTree == null)
                {
                    m_ControlTree             = InputControlTreeView.Create(m_Control, ref m_ControlTreeState, ref m_ControlTreeHeaderState);
                    m_ControlTree.stateBuffer = m_StateBuffers[(int)m_SelectedStateBuffer];
                    m_ControlTree.ExpandAll();
                }

                var rect = EditorGUILayout.GetControlRect(GUILayout.ExpandHeight(true));
                m_ControlTree.OnGUI(rect);
            }
        }
        private void InitializeWith(InputDevice device)
        {
            m_Device             = device;
            m_DeviceId           = device.id;
            m_DeviceIdString     = device.id.ToString();
            m_DeviceUsagesString = string.Join(", ", device.usages.Select(x => x.ToString()).ToArray());

            // Set up event trace. The default trace size of 1mb fits a ton of events and will
            // likely bog down the UI if we try to display that many events. Instead, come up
            // with a more reasonable sized based on the state size of the device.
            if (m_EventTrace == null)
            {
                m_EventTrace = new InputEventTrace((int)device.stateBlock.alignedSizeInBytes * 64)
                {
                    deviceId = device.id
                }
            }
            ;
            m_EventTrace.onEvent += _ =>
            {
                ////FIXME: this is very inefficient
                m_EventTree.Reload();
                Repaint();
            };
            if (!m_EventTraceDisabled)
            {
                m_EventTrace.Enable();
            }

            // Set up event tree.
            m_EventTree = InputEventTreeView.Create(m_Device, m_EventTrace, ref m_EventTreeState, ref m_EventTreeHeaderState);

            // Set up control tree.
            m_ControlTree = InputControlTreeView.Create(m_Device, ref m_ControlTreeState, ref m_ControlTreeHeaderState);
            m_ControlTree.ExpandAll();

            // Look for GUI extension methods in plugins.
            m_OnToolbarGUIMethods = InputManager.ScanForPluginMethods("OnToolbarGUI");
        }