Skip to content

Commit a18b1a5

Browse files
arttu-peltonenEvergreen
authored andcommitted
Refactor input for Rendering Debugger, remove DebugUpdater GameObject when using InputSystem
1 parent dcf0894 commit a18b1a5

10 files changed

Lines changed: 181 additions & 199 deletions

File tree

Packages/com.unity.render-pipelines.core/Runtime/Camera/FreeCamera.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void RegisterInputs()
9999
#endif
100100

101101
#if UNITY_EDITOR && !USE_INPUT_SYSTEM
102+
#pragma warning disable CS0618 // Type or member is obsolete
102103
List<InputManagerEntry> inputEntries = new List<InputManagerEntry>();
103104

104105
// Add new bindings
@@ -112,6 +113,7 @@ void RegisterInputs()
112113
inputEntries.Add(new InputManagerEntry { name = kSpeedAxis, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Seventh, gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f });
113114

114115
InputRegistering.RegisterInputs(inputEntries);
116+
#pragma warning restore CS0618 // Type or member is obsolete
115117
#endif
116118
}
117119

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#if ENABLE_UIELEMENTS_MODULE && (UNITY_EDITOR || DEVELOPMENT_BUILD)
2+
#define ENABLE_RENDERING_DEBUGGER_UI
3+
#endif
4+
#if ENABLE_INPUT_SYSTEM && ENABLE_INPUT_SYSTEM_PACKAGE
5+
#define USE_INPUT_SYSTEM
6+
using UnityEngine.InputSystem;
7+
#endif
8+
9+
// Input support for Rendering Debugger using Input System Package
10+
11+
namespace UnityEngine.Rendering
12+
{
13+
public sealed partial class DebugManager
14+
{
15+
const string k_EnableDebug = "Enable Debug";
16+
const string k_ResetBtn = "Debug Reset";
17+
const string k_DebugPreviousBtn = "Debug Previous";
18+
const string k_DebugNextBtn = "Debug Next";
19+
const string k_PersistentBtn = "Debug Persistent";
20+
const string k_DPadHorizontal = "Debug Horizontal";
21+
const string k_MultiplierBtn = "Debug Multiplier";
22+
23+
#if USE_INPUT_SYSTEM
24+
const string k_AnyTouch = "Any Touch";
25+
26+
readonly InputActionMap m_DebugActionMap = new InputActionMap("Debug Menu");
27+
InputAction m_MultiplierAction;
28+
29+
internal void EnableInputCallbacks()
30+
{
31+
m_DebugActionMap.Enable();
32+
}
33+
34+
internal void DisableInputCallbacks()
35+
{
36+
m_DebugActionMap.Disable();
37+
}
38+
39+
void ToggleRuntimeUI() => displayRuntimeUI = !displayRuntimeUI;
40+
41+
void RegisterDebugInputs()
42+
{
43+
var enableAction = m_DebugActionMap.AddAction(k_EnableDebug, type: InputActionType.Button);
44+
enableAction.AddCompositeBinding("ButtonWithOneModifier")
45+
.With("Modifier", "<Gamepad>/rightStickPress")
46+
.With("Button", "<Gamepad>/leftStickPress")
47+
.With("Modifier", "<Keyboard>/leftCtrl")
48+
.With("Button", "<Keyboard>/backspace");
49+
enableAction.performed += _ => ToggleRuntimeUI();
50+
51+
var anyTouchAction = m_DebugActionMap.AddAction(k_AnyTouch, type: InputActionType.Button);
52+
anyTouchAction.AddBinding("<Touchscreen>/touch2/tap"); // touch2 means "third finger"
53+
anyTouchAction.performed += ctx =>
54+
{
55+
// We want a three-finger double-tap to toggle the debug UI. However, it's a bit tricky to perform a
56+
// three-finger tap consistently. Therefore, to be slightly error-tolerant, we actually check for a
57+
// "double-tap action on the third tracked finger".
58+
var pressControl = ctx.control as InputSystem.Controls.ButtonControl;
59+
var touchControl = pressControl?.parent as InputSystem.Controls.TouchControl;
60+
int tapCount = touchControl?.tapCount?.ReadValue() ?? 0;
61+
if (tapCount == 2)
62+
ToggleRuntimeUI();
63+
};
64+
65+
#if ENABLE_RENDERING_DEBUGGER_UI
66+
var resetAction = m_DebugActionMap.AddAction(k_ResetBtn, type: InputActionType.Button);
67+
resetAction.AddCompositeBinding("ButtonWithOneModifier")
68+
.With("Modifier", "<Gamepad>/rightStickPress")
69+
.With("Button", "<Gamepad>/b")
70+
.With("Modifier", "<Keyboard>/leftAlt")
71+
.With("Button", "<Keyboard>/backspace");
72+
resetAction.performed += _ => { Reset(); };
73+
74+
var next = m_DebugActionMap.AddAction(k_DebugNextBtn, type: InputActionType.Button);
75+
next.AddBinding("<Keyboard>/pageDown");
76+
next.AddBinding("<Gamepad>/rightShoulder");
77+
next.performed += _ => { m_RuntimeDebugWindow.SelectNextPanel(); };
78+
79+
var previous = m_DebugActionMap.AddAction(k_DebugPreviousBtn, type: InputActionType.Button);
80+
previous.AddBinding("<Keyboard>/pageUp");
81+
previous.AddBinding("<Gamepad>/leftShoulder");
82+
previous.performed += _ => { m_RuntimeDebugWindow.SelectPreviousPanel(); };
83+
84+
var persistentAction = m_DebugActionMap.AddAction(k_PersistentBtn, type: InputActionType.Button);
85+
persistentAction.AddBinding("<Keyboard>/rightShift");
86+
persistentAction.AddBinding("<Gamepad>/x");
87+
persistentAction.performed += _ => { TogglePersistent(); };
88+
89+
m_MultiplierAction = m_DebugActionMap.AddAction(k_MultiplierBtn, type: InputActionType.Value);
90+
m_MultiplierAction.AddBinding("<Keyboard>/leftShift");
91+
m_MultiplierAction.AddBinding("<Gamepad>/y");
92+
93+
var moveHorizontalAction = m_DebugActionMap.AddAction(k_DPadHorizontal);
94+
moveHorizontalAction.AddCompositeBinding("1DAxis")
95+
.With("Positive", "<Gamepad>/dpad/right")
96+
.With("Negative", "<Gamepad>/dpad/left")
97+
.With("Positive", "<Keyboard>/rightArrow")
98+
.With("Negative", "<Keyboard>/leftArrow");
99+
moveHorizontalAction.performed += ctx =>
100+
{
101+
bool multiplierPressed = m_MultiplierAction.IsPressed();
102+
bool increment = ctx.ReadValue<float>() > 0.0f;
103+
if (increment)
104+
{
105+
selectedWidget.OnIncrement(multiplierPressed);
106+
}
107+
else
108+
{
109+
selectedWidget.OnDecrement(multiplierPressed);
110+
}
111+
};
112+
#endif
113+
}
114+
#endif
115+
}
116+
}

Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugManager.Input.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)