experiments with fresnel and shadergraph
[WindSway-HDRP.git] / Library / PackageCache / com.unity.render-pipelines.high-definition@4.10.0-preview / Runtime / Core / Debugging / DebugManager.Actions.cs
blob8d5da4811797dd55dbd401232895ccd1a537a946
1 using System.Collections.Generic;
3 namespace UnityEngine.Experimental.Rendering
5 public enum DebugAction
7 EnableDebugMenu,
8 PreviousDebugPanel,
9 NextDebugPanel,
10 Action,
11 MakePersistent,
12 MoveVertical,
13 MoveHorizontal,
14 Multiplier,
15 DebugActionCount
18 enum DebugActionRepeatMode
20 Never,
21 Delay
24 public sealed partial class DebugManager
26 const string kEnableDebugBtn1 = "Enable Debug Button 1";
27 const string kEnableDebugBtn2 = "Enable Debug Button 2";
28 const string kDebugPreviousBtn = "Debug Previous";
29 const string kDebugNextBtn = "Debug Next";
30 const string kValidateBtn = "Debug Validate";
31 const string kPersistentBtn = "Debug Persistent";
32 const string kDPadVertical = "Debug Vertical";
33 const string kDPadHorizontal = "Debug Horizontal";
34 const string kMultiplierBtn = "Debug Multiplier";
36 DebugActionDesc[] m_DebugActions;
37 DebugActionState[] m_DebugActionStates;
39 void RegisterActions()
41 m_DebugActions = new DebugActionDesc[(int)DebugAction.DebugActionCount];
42 m_DebugActionStates = new DebugActionState[(int)DebugAction.DebugActionCount];
44 var enableDebugMenu = new DebugActionDesc();
45 enableDebugMenu.buttonTriggerList.Add(new[] { kEnableDebugBtn1, kEnableDebugBtn2 });
46 enableDebugMenu.keyTriggerList.Add(new[] { KeyCode.LeftControl, KeyCode.Backspace });
47 enableDebugMenu.repeatMode = DebugActionRepeatMode.Never;
48 AddAction(DebugAction.EnableDebugMenu, enableDebugMenu);
50 var nextDebugPanel = new DebugActionDesc();
51 nextDebugPanel.buttonTriggerList.Add(new[] { kDebugNextBtn });
52 nextDebugPanel.repeatMode = DebugActionRepeatMode.Never;
53 AddAction(DebugAction.NextDebugPanel, nextDebugPanel);
55 var previousDebugPanel = new DebugActionDesc();
56 previousDebugPanel.buttonTriggerList.Add(new[] { kDebugPreviousBtn });
57 previousDebugPanel.repeatMode = DebugActionRepeatMode.Never;
58 AddAction(DebugAction.PreviousDebugPanel, previousDebugPanel);
60 var validate = new DebugActionDesc();
61 validate.buttonTriggerList.Add(new[] { kValidateBtn });
62 validate.repeatMode = DebugActionRepeatMode.Never;
63 AddAction(DebugAction.Action, validate);
65 var persistent = new DebugActionDesc();
66 persistent.buttonTriggerList.Add(new[] { kPersistentBtn });
67 persistent.repeatMode = DebugActionRepeatMode.Never;
68 AddAction(DebugAction.MakePersistent, persistent);
70 var multiplier = new DebugActionDesc();
71 multiplier.buttonTriggerList.Add(new[] { kMultiplierBtn });
72 multiplier.repeatMode = DebugActionRepeatMode.Delay;
73 validate.repeatDelay = 0f;
74 AddAction(DebugAction.Multiplier, multiplier);
76 AddAction(DebugAction.MoveVertical, new DebugActionDesc { axisTrigger = kDPadVertical, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.16f });
77 AddAction(DebugAction.MoveHorizontal, new DebugActionDesc { axisTrigger = kDPadHorizontal, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.16f });
80 void AddAction(DebugAction action, DebugActionDesc desc)
82 int index = (int)action;
83 m_DebugActions[index] = desc;
84 m_DebugActionStates[index] = new DebugActionState();
87 void SampleAction(int actionIndex)
89 var desc = m_DebugActions[actionIndex];
90 var state = m_DebugActionStates[actionIndex];
92 //bool canSampleAction = (state.actionTriggered == false) || (desc.repeatMode == DebugActionRepeatMode.Delay && state.timer > desc.repeatDelay);
93 if (state.runningAction == false)
95 // Check button triggers
96 for (int buttonListIndex = 0; buttonListIndex < desc.buttonTriggerList.Count; ++buttonListIndex)
98 var buttons = desc.buttonTriggerList[buttonListIndex];
99 bool allButtonPressed = true;
101 foreach (var button in buttons)
103 allButtonPressed = Input.GetButton(button);
104 if (!allButtonPressed)
105 break;
108 if (allButtonPressed)
110 state.TriggerWithButton(buttons, 1f);
111 break;
115 // Check axis triggers
116 if (desc.axisTrigger != "")
118 float axisValue = Input.GetAxis(desc.axisTrigger);
120 if (axisValue != 0f)
121 state.TriggerWithAxis(desc.axisTrigger, axisValue);
124 // Check key triggers
125 for (int keyListIndex = 0; keyListIndex < desc.keyTriggerList.Count; ++keyListIndex)
127 var keys = desc.keyTriggerList[keyListIndex];
128 bool allKeyPressed = true;
130 foreach (var key in keys)
132 allKeyPressed = Input.GetKey(key);
133 if (!allKeyPressed)
134 break;
137 if (allKeyPressed)
139 state.TriggerWithKey(keys, 1f);
140 break;
146 void UpdateAction(int actionIndex)
148 var desc = m_DebugActions[actionIndex];
149 var state = m_DebugActionStates[actionIndex];
151 if (state.runningAction)
152 state.Update(desc);
155 public void UpdateActions()
157 for (int actionIndex = 0; actionIndex < m_DebugActions.Length; ++actionIndex)
159 UpdateAction(actionIndex);
160 SampleAction(actionIndex);
164 public float GetAction(DebugAction action)
166 return m_DebugActionStates[(int)action].actionState;
169 void RegisterInputs()
171 #if UNITY_EDITOR
172 var inputEntries = new List<InputManagerEntry>
174 new InputManagerEntry { name = kEnableDebugBtn1, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "left ctrl", altBtnPositive = "joystick button 8" },
175 new InputManagerEntry { name = kEnableDebugBtn2, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "backspace", altBtnPositive = "joystick button 9" },
176 new InputManagerEntry { name = kDebugNextBtn, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "page down", altBtnPositive = "joystick button 5" },
177 new InputManagerEntry { name = kDebugPreviousBtn, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "page up", altBtnPositive = "joystick button 4" },
178 new InputManagerEntry { name = kValidateBtn, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "return", altBtnPositive = "joystick button 0" },
179 new InputManagerEntry { name = kPersistentBtn, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "right shift", altBtnPositive = "joystick button 2" },
180 new InputManagerEntry { name = kMultiplierBtn, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "left shift", altBtnPositive = "joystick button 3" },
181 new InputManagerEntry { name = kDPadHorizontal, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "right", btnNegative = "left", gravity = 1000f, deadZone = 0.001f, sensitivity = 1000f },
182 new InputManagerEntry { name = kDPadVertical, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "up", btnNegative = "down", gravity = 1000f, deadZone = 0.001f, sensitivity = 1000f },
183 new InputManagerEntry { name = kDPadVertical, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Seventh, btnPositive = "up", btnNegative = "down", gravity = 1000f, deadZone = 0.001f, sensitivity = 1000f },
184 new InputManagerEntry { name = kDPadHorizontal, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Sixth, btnPositive = "right", btnNegative = "left", gravity = 1000f, deadZone = 0.001f, sensitivity = 1000f },
187 InputRegistering.RegisterInputs(inputEntries);
188 #endif
192 class DebugActionDesc
194 public List<string[]> buttonTriggerList = new List<string[]>();
195 public string axisTrigger = "";
196 public List<KeyCode[]> keyTriggerList = new List<KeyCode[]>();
197 public DebugActionRepeatMode repeatMode = DebugActionRepeatMode.Never;
198 public float repeatDelay;
201 class DebugActionState
203 enum DebugActionKeyType
205 Button,
206 Axis,
210 DebugActionKeyType m_Type;
211 string[] m_PressedButtons;
212 string m_PressedAxis = "";
213 KeyCode[] m_PressedKeys;
214 bool[] m_TriggerPressedUp;
215 float m_Timer;
217 internal bool runningAction { get; private set; }
218 internal float actionState { get; private set; }
220 void Trigger(int triggerCount, float state)
222 actionState = state;
223 runningAction = true;
224 m_Timer = 0f;
226 m_TriggerPressedUp = new bool[triggerCount];
227 for (int i = 0; i < m_TriggerPressedUp.Length; ++i)
228 m_TriggerPressedUp[i] = false;
231 public void TriggerWithButton(string[] buttons, float state)
233 m_Type = DebugActionKeyType.Button;
234 m_PressedButtons = buttons;
235 m_PressedAxis = "";
236 Trigger(buttons.Length, state);
239 public void TriggerWithAxis(string axis, float state)
241 m_Type = DebugActionKeyType.Axis;
242 m_PressedAxis = axis;
243 Trigger(1, state);
246 public void TriggerWithKey(KeyCode[] keys, float state)
248 m_Type = DebugActionKeyType.Key;
249 m_PressedKeys = keys;
250 m_PressedAxis = "";
251 Trigger(keys.Length, state);
254 void Reset()
256 runningAction = false;
257 m_Timer = 0f;
258 m_TriggerPressedUp = null;
261 public void Update(DebugActionDesc desc)
263 // Always reset this so that the action can only be caught once until repeat/reset
264 actionState = 0f;
266 if (m_TriggerPressedUp != null)
268 m_Timer += Time.deltaTime;
270 for (int i = 0; i < m_TriggerPressedUp.Length; ++i)
272 if (m_Type == DebugActionKeyType.Button)
273 m_TriggerPressedUp[i] |= Input.GetButtonUp(m_PressedButtons[i]);
274 else if (m_Type == DebugActionKeyType.Axis)
275 m_TriggerPressedUp[i] |= Mathf.Approximately(Input.GetAxis(m_PressedAxis), 0f);
276 else
277 m_TriggerPressedUp[i] |= Input.GetKeyUp(m_PressedKeys[i]);
280 bool allTriggerUp = true;
281 foreach (bool value in m_TriggerPressedUp)
282 allTriggerUp &= value;
284 if (allTriggerUp || (m_Timer > desc.repeatDelay && desc.repeatMode == DebugActionRepeatMode.Delay))
285 Reset();