Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC for device flag clarity #2039

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal void OnGUI()
}

////FIXME: with ExpandHeight(false), editor still expands height for some reason....
EditorGUILayout.BeginVertical("OL Box", GUILayout.Height(170));// GUILayout.ExpandHeight(false));
EditorGUILayout.BeginVertical("OL Box", GUILayout.Height(130));// GUILayout.ExpandHeight(false));
EditorGUILayout.LabelField("Name", m_Device.name);
EditorGUILayout.LabelField("Layout", m_Device.layout);
EditorGUILayout.LabelField("Type", m_Device.GetType().Name);
Expand All @@ -137,16 +137,39 @@ internal void OnGUI()
EditorGUILayout.LabelField("Device ID", m_DeviceIdString);
if (!string.IsNullOrEmpty(m_DeviceUsagesString))
EditorGUILayout.LabelField("Usages", m_DeviceUsagesString);
if (!string.IsNullOrEmpty(m_DeviceFlagsString))
EditorGUILayout.LabelField("Flags", m_DeviceFlagsString);
if (m_Device is Keyboard)
EditorGUILayout.LabelField("Keyboard Layout", ((Keyboard)m_Device).keyboardLayout);
EditorGUILayout.EndVertical();


DrawFlags();
DrawControlTree();
DrawEventList();
}

private void DrawFlags()
{
GUILayout.BeginHorizontal(EditorStyles.toolbar);
GUILayout.Label("Flags", GUILayout.MinWidth(100), GUILayout.ExpandWidth(true));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

var rect = EditorGUILayout.GetControlRect(GUILayout.ExpandHeight(true));
m_DeviceFlagsTree.OnGUI(rect);

/*const string kTrue = "true";
const string kFalse = "false";
EditorGUILayout.LabelField("Native", m_Device.native ? kTrue : kFalse);
EditorGUILayout.LabelField("Remote", m_Device.remote ? kTrue : kFalse);
EditorGUILayout.LabelField("UpdateBeforeRender", m_Device.updateBeforeRender ? kTrue : kFalse);
EditorGUILayout.LabelField("HasStateCallbacks", m_Device.hasStateCallbacks ? kTrue : kFalse);
EditorGUILayout.LabelField("HasEventMerger", m_Device.hasEventMerger ? kTrue : kFalse);
EditorGUILayout.LabelField("HasEventPreProcessor", m_Device.hasEventPreProcessor ? kTrue : kFalse);
EditorGUILayout.LabelField("DisabledInFrontend", m_Device.disabledInFrontend ? kTrue : kFalse);
EditorGUILayout.LabelField("DisabledInRuntime", m_Device.disabledInRuntime ? kTrue : kFalse);
EditorGUILayout.LabelField("DisabledWWhileInBackground", m_Device.disabledWhileInBackground ? kTrue : kFalse);
EditorGUILayout.LabelField("CanRunInBackground", m_Device.canDeviceRunInBackground ? kTrue : kFalse);*/
}

private void DrawControlTree()
{
var label = m_InputUpdateTypeShownInControlTree == InputUpdateType.Editor
Expand Down Expand Up @@ -287,6 +310,11 @@ private void InitializeWith(InputDevice device)
m_DeviceUsagesString = string.Join(", ", device.usages.Select(x => x.ToString()).ToArray());

UpdateDeviceFlags();

// Setup flags
m_DeviceFlagsTree = DeviceFlagsTreeView.Create(m_Device, ref m_DeviceFlagsTreeState, ref m_DeviceFlagsHeaderState);
m_DeviceFlagsTree.Reload();
m_DeviceFlagsTree.ExpandAll();

// Set up event trace. The default trace size of 512kb fits a ton of events and will
// likely bog down the UI if we try to display that many events. Instead, come up
Expand Down Expand Up @@ -326,6 +354,8 @@ private void InitializeWith(InputDevice device)
EditorApplication.playModeStateChanged += OnPlayModeChange;
}

//private List<ValueTuple<string, bool>> m_Flags = new List<ValueTuple<string, bool>>();

