< Summary

Class:InputProcessor
Assembly:InputController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/InputController/InputController.cs
Covered lines:36
Uncovered lines:22
Coverable lines:58
Total lines:662
Line coverage:62% (36 of 58)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InputProcessor()0%110100%
PassModifierKeys(...)0%5.025090.91%
PassModifiers(...)0%5.25080%
FromKey(...)0%4.054085.71%
FromMouseButton(...)0%12300%
FromKey(...)0%4.374071.43%
FromKey(...)0%2.062075%
FromMouse(...)0%20400%
FromAxis(...)0%220100%
IsModifierSet(...)0%2100%
FocusIsInInputField()0%5.25080%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/InputController/InputController.cs

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