< Summary

Class:InputController
Assembly:InputController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/InputController/InputController.cs
Covered lines:104
Uncovered lines:89
Coverable lines:193
Total lines:650
Line coverage:53.8% (104 of 193)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InputController()0%110100%
InputController()0%110100%
Update()0%7.586064.71%
Update_Trigger(...)0%487.1860050.86%
Update_Hold(...)0%101.921043.18%
Update_Measurable(...)0%7.017093.33%
Stop_Measurable(...)0%220100%

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;
 7
 8/// <summary>
 9/// Mapping for Trigger actions
 10/// </summary>
 11public 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
 28    OpenExpressions = 200,
 29    Expression_Wave = 201,
 30    Expression_FistPump = 202,
 31    Expression_Robot = 203,
 32    Expression_RaiseHand = 204,
 33    Expression_Clap = 205,
 34    Expression_ThrowMoney = 206,
 35    Expression_SendKiss = 207,
 36
 37    //Builder In World 4xx
 38    BuildEditModeChange = 408,
 39    BuildEditModeToggleUI = 409,
 40    BuildEditModeToggleEntityList = 410,
 41    BuildEditModeToggleCatalog = 411,
 42    BuildEditModeToggleSceneInfo = 412,
 43    BuildEditModeToggleChangeCamera = 413,
 44    BuildEditModeToggleControls = 414,
 45    BuildEditModeToggleSnapMode = 415,
 46    BuildEditModeUndoAction = 417,
 47    BuildEditModeRedoAction = 418,
 48    BuildEditModeQuickBar1 = 419,
 49    BuildEditModeQuickBar2 = 420,
 50    BuildEditModeQuickBar3 = 421,
 51    BuildEditModeQuickBar4 = 422,
 52    BuildEditModeQuickBar5 = 423,
 53    BuildEditModeQuickBar6 = 424,
 54    BuildEditModeQuickBar7 = 425,
 55    BuildEditModeQuickBar8 = 426,
 56    BuildEditModeQuickBar9 = 427,
 57    BuildEditModeDuplicate = 428,
 58    BuildEditModeTranslate = 429,
 59    BuildEditModeRotate = 430,
 60    BuildEditModeScale = 431,
 61    BuildEditModeDelete = 434,
 62    BuildEditModeFocusSelectedEntities = 435,
 63    BuildEditModeReset = 443,
 64    BuildEditHideSelectedEntities = 444,
 65    BuildEditShowAllEntities = 445,
 66    BuildEditModeResetCamera = 446,
 67    BuildEditModeZoomIn = 447,
 68    BuildEditModeZoomOut = 448
 69}
 70
 71/// <summary>
 72/// Mapping for hold actions
 73/// </summary>
 74public enum DCLAction_Hold
 75{
 76    //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts
 77    Sprint = 1,
 78    Jump = 2,
 79    FreeCameraMode = 101,
 80    VoiceChatRecording = 102,
 81    DefaultConfirmAction = 300,
 82    DefaultCancelAction = 301,
 83    BuildEditModeMultiSelection = 432,
 84    BuildEditModeSquareMultiSelection = 433,
 85    BuildEditModeFirstPersonRotation = 436,
 86    BuildEditModeCameraAdvanceFoward = 437,
 87    BuildEditModeCameraAdvanceBack = 438,
 88    BuildEditModeCameraAdvanceLeft = 439,
 89    BuildEditModeCameraAdvanceRight = 440,
 90    BuildEditModeCameraAdvanceUp = 441,
 91    BuildEditModeCameraAdvanceDown = 442,
 92    BuildEditModeCameraPan = 446
 93}
 94
 95/// <summary>
 96/// Mapping for measurable actions
 97/// </summary>
 98public enum DCLAction_Measurable
 99{
 100    //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts
 101    CharacterXAxis = 1,
 102    CharacterYAxis = 2,
 103    CameraXAxis = 3,
 104    CameraYAxis = 4,
 105}
 106
 107/// <summary>
 108/// Group of actions currently actived
 109/// </summary>
 110public enum InputTypeMode
 111{
 112    OFF,
 113    GENERAL,
 114    BUILD_MODE_LOADING,
 115    BUILD_MODE
 116}
 117
 118/// <summary>
 119/// Input Controller will map inputs(keys/mouse/axis) to DCL actions, check if they can be triggered (modifiers) and rai
 120/// </summary>
 121public class InputController : MonoBehaviour
 122{
 1123    public static bool ENABLE_THIRD_PERSON_CAMERA = true;
 124
 125    [Header("General Input")]
 126    public InputAction_Trigger[] triggerTimeActions;
 127
 128    public InputAction_Hold[] holdActions;
 129    public InputAction_Measurable[] measurableActions;
 130
 131    [Header("BuildMode Input")]
 132    public InputAction_Trigger[] builderTriggerTimeActions;
 133
 134    public InputAction_Hold[] builderHoldActions;
 135    public InputAction_Trigger[] loadingBuilderTriggerTimeActions;
 136
 17683137    bool renderingEnabled => CommonScriptableObjects.rendererState.Get();
 99487138    bool allUIHidden => CommonScriptableObjects.allUIHidden.Get();
 331139    public InputTypeMode inputTypeMode { get; set; } = InputTypeMode.GENERAL;
 140
 141    private void Update()
 142    {
 17683143        if (!renderingEnabled)
 144        {
 295145            Stop_Measurable(measurableActions);
 295146            return;
 147        }
 148
 17388149        switch (inputTypeMode)
 150        {
 151            case InputTypeMode.OFF:
 0152                Stop_Measurable(measurableActions);
 0153                return;
 154            case InputTypeMode.GENERAL:
 17327155                Update_Trigger(triggerTimeActions);
 17327156                Update_Hold(holdActions);
 17327157                Update_Measurable(measurableActions);
 17327158                break;
 159            case InputTypeMode.BUILD_MODE_LOADING:
 61160                Update_Trigger(loadingBuilderTriggerTimeActions);
 61161                Stop_Measurable(measurableActions);
 61162                break;
 163            case InputTypeMode.BUILD_MODE:
 0164                Update_Trigger(builderTriggerTimeActions);
 0165                Update_Hold(builderHoldActions);
 0166                Update_Measurable(measurableActions);
 167                break;
 168        }
 0169    }
 170
 171    /// <summary>
 172    /// Map the trigger actions to inputs + modifiers and check if their events must be triggered
 173    /// </summary>
 174    public void Update_Trigger(InputAction_Trigger[] triggerTimeActions)
 175    {
 762632176        for (var i = 0; i < triggerTimeActions.Length; i++)
 177        {
 363928178            var action = triggerTimeActions[i];
 179
 363928180            if (action.isTriggerBlocked != null && action.isTriggerBlocked.Get())
 181                continue;
 182
 350503183            switch (action.GetDCLAction())
 184            {
 185                case DCLAction_Trigger.CameraChange:
 186                    //Disable until the fine-tuning is ready
 17327187                    if (ENABLE_THIRD_PERSON_CAMERA)
 17327188                        InputProcessor.FromKey(action, KeyCode.V,
 189                            modifiers: InputProcessor.Modifier.NeedsPointerLocked |
 190                                       InputProcessor.Modifier.FocusNotInInput);
 17327191                    break;
 192                case DCLAction_Trigger.ToggleNavMap:
 16432193                    if (allUIHidden)
 194                        break;
 16424195                    InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16424196                    InputProcessor.FromKey(action, KeyCode.Tab, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16424197                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16424198                    break;
 199                case DCLAction_Trigger.ToggleFriends:
 16432200                    if (allUIHidden)
 201                        break;
 16424202                    InputProcessor.FromKey(action, KeyCode.L, modifiers: InputProcessor.Modifier.None);
 16424203                    break;
 204                case DCLAction_Trigger.ToggleWorldChat:
 16432205                    if (allUIHidden)
 206                        break;
 16424207                    InputProcessor.FromKey(action, KeyCode.Return, modifiers: InputProcessor.Modifier.None);
 16424208                    break;
 209                case DCLAction_Trigger.ToggleUIVisibility:
 16432210                    InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.None);
 16432211                    break;
 212                case DCLAction_Trigger.CloseWindow:
 17327213                    if (allUIHidden || DataStore.i.isSignUpFlow.Get())
 214                        break;
 17319215                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.None);
 17319216                    break;
 217                case DCLAction_Trigger.OpenExpressions:
 16432218                    if (allUIHidden)
 219                        break;
 16424220                    InputProcessor.FromKey(action, KeyCode.B, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16424221                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16424222                    break;
 223                case DCLAction_Trigger.ToggleControlsHud:
 16432224                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16432225                    break;
 226                case DCLAction_Trigger.ToggleSettings:
 17327227                    InputProcessor.FromKey(action, KeyCode.P, modifiers: InputProcessor.Modifier.FocusNotInInput);
 17327228                    break;
 229                case DCLAction_Trigger.ToggleExploreHud:
 16432230                    if (allUIHidden)
 231                        break;
 16424232                    InputProcessor.FromKey(action, KeyCode.X, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16424233                    break;
 234                case DCLAction_Trigger.Expression_Wave:
 16432235                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16432236                    break;
 237                case DCLAction_Trigger.Expression_FistPump:
 16432238                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16432239                    break;
 240                case DCLAction_Trigger.Expression_Robot:
 16432241                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16432242                    break;
 243                case DCLAction_Trigger.Expression_RaiseHand:
 16432244                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16432245                    break;
 246                case DCLAction_Trigger.Expression_Clap:
 16432247                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16432248                    break;
 249                case DCLAction_Trigger.Expression_ThrowMoney:
 16432250                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16432251                    break;
 252                case DCLAction_Trigger.Expression_SendKiss:
 16432253                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16432254                    break;
 255                case DCLAction_Trigger.BuildEditModeChange:
 17388256                    InputProcessor.FromKey(action, KeyCode.K, modifiers: InputProcessor.Modifier.FocusNotInInput);
 17388257                    break;
 258                case DCLAction_Trigger.ToggleVoiceChatRecording:
 17327259                    InputProcessor.FromKey(action, KeyCode.T, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 17327260                    break;
 261                case DCLAction_Trigger.ToggleAvatarEditorHud:
 16432262                    InputProcessor.FromKey(action, KeyCode.I, modifiers: InputProcessor.Modifier.FocusNotInInput);
 16432263                    break;
 264                case DCLAction_Trigger.BuildEditModeToggleUI:
 0265                    InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0266                    break;
 267                case DCLAction_Trigger.BuildEditModeToggleChangeCamera:
 0268                    InputProcessor.FromKey(action, KeyCode.V, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0269                    break;
 270                case DCLAction_Trigger.BuildEditModeToggleControls:
 0271                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0272                    break;
 273                case DCLAction_Trigger.BuildEditModeToggleSnapMode:
 0274                    InputProcessor.FromKey(action, KeyCode.O, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0275                    break;
 276                case DCLAction_Trigger.BuildEditModeRedoAction:
 0277                    InputProcessor.FromKey(action, KeyCode.Y, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0278                    break;
 279                case DCLAction_Trigger.BuildEditModeUndoAction:
 0280                    InputProcessor.FromKey(action, KeyCode.Z, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0281                    break;
 282                case DCLAction_Trigger.BuildEditModeQuickBar1:
 0283                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0284                    break;
 285                case DCLAction_Trigger.BuildEditModeQuickBar2:
 0286                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0287                    break;
 288                case DCLAction_Trigger.BuildEditModeQuickBar3:
 0289                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0290                    break;
 291                case DCLAction_Trigger.BuildEditModeQuickBar4:
 0292                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0293                    break;
 294                case DCLAction_Trigger.BuildEditModeQuickBar5:
 0295                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0296                    break;
 297                case DCLAction_Trigger.BuildEditModeQuickBar6:
 0298                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0299                    break;
 300                case DCLAction_Trigger.BuildEditModeQuickBar7:
 0301                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0302                    break;
 303                case DCLAction_Trigger.BuildEditModeQuickBar8:
 0304                    InputProcessor.FromKey(action, KeyCode.Alpha8, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0305                    break;
 306                case DCLAction_Trigger.BuildEditModeQuickBar9:
 0307                    InputProcessor.FromKey(action, KeyCode.Alpha9, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0308                    break;
 309                case DCLAction_Trigger.BuildEditModeDelete:
 0310                    InputProcessor.FromKey(action, KeyCode.Delete, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0311                    InputProcessor.FromKey(action, KeyCode.Backspace, modifiers: InputProcessor.Modifier.FocusNotInInput
 0312                    break;
 313                case DCLAction_Trigger.BuildEditModeDuplicate:
 0314                    InputProcessor.FromKey(action, KeyCode.D, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0315                    break;
 316                case DCLAction_Trigger.BuildEditModeTranslate:
 0317                    InputProcessor.FromKey(action, KeyCode.G, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0318                    InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0319                    break;
 320                case DCLAction_Trigger.BuildEditModeRotate:
 0321                    InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0322                    break;
 323                case DCLAction_Trigger.BuildEditModeScale:
 0324                    InputProcessor.FromKey(action, KeyCode.S, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0325                    break;
 326                case DCLAction_Trigger.BuildEditModeFocusSelectedEntities:
 0327                    InputProcessor.FromKey(action, KeyCode.F, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0328                    break;
 329                case DCLAction_Trigger.BuildEditModeReset:
 0330                    InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0331                    break;
 332                case DCLAction_Trigger.BuildEditHideSelectedEntities:
 0333                    InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0334                    break;
 335                case DCLAction_Trigger.BuildEditShowAllEntities:
 0336                    InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0337                    break;
 338                case DCLAction_Trigger.BuildEditModeResetCamera:
 0339                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0340                    break;
 341                case DCLAction_Trigger.BuildEditModeZoomIn:
 0342                    InputProcessor.FromKey(action, KeyCode.KeypadPlus, modifiers: InputProcessor.Modifier.FocusNotInInpu
 0343                    break;
 344                case DCLAction_Trigger.BuildEditModeZoomOut:
 0345                    InputProcessor.FromKey(action, KeyCode.KeypadMinus, modifiers: InputProcessor.Modifier.FocusNotInInp
 0346                    break;
 347                case DCLAction_Trigger.ToggleQuestsPanelHud:
 17327348                    InputProcessor.FromKey(action, KeyCode.J, modifiers: InputProcessor.Modifier.FocusNotInInput);
 17327349                    break;
 350                default:
 0351                    throw new ArgumentOutOfRangeException();
 352            }
 353        }
 17388354    }
 355
 356    /// <summary>
 357    /// Map the hold actions to inputs + modifiers and check if their events must be triggered
 358    /// </summary>
 359    private void Update_Hold(InputAction_Hold[] holdActions)
 360    {
 277232361        for (var i = 0; i < holdActions.Length; i++)
 362        {
 121289363            var action = holdActions[i];
 121289364            switch (action.GetDCLAction())
 365            {
 366                case DCLAction_Hold.Sprint:
 17327367                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.NeedsPointerLocked);
 17327368                    break;
 369                case DCLAction_Hold.Jump:
 17327370                    InputProcessor.FromKey(action, KeyCode.Space, InputProcessor.Modifier.NeedsPointerLocked);
 17327371                    break;
 372                case DCLAction_Hold.FreeCameraMode:
 373                    //Disable until the fine-tuning is ready
 17327374                    if (ENABLE_THIRD_PERSON_CAMERA)
 17327375                        InputProcessor.FromKey(action, KeyCode.Y, InputProcessor.Modifier.NeedsPointerLocked);
 17327376                    break;
 377                case DCLAction_Hold.VoiceChatRecording:
 378                    // Push to talk functionality only triggers if no modifier key is pressed
 34654379                    InputProcessor.FromKey(action, KeyCode.T, InputProcessor.Modifier.FocusNotInInput, null);
 34654380                    break;
 381                case DCLAction_Hold.DefaultConfirmAction:
 17327382                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.None);
 17327383                    break;
 384                case DCLAction_Hold.DefaultCancelAction:
 17327385                    InputProcessor.FromKey(action, KeyCode.F, InputProcessor.Modifier.None);
 17327386                    break;
 387                case DCLAction_Hold.BuildEditModeMultiSelection:
 0388                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 0389                    break;
 390                case DCLAction_Hold.BuildEditModeSquareMultiSelection:
 0391                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 0392                    break;
 393                case DCLAction_Hold.BuildEditModeFirstPersonRotation:
 0394                    InputProcessor.FromKey(action, KeyCode.R, InputProcessor.Modifier.FocusNotInInput);
 0395                    break;
 396                case DCLAction_Hold.BuildEditModeCameraAdvanceFoward:
 0397                    InputProcessor.FromKey(action, KeyCode.UpArrow, InputProcessor.Modifier.FocusNotInInput);
 0398                    InputProcessor.FromKey(action, KeyCode.W, InputProcessor.Modifier.FocusNotInInput);
 0399                    break;
 400                case DCLAction_Hold.BuildEditModeCameraAdvanceBack:
 0401                    InputProcessor.FromKey(action, KeyCode.DownArrow, InputProcessor.Modifier.FocusNotInInput);
 0402                    InputProcessor.FromKey(action, KeyCode.S, InputProcessor.Modifier.FocusNotInInput);
 0403                    break;
 404                case DCLAction_Hold.BuildEditModeCameraAdvanceLeft:
 0405                    InputProcessor.FromKey(action, KeyCode.LeftArrow, InputProcessor.Modifier.FocusNotInInput);
 0406                    InputProcessor.FromKey(action, KeyCode.A, InputProcessor.Modifier.FocusNotInInput);
 0407                    break;
 408                case DCLAction_Hold.BuildEditModeCameraAdvanceRight:
 0409                    InputProcessor.FromKey(action, KeyCode.RightArrow, InputProcessor.Modifier.FocusNotInInput);
 0410                    InputProcessor.FromKey(action, KeyCode.D, InputProcessor.Modifier.FocusNotInInput);
 0411                    break;
 412                case DCLAction_Hold.BuildEditModeCameraAdvanceUp:
 0413                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.FocusNotInInput);
 0414                    break;
 415                case DCLAction_Hold.BuildEditModeCameraAdvanceDown:
 0416                    InputProcessor.FromKey(action, KeyCode.Q, InputProcessor.Modifier.FocusNotInInput);
 0417                    break;
 418                case DCLAction_Hold.BuildEditModeCameraPan:
 0419                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 0420                    break;
 421                default:
 0422                    throw new ArgumentOutOfRangeException();
 423            }
 424        }
 17327425    }
 426
 427    /// <summary>
 428    /// Map the measurable actions to inputs + modifiers and check if their events must be triggered
 429    /// </summary>
 430    private void Update_Measurable(InputAction_Measurable[] measurableActions)
 431    {
 173270432        for (var i = 0; i < measurableActions.Length; i++)
 433        {
 69308434            var action = measurableActions[i];
 69308435            switch (action.GetDCLAction())
 436            {
 437                case DCLAction_Measurable.CharacterXAxis:
 17327438                    InputProcessor.FromAxis(action, "Horizontal", InputProcessor.Modifier.NeedsPointerLocked);
 17327439                    break;
 440                case DCLAction_Measurable.CharacterYAxis:
 17327441                    InputProcessor.FromAxis(action, "Vertical", InputProcessor.Modifier.NeedsPointerLocked);
 17327442                    break;
 443                case DCLAction_Measurable.CameraXAxis:
 17327444                    InputProcessor.FromAxis(action, "Mouse X", InputProcessor.Modifier.NeedsPointerLocked);
 17327445                    break;
 446                case DCLAction_Measurable.CameraYAxis:
 17327447                    InputProcessor.FromAxis(action, "Mouse Y", InputProcessor.Modifier.NeedsPointerLocked);
 17327448                    break;
 449                default:
 0450                    throw new ArgumentOutOfRangeException();
 451            }
 452        }
 17327453    }
 454
 455    private void Stop_Measurable(InputAction_Measurable[] measurableActions)
 456    {
 3560457        for (var i = 0; i < measurableActions.Length; i++)
 458        {
 1424459            measurableActions[i].RaiseOnValueChanged(0);
 460        }
 356461    }
 462}
 463
 464/// <summary>
 465/// Helper class that wraps the processing of inputs and modifiers to trigger actions events
 466/// </summary>
 467public static class InputProcessor
 468{
 469    private static readonly KeyCode[] MODIFIER_KEYS = new[] { KeyCode.LeftControl, KeyCode.LeftAlt, KeyCode.LeftShift, K
 470
 471    [Flags]
 472    public enum Modifier
 473    {
 474        //Set the values as bit masks
 475        None = 0b0000000, // No modifier needed
 476        NeedsPointerLocked = 0b0000001, // The pointer must be locked to the game
 477        FocusNotInInput = 0b0000010, // The game focus cannot be in an input field
 478    }
 479
 480    /// <summary>
 481    /// Check if the modifier keys are pressed
 482    /// </summary>
 483    /// <param name="modifierKeys"> Keycodes modifiers</param>
 484    /// <returns></returns>
 485    public static Boolean PassModifierKeys(KeyCode[] modifierKeys)
 486    {
 487        for (var i = 0; i < MODIFIER_KEYS.Length; i++)
 488        {
 489            var keyCode = MODIFIER_KEYS[i];
 490            var pressed = Input.GetKey(keyCode);
 491            if (modifierKeys == null)
 492            {
 493                if (pressed)
 494                    return false;
 495            }
 496            else
 497            {
 498                if (modifierKeys.Contains(keyCode) != pressed)
 499                    return false;
 500            }
 501        }
 502
 503        return true;
 504    }
 505
 506    /// <summary>
 507    /// Check if a miscellaneous modifiers are present. These modifiers are related to the meta-state of the application
 508    /// they can be anything such as mouse pointer state, where the focus is, camera mode...
 509    /// </summary>
 510    /// <param name="modifiers"></param>
 511    /// <returns></returns>
 512    public static bool PassModifiers(Modifier modifiers)
 513    {
 514        if (IsModifierSet(modifiers, Modifier.NeedsPointerLocked) && !DCL.Helpers.Utils.isCursorLocked)
 515            return false;
 516
 517        if (IsModifierSet(modifiers, Modifier.FocusNotInInput) && FocusIsInInputField())
 518            return false;
 519
 520        return true;
 521    }
 522
 523    /// <summary>
 524    /// Process an input action mapped to a keyboard key.
 525    /// </summary>
 526    /// <param name="action">Trigger Action to perform</param>
 527    /// <param name="key">KeyCode mapped to this action</param>
 528    /// <param name="modifierKeys">KeyCodes required to perform the action</param>
 529    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 530    public static void FromKey(InputAction_Trigger action, KeyCode key, KeyCode[] modifierKeys = null,
 531        Modifier modifiers = Modifier.None)
 532    {
 533        if (!PassModifiers(modifiers))
 534            return;
 535
 536        if (!PassModifierKeys(modifierKeys))
 537            return;
 538
 539        if (Input.GetKeyDown(key))
 540            action.RaiseOnTriggered();
 541    }
 542
 543    /// <summary>
 544    /// Process an input action mapped to a button.
 545    /// </summary>
 546    /// <param name="action">Trigger Action to perform</param>
 547    /// <param name="mouseButtonIdx">Index of the mouse button mapped to this action</param>
 548    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 549    public static void FromMouseButton(InputAction_Trigger action, int mouseButtonIdx,
 550        Modifier modifiers = Modifier.None)
 551    {
 552        if (!PassModifiers(modifiers))
 553            return;
 554
 555        if (Input.GetMouseButton(mouseButtonIdx))
 556            action.RaiseOnTriggered();
 557    }
 558
 559    /// <summary>
 560    /// Process an input action mapped to a keyboard key
 561    /// </summary>
 562    /// <param name="action">Hold Action to perform</param>
 563    /// <param name="key">KeyCode mapped to this action</param>
 564    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 565    public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers = Modifier.None)
 566    {
 567        if (!PassModifiers(modifiers))
 568            return;
 569
 570        if (Input.GetKeyDown(key))
 571            action.RaiseOnStarted();
 572        if (Input.GetKeyUp(key))
 573            action.RaiseOnFinished();
 574    }
 575
 576    /// <summary>
 577    /// Process an input action mapped to a keyboard key
 578    /// </summary>
 579    /// <param name="action">Hold Action to perform</param>
 580    /// <param name="key">KeyCode mapped to this action</param>
 581    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 582    /// <param name="modifierKeys">KeyCodes required to perform the action</param>
 583    public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers, KeyCode[] modifierKeys)
 584    {
 585        if (!PassModifierKeys(modifierKeys))
 586            return;
 587
 588        FromKey(action, key, modifiers);
 589    }
 590
 591    /// <summary>
 592    /// Process an input action mapped to a mouse button
 593    /// </summary>
 594    /// <param name="action">Hold Action to perform</param>
 595    /// <param name="mouseButtonIdx">Index of the mouse button</param>
 596    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 597    public static void FromMouse(InputAction_Hold action, int mouseButtonIdx, Modifier modifiers = Modifier.None)
 598    {
 599        if (!PassModifiers(modifiers))
 600            return;
 601
 602        if (Input.GetMouseButtonDown(mouseButtonIdx))
 603            action.RaiseOnStarted();
 604        if (Input.GetMouseButtonUp(mouseButtonIdx))
 605            action.RaiseOnFinished();
 606    }
 607
 608    /// <summary>
 609    /// Process an input action mapped to an axis
 610    /// </summary>
 611    /// <param name="action">Measurable Action to perform</param>
 612    /// <param name="axisName">Axis name</param>
 613    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 614    public static void FromAxis(InputAction_Measurable action, string axisName, Modifier modifiers = Modifier.None)
 615    {
 616        if (!PassModifiers(modifiers))
 617        {
 618            action.RaiseOnValueChanged(0);
 619            return;
 620        }
 621
 622        action.RaiseOnValueChanged(Input.GetAxis(axisName));
 623    }
 624
 625    /// <summary>
 626    /// Bitwise check for the modifiers flags
 627    /// </summary>
 628    /// <param name="modifiers">Modifier to check</param>
 629    /// <param name="value">Modifier mapped to a bit to check</param>
 630    /// <returns></returns>
 631    public static bool IsModifierSet(Modifier modifiers, Modifier value)
 632    {
 633        int flagsValue = (int)modifiers;
 634        int flagValue = (int)value;
 635
 636        return (flagsValue & flagValue) != 0;
 637    }
 638
 639    public static bool FocusIsInInputField()
 640    {
 641        if (EventSystem.current.currentSelectedGameObject != null &&
 642            (EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null ||
 643             EventSystem.current.currentSelectedGameObject.GetComponent<UnityEngine.UI.InputField>() != null))
 644        {
 645            return true;
 646        }
 647
 648        return false;
 649    }
 650}