private void UpdateDeviceFlags()
{
var flags = new List<string>();
Expand Down Expand Up @@ -397,6 +427,7 @@ internal static InputUpdateType DetermineUpdateTypeToShow(InputDevice device)
private InputDevice.DeviceFlags m_DeviceFlags;
private InputControlTreeView m_ControlTree;
private InputEventTreeView m_EventTree;
private DeviceFlagsTreeView m_DeviceFlagsTree;
private bool m_NeedControlValueRefresh;
private bool m_ReloadEventTree;
private InputEventTrace.ReplayController m_ReplayController;
Expand All @@ -406,8 +437,10 @@ internal static InputUpdateType DetermineUpdateTypeToShow(InputDevice device)
[SerializeField] private int m_DeviceId = InputDevice.InvalidDeviceId;
[SerializeField] private TreeViewState m_ControlTreeState;
[SerializeField] private TreeViewState m_EventTreeState;
[SerializeField] private TreeViewState m_DeviceFlagsTreeState;
[SerializeField] private MultiColumnHeaderState m_ControlTreeHeaderState;
[SerializeField] private MultiColumnHeaderState m_EventTreeHeaderState;
[SerializeField] private MultiColumnHeaderState m_DeviceFlagsHeaderState;
[SerializeField] private bool m_EventTraceDisabled;

private static List<InputDeviceDebuggerWindow> s_OpenDebuggerWindows;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using UnityEditor;
using UnityEditor.IMGUI.Controls;

#if UNITY_EDITOR

namespace UnityEngine.InputSystem.Editor
{
public class DeviceFlagsTreeView : TreeView
{
private InputDevice m_Device;

private enum ColumnId
{
Name,
Value,
COUNT
}

public static DeviceFlagsTreeView Create(InputDevice device, ref TreeViewState treeState, ref MultiColumnHeaderState headerState)
{
if (treeState == null)
treeState = new TreeViewState();

var newHeaderState = CreateHeaderState();
if (headerState != null)
MultiColumnHeaderState.OverwriteSerializedFields(headerState, newHeaderState);
headerState = newHeaderState;

var header = new MultiColumnHeader(headerState);
return new DeviceFlagsTreeView(treeState, header, device);
}

private static MultiColumnHeaderState CreateHeaderState()
{
var columns = new MultiColumnHeaderState.Column[(int)ColumnId.COUNT];

columns[(int)ColumnId.Name] = new MultiColumnHeaderState.Column()
{
width = 320,
minWidth = 60,
headerContent = new GUIContent("Name"),
canSort = false
};
columns[(int)ColumnId.Value] = new MultiColumnHeaderState.Column()
{
width = 80,
minWidth = 60,
headerContent = new GUIContent("Value"),
canSort = false
};

return new MultiColumnHeaderState(columns);
}

private DeviceFlagsTreeView(TreeViewState state, MultiColumnHeader multiColumnHeader, InputDevice device)
: base(state, multiColumnHeader)
{
m_Device = device;
Reload();
}

private void AddFlag(TreeViewItem root, InputDevice.DeviceFlags flag)
{
root.AddChild(new FlagItem()
{
id = 1,
depth = 1,
displayName = "",
Flag = flag
});
}

protected override TreeViewItem BuildRoot()
{
var root = new TreeViewItem { id = 0, depth = -1, displayName = "Root" };

AddFlag(root, InputDevice.DeviceFlags.Native);
AddFlag(root, InputDevice.DeviceFlags.Remote);

AddFlag(root, InputDevice.DeviceFlags.CanRunInBackground);
AddFlag(root, InputDevice.DeviceFlags.CanRunInBackgroundHasBeenQueried);

AddFlag(root, InputDevice.DeviceFlags.UpdateBeforeRender);
AddFlag(root, InputDevice.DeviceFlags.HasStateCallbacks);
AddFlag(root, InputDevice.DeviceFlags.HasControlsWithDefaultState);
AddFlag(root, InputDevice.DeviceFlags.HasDontResetControls);
AddFlag(root, InputDevice.DeviceFlags.HasEventMerger);
AddFlag(root, InputDevice.DeviceFlags.HasEventPreProcessor);

AddFlag(root, InputDevice.DeviceFlags.DisabledInFrontend);
AddFlag(root, InputDevice.DeviceFlags.DisabledInRuntime);
AddFlag(root, InputDevice.DeviceFlags.DisabledWhileInBackground);
AddFlag(root, InputDevice.DeviceFlags.DisabledStateHasBeenQueriedFromRuntime);

return root;
}

protected override void RowGUI(RowGUIArgs args)
{
var columnCount = args.GetNumVisibleColumns();
for (var i = 0; i < columnCount; ++i)
{
var item = (FlagItem)args.item;
ColumnGUI(args.GetCellRect(i), item.Flag, args.GetColumn(i));
}
}

private unsafe void ColumnGUI(Rect cellRect, InputDevice.DeviceFlags flag, int column)
{
CenterRectUsingSingleLineHeight(ref cellRect);

switch (column)
{
case (int)ColumnId.Name:
GUI.Label(cellRect, flag.ToString());
break;
case (int)ColumnId.Value:
{
var isSet = ((m_Device.m_DeviceFlags & flag) != 0);
if (isSet)
GUI.Label(cellRect, "true", EditorStyles.boldLabel);
else
GUI.Label(cellRect, "false");
}
break;
}
}

private class FlagItem : TreeViewItem
{
public InputDevice.DeviceFlags Flag;
}
}
}

#endif // UNITY_EDITOR

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading