| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using System.Linq; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.EventSystems; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// Mapping for Trigger actions |
| | 10 | | /// </summary> |
| | 11 | | public enum DCLAction_Trigger |
| | 12 | | { |
| | 13 | | //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts |
| | 14 | | CameraChange = 100, |
| | 15 | |
|
| | 16 | | ToggleNavMap = 110, |
| | 17 | | ToggleFriends = 120, |
| | 18 | | CloseWindow = 121, |
| | 19 | | ToggleWorldChat = 122, |
| | 20 | | ToggleUIVisibility = 123, |
| | 21 | | ToggleControlsHud = 124, |
| | 22 | | ToggleSettings = 125, |
| | 23 | | ToggleExploreHud = 126, |
| | 24 | | ToggleVoiceChatRecording = 127, |
| | 25 | | ToggleAvatarEditorHud = 128, |
| | 26 | | ToggleQuestsPanelHud = 129, |
| | 27 | | ToggleAvatarNamesHud = 130, |
| | 28 | |
|
| | 29 | | OpenExpressions = 200, |
| | 30 | | Expression_Wave = 201, |
| | 31 | | Expression_FistPump = 202, |
| | 32 | | Expression_Robot = 203, |
| | 33 | | Expression_RaiseHand = 204, |
| | 34 | | Expression_Clap = 205, |
| | 35 | | Expression_ThrowMoney = 206, |
| | 36 | | Expression_SendKiss = 207, |
| | 37 | |
|
| | 38 | | //Builder In World 4xx |
| | 39 | | BuildEditModeChange = 408, |
| | 40 | | BuildEditModeToggleUI = 409, |
| | 41 | | BuildEditModeToggleEntityList = 410, |
| | 42 | | BuildEditModeToggleCatalog = 411, |
| | 43 | | BuildEditModeToggleSceneInfo = 412, |
| | 44 | | BuildEditModeToggleChangeCamera = 413, |
| | 45 | | BuildEditModeToggleControls = 414, |
| | 46 | | BuildEditModeToggleSnapMode = 415, |
| | 47 | | BuildEditModeUndoAction = 417, |
| | 48 | | BuildEditModeRedoAction = 418, |
| | 49 | | BuildEditModeQuickBar1 = 419, |
| | 50 | | BuildEditModeQuickBar2 = 420, |
| | 51 | | BuildEditModeQuickBar3 = 421, |
| | 52 | | BuildEditModeQuickBar4 = 422, |
| | 53 | | BuildEditModeQuickBar5 = 423, |
| | 54 | | BuildEditModeQuickBar6 = 424, |
| | 55 | | BuildEditModeQuickBar7 = 425, |
| | 56 | | BuildEditModeQuickBar8 = 426, |
| | 57 | | BuildEditModeQuickBar9 = 427, |
| | 58 | | BuildEditModeDuplicate = 428, |
| | 59 | | BuildEditModeTranslate = 429, |
| | 60 | | BuildEditModeRotate = 430, |
| | 61 | | BuildEditModeScale = 431, |
| | 62 | | BuildEditModeDelete = 434, |
| | 63 | | BuildEditModeFocusSelectedEntities = 435, |
| | 64 | | BuildEditModeReset = 443, |
| | 65 | | BuildEditHideSelectedEntities = 444, |
| | 66 | | BuildEditShowAllEntities = 445, |
| | 67 | | BuildEditModeResetCamera = 446, |
| | 68 | | BuildEditModeZoomIn = 447, |
| | 69 | | BuildEditModeZoomOut = 448 |
| | 70 | | } |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// Mapping for hold actions |
| | 74 | | /// </summary> |
| | 75 | | public enum DCLAction_Hold |
| | 76 | | { |
| | 77 | | //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts |
| | 78 | | Sprint = 1, |
| | 79 | | Jump = 2, |
| | 80 | | FreeCameraMode = 101, |
| | 81 | | VoiceChatRecording = 102, |
| | 82 | | DefaultConfirmAction = 300, |
| | 83 | | DefaultCancelAction = 301, |
| | 84 | | BuildEditModeMultiSelection = 432, |
| | 85 | | BuildEditModeSquareMultiSelection = 433, |
| | 86 | | BuildEditModeFirstPersonRotation = 436, |
| | 87 | | BuildEditModeCameraAdvanceFoward = 437, |
| | 88 | | BuildEditModeCameraAdvanceBack = 438, |
| | 89 | | BuildEditModeCameraAdvanceLeft = 439, |
| | 90 | | BuildEditModeCameraAdvanceRight = 440, |
| | 91 | | BuildEditModeCameraAdvanceUp = 441, |
| | 92 | | BuildEditModeCameraAdvanceDown = 442, |
| | 93 | | BuildEditModeCameraPan = 446 |
| | 94 | | } |
| | 95 | |
|
| | 96 | | /// <summary> |
| | 97 | | /// Mapping for measurable actions |
| | 98 | | /// </summary> |
| | 99 | | public enum DCLAction_Measurable |
| | 100 | | { |
| | 101 | | //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts |
| | 102 | | CharacterXAxis = 1, |
| | 103 | | CharacterYAxis = 2, |
| | 104 | | CameraXAxis = 3, |
| | 105 | | CameraYAxis = 4, |
| | 106 | | } |
| | 107 | |
|
| | 108 | | /// <summary> |
| | 109 | | /// Group of actions currently actived |
| | 110 | | /// </summary> |
| | 111 | | public enum InputTypeMode |
| | 112 | | { |
| | 113 | | OFF, |
| | 114 | | GENERAL, |
| | 115 | | BUILD_MODE_LOADING, |
| | 116 | | BUILD_MODE |
| | 117 | | } |
| | 118 | |
|
| | 119 | | /// <summary> |
| | 120 | | /// Input Controller will map inputs(keys/mouse/axis) to DCL actions, check if they can be triggered (modifiers) and rai |
| | 121 | | /// </summary> |
| | 122 | | public class InputController : MonoBehaviour |
| | 123 | | { |
| 1 | 124 | | public static bool ENABLE_THIRD_PERSON_CAMERA = true; |
| | 125 | |
|
| | 126 | | [Header("General Input")] |
| | 127 | | public InputAction_Trigger[] triggerTimeActions; |
| | 128 | |
|
| | 129 | | public InputAction_Hold[] holdActions; |
| | 130 | | public InputAction_Measurable[] measurableActions; |
| | 131 | |
|
| | 132 | | [Header("BuildMode Input")] |
| | 133 | | public InputAction_Trigger[] builderTriggerTimeActions; |
| | 134 | |
|
| | 135 | | public InputAction_Hold[] builderHoldActions; |
| | 136 | | public InputAction_Trigger[] loadingBuilderTriggerTimeActions; |
| | 137 | |
|
| 20150 | 138 | | bool renderingEnabled => CommonScriptableObjects.rendererState.Get(); |
| 114304 | 139 | | bool allUIHidden => CommonScriptableObjects.allUIHidden.Get(); |
| 328 | 140 | | public InputTypeMode inputTypeMode { get; set; } = InputTypeMode.GENERAL; |
| | 141 | |
|
| | 142 | | private void Update() |
| | 143 | | { |
| 20150 | 144 | | if (!renderingEnabled) |
| | 145 | | { |
| 327 | 146 | | Stop_Measurable(measurableActions); |
| 327 | 147 | | return; |
| | 148 | | } |
| | 149 | |
|
| 19823 | 150 | | switch (inputTypeMode) |
| | 151 | | { |
| | 152 | | case InputTypeMode.OFF: |
| 0 | 153 | | Stop_Measurable(measurableActions); |
| 0 | 154 | | return; |
| | 155 | | case InputTypeMode.GENERAL: |
| 19774 | 156 | | Update_Trigger(triggerTimeActions); |
| 19774 | 157 | | Update_Hold(holdActions); |
| 19774 | 158 | | Update_Measurable(measurableActions); |
| 19774 | 159 | | break; |
| | 160 | | case InputTypeMode.BUILD_MODE_LOADING: |
| 49 | 161 | | Update_Trigger(loadingBuilderTriggerTimeActions); |
| 49 | 162 | | Stop_Measurable(measurableActions); |
| 49 | 163 | | break; |
| | 164 | | case InputTypeMode.BUILD_MODE: |
| 0 | 165 | | Update_Trigger(builderTriggerTimeActions); |
| 0 | 166 | | Update_Hold(builderHoldActions); |
| 0 | 167 | | Update_Measurable(measurableActions); |
| | 168 | | break; |
| | 169 | | } |
| 0 | 170 | | } |
| | 171 | |
|
| | 172 | | /// <summary> |
| | 173 | | /// Map the trigger actions to inputs + modifiers and check if their events must be triggered |
| | 174 | | /// </summary> |
| | 175 | | public void Update_Trigger(InputAction_Trigger[] triggerTimeActions) |
| | 176 | | { |
| 909800 | 177 | | for (var i = 0; i < triggerTimeActions.Length; i++) |
| | 178 | | { |
| 435077 | 179 | | var action = triggerTimeActions[i]; |
| | 180 | |
|
| 435077 | 181 | | if (action.isTriggerBlocked != null && action.isTriggerBlocked.Get()) |
| | 182 | | continue; |
| | 183 | |
|
| 422057 | 184 | | switch (action.GetDCLAction()) |
| | 185 | | { |
| | 186 | | case DCLAction_Trigger.CameraChange: |
| | 187 | | //Disable until the fine-tuning is ready |
| 19774 | 188 | | if (ENABLE_THIRD_PERSON_CAMERA) |
| 19774 | 189 | | InputProcessor.FromKey(action, KeyCode.V, |
| | 190 | | modifiers: InputProcessor.Modifier.NeedsPointerLocked | |
| | 191 | | InputProcessor.Modifier.FocusNotInInput); |
| 19774 | 192 | | break; |
| | 193 | | case DCLAction_Trigger.ToggleNavMap: |
| 18906 | 194 | | if (allUIHidden) |
| | 195 | | break; |
| 11251 | 196 | | InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 11251 | 197 | | InputProcessor.FromKey(action, KeyCode.Tab, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 11251 | 198 | | InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 11251 | 199 | | break; |
| | 200 | | case DCLAction_Trigger.ToggleFriends: |
| 18906 | 201 | | if (allUIHidden) |
| | 202 | | break; |
| 11251 | 203 | | InputProcessor.FromKey(action, KeyCode.L, modifiers: InputProcessor.Modifier.None); |
| 11251 | 204 | | break; |
| | 205 | | case DCLAction_Trigger.ToggleWorldChat: |
| 18906 | 206 | | if (allUIHidden) |
| | 207 | | break; |
| 11251 | 208 | | InputProcessor.FromKey(action, KeyCode.Return, modifiers: InputProcessor.Modifier.None); |
| 11251 | 209 | | break; |
| | 210 | | case DCLAction_Trigger.ToggleUIVisibility: |
| 18906 | 211 | | InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.None); |
| 18906 | 212 | | break; |
| | 213 | | case DCLAction_Trigger.CloseWindow: |
| 19774 | 214 | | if (allUIHidden || DataStore.i.isSignUpFlow.Get()) |
| | 215 | | break; |
| 11251 | 216 | | InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.None); |
| 11251 | 217 | | break; |
| | 218 | | case DCLAction_Trigger.OpenExpressions: |
| 18906 | 219 | | if (allUIHidden) |
| | 220 | | break; |
| 11251 | 221 | | InputProcessor.FromKey(action, KeyCode.B, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 11251 | 222 | | InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 11251 | 223 | | break; |
| | 224 | | case DCLAction_Trigger.ToggleControlsHud: |
| 18906 | 225 | | InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 18906 | 226 | | break; |
| | 227 | | case DCLAction_Trigger.ToggleSettings: |
| 19774 | 228 | | InputProcessor.FromKey(action, KeyCode.P, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 19774 | 229 | | break; |
| | 230 | | case DCLAction_Trigger.ToggleExploreHud: |
| 18906 | 231 | | if (allUIHidden) |
| | 232 | | break; |
| 11251 | 233 | | InputProcessor.FromKey(action, KeyCode.X, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 11251 | 234 | | break; |
| | 235 | | case DCLAction_Trigger.Expression_Wave: |
| 18906 | 236 | | InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 18906 | 237 | | break; |
| | 238 | | case DCLAction_Trigger.Expression_FistPump: |
| 18906 | 239 | | InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 18906 | 240 | | break; |
| | 241 | | case DCLAction_Trigger.Expression_Robot: |
| 18906 | 242 | | InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 18906 | 243 | | break; |
| | 244 | | case DCLAction_Trigger.Expression_RaiseHand: |
| 18906 | 245 | | InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 18906 | 246 | | break; |
| | 247 | | case DCLAction_Trigger.Expression_Clap: |
| 18906 | 248 | | InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 18906 | 249 | | break; |
| | 250 | | case DCLAction_Trigger.Expression_ThrowMoney: |
| 18906 | 251 | | InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 18906 | 252 | | break; |
| | 253 | | case DCLAction_Trigger.Expression_SendKiss: |
| 18906 | 254 | | InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 18906 | 255 | | break; |
| | 256 | | case DCLAction_Trigger.BuildEditModeChange: |
| 19823 | 257 | | InputProcessor.FromKey(action, KeyCode.K, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 19823 | 258 | | break; |
| | 259 | | case DCLAction_Trigger.ToggleVoiceChatRecording: |
| 19774 | 260 | | InputProcessor.FromKey(action, KeyCode.T, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 19774 | 261 | | break; |
| | 262 | | case DCLAction_Trigger.ToggleAvatarEditorHud: |
| 18906 | 263 | | InputProcessor.FromKey(action, KeyCode.I, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 18906 | 264 | | break; |
| | 265 | | case DCLAction_Trigger.BuildEditModeToggleUI: |
| 0 | 266 | | InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 267 | | break; |
| | 268 | | case DCLAction_Trigger.BuildEditModeToggleChangeCamera: |
| 0 | 269 | | InputProcessor.FromKey(action, KeyCode.V, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 270 | | break; |
| | 271 | | case DCLAction_Trigger.BuildEditModeToggleControls: |
| 0 | 272 | | InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 273 | | break; |
| | 274 | | case DCLAction_Trigger.BuildEditModeToggleSnapMode: |
| 0 | 275 | | InputProcessor.FromKey(action, KeyCode.O, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 276 | | break; |
| | 277 | | case DCLAction_Trigger.BuildEditModeRedoAction: |
| 0 | 278 | | InputProcessor.FromKey(action, KeyCode.Y, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 279 | | break; |
| | 280 | | case DCLAction_Trigger.BuildEditModeUndoAction: |
| 0 | 281 | | InputProcessor.FromKey(action, KeyCode.Z, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 282 | | break; |
| | 283 | | case DCLAction_Trigger.BuildEditModeQuickBar1: |
| 0 | 284 | | InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 285 | | break; |
| | 286 | | case DCLAction_Trigger.BuildEditModeQuickBar2: |
| 0 | 287 | | InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 288 | | break; |
| | 289 | | case DCLAction_Trigger.BuildEditModeQuickBar3: |
| 0 | 290 | | InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 291 | | break; |
| | 292 | | case DCLAction_Trigger.BuildEditModeQuickBar4: |
| 0 | 293 | | InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 294 | | break; |
| | 295 | | case DCLAction_Trigger.BuildEditModeQuickBar5: |
| 0 | 296 | | InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 297 | | break; |
| | 298 | | case DCLAction_Trigger.BuildEditModeQuickBar6: |
| 0 | 299 | | InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 300 | | break; |
| | 301 | | case DCLAction_Trigger.BuildEditModeQuickBar7: |
| 0 | 302 | | InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 303 | | break; |
| | 304 | | case DCLAction_Trigger.BuildEditModeQuickBar8: |
| 0 | 305 | | InputProcessor.FromKey(action, KeyCode.Alpha8, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 306 | | break; |
| | 307 | | case DCLAction_Trigger.BuildEditModeQuickBar9: |
| 0 | 308 | | InputProcessor.FromKey(action, KeyCode.Alpha9, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 309 | | break; |
| | 310 | | case DCLAction_Trigger.BuildEditModeDelete: |
| 0 | 311 | | InputProcessor.FromKey(action, KeyCode.Delete, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 312 | | InputProcessor.FromKey(action, KeyCode.Backspace, modifiers: InputProcessor.Modifier.FocusNotInInput |
| 0 | 313 | | break; |
| | 314 | | case DCLAction_Trigger.BuildEditModeDuplicate: |
| 0 | 315 | | InputProcessor.FromKey(action, KeyCode.D, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 316 | | break; |
| | 317 | | case DCLAction_Trigger.BuildEditModeTranslate: |
| 0 | 318 | | InputProcessor.FromKey(action, KeyCode.G, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 319 | | InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 320 | | break; |
| | 321 | | case DCLAction_Trigger.BuildEditModeRotate: |
| 0 | 322 | | InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 323 | | break; |
| | 324 | | case DCLAction_Trigger.BuildEditModeScale: |
| 0 | 325 | | InputProcessor.FromKey(action, KeyCode.S, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 326 | | break; |
| | 327 | | case DCLAction_Trigger.BuildEditModeFocusSelectedEntities: |
| 0 | 328 | | InputProcessor.FromKey(action, KeyCode.F, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 329 | | break; |
| | 330 | | case DCLAction_Trigger.BuildEditModeReset: |
| 0 | 331 | | InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 332 | | break; |
| | 333 | | case DCLAction_Trigger.BuildEditHideSelectedEntities: |
| 0 | 334 | | InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 335 | | break; |
| | 336 | | case DCLAction_Trigger.BuildEditShowAllEntities: |
| 0 | 337 | | InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 338 | | break; |
| | 339 | | case DCLAction_Trigger.BuildEditModeResetCamera: |
| 0 | 340 | | InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 341 | | break; |
| | 342 | | case DCLAction_Trigger.BuildEditModeZoomIn: |
| 0 | 343 | | InputProcessor.FromKey(action, KeyCode.KeypadPlus, modifiers: InputProcessor.Modifier.FocusNotInInpu |
| 0 | 344 | | break; |
| | 345 | | case DCLAction_Trigger.BuildEditModeZoomOut: |
| 0 | 346 | | InputProcessor.FromKey(action, KeyCode.KeypadMinus, modifiers: InputProcessor.Modifier.FocusNotInInp |
| 0 | 347 | | break; |
| | 348 | | case DCLAction_Trigger.ToggleQuestsPanelHud: |
| 19774 | 349 | | InputProcessor.FromKey(action, KeyCode.J, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 19774 | 350 | | break; |
| | 351 | | case DCLAction_Trigger.ToggleAvatarNamesHud: |
| 19774 | 352 | | InputProcessor.FromKey(action, KeyCode.N, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 19774 | 353 | | break; |
| | 354 | | default: |
| 0 | 355 | | throw new ArgumentOutOfRangeException(); |
| | 356 | | } |
| | 357 | | } |
| 19823 | 358 | | } |
| | 359 | |
|
| | 360 | | /// <summary> |
| | 361 | | /// Map the hold actions to inputs + modifiers and check if their events must be triggered |
| | 362 | | /// </summary> |
| | 363 | | private void Update_Hold(InputAction_Hold[] holdActions) |
| | 364 | | { |
| 316384 | 365 | | for (var i = 0; i < holdActions.Length; i++) |
| | 366 | | { |
| 138418 | 367 | | var action = holdActions[i]; |
| 138418 | 368 | | switch (action.GetDCLAction()) |
| | 369 | | { |
| | 370 | | case DCLAction_Hold.Sprint: |
| 19774 | 371 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.NeedsPointerLocked); |
| 19774 | 372 | | break; |
| | 373 | | case DCLAction_Hold.Jump: |
| 19774 | 374 | | InputProcessor.FromKey(action, KeyCode.Space, InputProcessor.Modifier.NeedsPointerLocked); |
| 19774 | 375 | | break; |
| | 376 | | case DCLAction_Hold.FreeCameraMode: |
| | 377 | | //Disable until the fine-tuning is ready |
| 19774 | 378 | | if (ENABLE_THIRD_PERSON_CAMERA) |
| 19774 | 379 | | InputProcessor.FromKey(action, KeyCode.Y, InputProcessor.Modifier.NeedsPointerLocked); |
| 19774 | 380 | | break; |
| | 381 | | case DCLAction_Hold.VoiceChatRecording: |
| | 382 | | // Push to talk functionality only triggers if no modifier key is pressed |
| 39548 | 383 | | InputProcessor.FromKey(action, KeyCode.T, InputProcessor.Modifier.FocusNotInInput, null); |
| 39548 | 384 | | break; |
| | 385 | | case DCLAction_Hold.DefaultConfirmAction: |
| 19774 | 386 | | InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.None); |
| 19774 | 387 | | break; |
| | 388 | | case DCLAction_Hold.DefaultCancelAction: |
| 19774 | 389 | | InputProcessor.FromKey(action, KeyCode.F, InputProcessor.Modifier.None); |
| 19774 | 390 | | break; |
| | 391 | | case DCLAction_Hold.BuildEditModeMultiSelection: |
| 0 | 392 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 393 | | break; |
| | 394 | | case DCLAction_Hold.BuildEditModeSquareMultiSelection: |
| 0 | 395 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 396 | | break; |
| | 397 | | case DCLAction_Hold.BuildEditModeFirstPersonRotation: |
| 0 | 398 | | InputProcessor.FromKey(action, KeyCode.R, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 399 | | break; |
| | 400 | | case DCLAction_Hold.BuildEditModeCameraAdvanceFoward: |
| 0 | 401 | | InputProcessor.FromKey(action, KeyCode.UpArrow, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 402 | | InputProcessor.FromKey(action, KeyCode.W, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 403 | | break; |
| | 404 | | case DCLAction_Hold.BuildEditModeCameraAdvanceBack: |
| 0 | 405 | | InputProcessor.FromKey(action, KeyCode.DownArrow, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 406 | | InputProcessor.FromKey(action, KeyCode.S, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 407 | | break; |
| | 408 | | case DCLAction_Hold.BuildEditModeCameraAdvanceLeft: |
| 0 | 409 | | InputProcessor.FromKey(action, KeyCode.LeftArrow, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 410 | | InputProcessor.FromKey(action, KeyCode.A, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 411 | | break; |
| | 412 | | case DCLAction_Hold.BuildEditModeCameraAdvanceRight: |
| 0 | 413 | | InputProcessor.FromKey(action, KeyCode.RightArrow, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 414 | | InputProcessor.FromKey(action, KeyCode.D, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 415 | | break; |
| | 416 | | case DCLAction_Hold.BuildEditModeCameraAdvanceUp: |
| 0 | 417 | | InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 418 | | break; |
| | 419 | | case DCLAction_Hold.BuildEditModeCameraAdvanceDown: |
| 0 | 420 | | InputProcessor.FromKey(action, KeyCode.Q, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 421 | | break; |
| | 422 | | case DCLAction_Hold.BuildEditModeCameraPan: |
| 0 | 423 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 424 | | break; |
| | 425 | | default: |
| 0 | 426 | | throw new ArgumentOutOfRangeException(); |
| | 427 | | } |
| | 428 | | } |
| 19774 | 429 | | } |
| | 430 | |
|
| | 431 | | /// <summary> |
| | 432 | | /// Map the measurable actions to inputs + modifiers and check if their events must be triggered |
| | 433 | | /// </summary> |
| | 434 | | private void Update_Measurable(InputAction_Measurable[] measurableActions) |
| | 435 | | { |
| 197740 | 436 | | for (var i = 0; i < measurableActions.Length; i++) |
| | 437 | | { |
| 79096 | 438 | | var action = measurableActions[i]; |
| 79096 | 439 | | switch (action.GetDCLAction()) |
| | 440 | | { |
| | 441 | | case DCLAction_Measurable.CharacterXAxis: |
| 19774 | 442 | | InputProcessor.FromAxis(action, "Horizontal", InputProcessor.Modifier.NeedsPointerLocked); |
| 19774 | 443 | | break; |
| | 444 | | case DCLAction_Measurable.CharacterYAxis: |
| 19774 | 445 | | InputProcessor.FromAxis(action, "Vertical", InputProcessor.Modifier.NeedsPointerLocked); |
| 19774 | 446 | | break; |
| | 447 | | case DCLAction_Measurable.CameraXAxis: |
| 19774 | 448 | | InputProcessor.FromAxis(action, "Mouse X", InputProcessor.Modifier.NeedsPointerLocked); |
| 19774 | 449 | | break; |
| | 450 | | case DCLAction_Measurable.CameraYAxis: |
| 19774 | 451 | | InputProcessor.FromAxis(action, "Mouse Y", InputProcessor.Modifier.NeedsPointerLocked); |
| 19774 | 452 | | break; |
| | 453 | | default: |
| 0 | 454 | | throw new ArgumentOutOfRangeException(); |
| | 455 | | } |
| | 456 | | } |
| 19774 | 457 | | } |
| | 458 | |
|
| | 459 | | private void Stop_Measurable(InputAction_Measurable[] measurableActions) |
| | 460 | | { |
| 3760 | 461 | | for (var i = 0; i < measurableActions.Length; i++) |
| | 462 | | { |
| 1504 | 463 | | measurableActions[i].RaiseOnValueChanged(0); |
| | 464 | | } |
| 376 | 465 | | } |
| | 466 | | } |
| | 467 | |
|
| | 468 | | /// <summary> |
| | 469 | | /// Helper class that wraps the processing of inputs and modifiers to trigger actions events |
| | 470 | | /// </summary> |
| | 471 | | public static class InputProcessor |
| | 472 | | { |
| | 473 | | private static readonly KeyCode[] MODIFIER_KEYS = new[] { KeyCode.LeftControl, KeyCode.LeftAlt, KeyCode.LeftShift, K |
| | 474 | |
|
| | 475 | | [Flags] |
| | 476 | | public enum Modifier |
| | 477 | | { |
| | 478 | | //Set the values as bit masks |
| | 479 | | None = 0b0000000, // No modifier needed |
| | 480 | | NeedsPointerLocked = 0b0000001, // The pointer must be locked to the game |
| | 481 | | FocusNotInInput = 0b0000010, // The game focus cannot be in an input field |
| | 482 | | } |
| | 483 | |
|
| | 484 | | /// <summary> |
| | 485 | | /// Check if the modifier keys are pressed |
| | 486 | | /// </summary> |
| | 487 | | /// <param name="modifierKeys"> Keycodes modifiers</param> |
| | 488 | | /// <returns></returns> |
| | 489 | | public static Boolean PassModifierKeys(KeyCode[] modifierKeys) |
| | 490 | | { |
| | 491 | | for (var i = 0; i < MODIFIER_KEYS.Length; i++) |
| | 492 | | { |
| | 493 | | var keyCode = MODIFIER_KEYS[i]; |
| | 494 | | var pressed = Input.GetKey(keyCode); |
| | 495 | | if (modifierKeys == null) |
| | 496 | | { |
| | 497 | | if (pressed) |
| | 498 | | return false; |
| | 499 | | } |
| | 500 | | else |
| | 501 | | { |
| | 502 | | if (modifierKeys.Contains(keyCode) != pressed) |
| | 503 | | return false; |
| | 504 | | } |
| | 505 | | } |
| | 506 | |
|
| | 507 | | return true; |
| | 508 | | } |
| | 509 | |
|
| | 510 | | /// <summary> |
| | 511 | | /// Check if a miscellaneous modifiers are present. These modifiers are related to the meta-state of the application |
| | 512 | | /// they can be anything such as mouse pointer state, where the focus is, camera mode... |
| | 513 | | /// </summary> |
| | 514 | | /// <param name="modifiers"></param> |
| | 515 | | /// <returns></returns> |
| | 516 | | public static bool PassModifiers(Modifier modifiers) |
| | 517 | | { |
| | 518 | | if (IsModifierSet(modifiers, Modifier.NeedsPointerLocked) && !DCL.Helpers.Utils.isCursorLocked) |
| | 519 | | return false; |
| | 520 | |
|
| | 521 | | if (IsModifierSet(modifiers, Modifier.FocusNotInInput) && FocusIsInInputField()) |
| | 522 | | return false; |
| | 523 | |
|
| | 524 | | return true; |
| | 525 | | } |
| | 526 | |
|
| | 527 | | /// <summary> |
| | 528 | | /// Process an input action mapped to a keyboard key. |
| | 529 | | /// </summary> |
| | 530 | | /// <param name="action">Trigger Action to perform</param> |
| | 531 | | /// <param name="key">KeyCode mapped to this action</param> |
| | 532 | | /// <param name="modifierKeys">KeyCodes required to perform the action</param> |
| | 533 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 534 | | public static void FromKey(InputAction_Trigger action, KeyCode key, KeyCode[] modifierKeys = null, |
| | 535 | | Modifier modifiers = Modifier.None) |
| | 536 | | { |
| | 537 | | if (!PassModifiers(modifiers)) |
| | 538 | | return; |
| | 539 | |
|
| | 540 | | if (!PassModifierKeys(modifierKeys)) |
| | 541 | | return; |
| | 542 | |
|
| | 543 | | if (Input.GetKeyDown(key)) |
| | 544 | | action.RaiseOnTriggered(); |
| | 545 | | } |
| | 546 | |
|
| | 547 | | /// <summary> |
| | 548 | | /// Process an input action mapped to a button. |
| | 549 | | /// </summary> |
| | 550 | | /// <param name="action">Trigger Action to perform</param> |
| | 551 | | /// <param name="mouseButtonIdx">Index of the mouse button mapped to this action</param> |
| | 552 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 553 | | public static void FromMouseButton(InputAction_Trigger action, int mouseButtonIdx, |
| | 554 | | Modifier modifiers = Modifier.None) |
| | 555 | | { |
| | 556 | | if (!PassModifiers(modifiers)) |
| | 557 | | return; |
| | 558 | |
|
| | 559 | | if (Input.GetMouseButton(mouseButtonIdx)) |
| | 560 | | action.RaiseOnTriggered(); |
| | 561 | | } |
| | 562 | |
|
| | 563 | | /// <summary> |
| | 564 | | /// Process an input action mapped to a keyboard key |
| | 565 | | /// </summary> |
| | 566 | | /// <param name="action">Hold Action to perform</param> |
| | 567 | | /// <param name="key">KeyCode mapped to this action</param> |
| | 568 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 569 | | public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers = Modifier.None) |
| | 570 | | { |
| | 571 | | if (!PassModifiers(modifiers)) |
| | 572 | | return; |
| | 573 | |
|
| | 574 | | if (Input.GetKeyDown(key)) |
| | 575 | | action.RaiseOnStarted(); |
| | 576 | | if (Input.GetKeyUp(key)) |
| | 577 | | action.RaiseOnFinished(); |
| | 578 | | } |
| | 579 | |
|
| | 580 | | /// <summary> |
| | 581 | | /// Process an input action mapped to a keyboard key |
| | 582 | | /// </summary> |
| | 583 | | /// <param name="action">Hold Action to perform</param> |
| | 584 | | /// <param name="key">KeyCode mapped to this action</param> |
| | 585 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 586 | | /// <param name="modifierKeys">KeyCodes required to perform the action</param> |
| | 587 | | public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers, KeyCode[] modifierKeys) |
| | 588 | | { |
| | 589 | | if (!PassModifierKeys(modifierKeys)) |
| | 590 | | return; |
| | 591 | |
|
| | 592 | | FromKey(action, key, modifiers); |
| | 593 | | } |
| | 594 | |
|
| | 595 | | /// <summary> |
| | 596 | | /// Process an input action mapped to a mouse button |
| | 597 | | /// </summary> |
| | 598 | | /// <param name="action">Hold Action to perform</param> |
| | 599 | | /// <param name="mouseButtonIdx">Index of the mouse button</param> |
| | 600 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 601 | | public static void FromMouse(InputAction_Hold action, int mouseButtonIdx, Modifier modifiers = Modifier.None) |
| | 602 | | { |
| | 603 | | if (!PassModifiers(modifiers)) |
| | 604 | | return; |
| | 605 | |
|
| | 606 | | if (Input.GetMouseButtonDown(mouseButtonIdx)) |
| | 607 | | action.RaiseOnStarted(); |
| | 608 | | if (Input.GetMouseButtonUp(mouseButtonIdx)) |
| | 609 | | action.RaiseOnFinished(); |
| | 610 | | } |
| | 611 | |
|
| | 612 | | /// <summary> |
| | 613 | | /// Process an input action mapped to an axis |
| | 614 | | /// </summary> |
| | 615 | | /// <param name="action">Measurable Action to perform</param> |
| | 616 | | /// <param name="axisName">Axis name</param> |
| | 617 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 618 | | public static void FromAxis(InputAction_Measurable action, string axisName, Modifier modifiers = Modifier.None) |
| | 619 | | { |
| | 620 | | if (!PassModifiers(modifiers)) |
| | 621 | | { |
| | 622 | | action.RaiseOnValueChanged(0); |
| | 623 | | return; |
| | 624 | | } |
| | 625 | |
|
| | 626 | | action.RaiseOnValueChanged(Input.GetAxis(axisName)); |
| | 627 | | } |
| | 628 | |
|
| | 629 | | /// <summary> |
| | 630 | | /// Bitwise check for the modifiers flags |
| | 631 | | /// </summary> |
| | 632 | | /// <param name="modifiers">Modifier to check</param> |
| | 633 | | /// <param name="value">Modifier mapped to a bit to check</param> |
| | 634 | | /// <returns></returns> |
| | 635 | | public static bool IsModifierSet(Modifier modifiers, Modifier value) |
| | 636 | | { |
| | 637 | | int flagsValue = (int)modifiers; |
| | 638 | | int flagValue = (int)value; |
| | 639 | |
|
| | 640 | | return (flagsValue & flagValue) != 0; |
| | 641 | | } |
| | 642 | |
|
| | 643 | | public static bool FocusIsInInputField() |
| | 644 | | { |
| | 645 | | if (EventSystem.current.currentSelectedGameObject != null && |
| | 646 | | (EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null || |
| | 647 | | EventSystem.current.currentSelectedGameObject.GetComponent<UnityEngine.UI.InputField>() != null)) |
| | 648 | | { |
| | 649 | | return true; |
| | 650 | | } |
| | 651 | |
|
| | 652 | | return false; |
| | 653 | | } |
| | 654 | | } |