< Summary

Class:InputController
Assembly:InputController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/InputController/InputController.cs
Covered lines:101
Uncovered lines:92
Coverable lines:193
Total lines:651
Line coverage:52.3% (101 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%11.346047.06%
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    BuildEditModeCreateLastSceneObject = 416,
 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>
 75public 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>
 99public 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>
 111public 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>
 122public class InputController : MonoBehaviour
 123{
 1124    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
 13162138    bool renderingEnabled => CommonScriptableObjects.rendererState.Get();
 77502139    bool allUIHidden => CommonScriptableObjects.allUIHidden.Get();
 314140    public InputTypeMode inputTypeMode { get; set; } = InputTypeMode.GENERAL;
 141
 142    private void Update()
 143    {
 13162144        if (!renderingEnabled)
 145        {
 245146            Stop_Measurable(measurableActions);
 245147            return;
 148        }
 149
 12917150        switch (inputTypeMode)
 151        {
 152            case InputTypeMode.OFF:
 0153                Stop_Measurable(measurableActions);
 0154                return;
 155            case InputTypeMode.GENERAL:
 12917156                Update_Trigger(triggerTimeActions);
 12917157                Update_Hold(holdActions);
 12917158                Update_Measurable(measurableActions);
 12917159                break;
 160            case InputTypeMode.BUILD_MODE_LOADING:
 0161                Update_Trigger(loadingBuilderTriggerTimeActions);
 0162                Stop_Measurable(measurableActions);
 0163                break;
 164            case InputTypeMode.BUILD_MODE:
 0165                Update_Trigger(builderTriggerTimeActions);
 0166                Update_Hold(builderHoldActions);
 0167                Update_Measurable(measurableActions);
 168                break;
 169        }
 0170    }
 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    {
 568348177        for (var i = 0; i < triggerTimeActions.Length; i++)
 178        {
 271257179            var action = triggerTimeActions[i];
 180
 271257181            if (action.isTriggerBlocked != null && action.isTriggerBlocked.Get())
 182                continue;
 183
 271257184            switch (action.GetDCLAction())
 185            {
 186                case DCLAction_Trigger.CameraChange:
 187                    //Disable until the fine-tuning is ready
 12917188                    if (ENABLE_THIRD_PERSON_CAMERA)
 12917189                        InputProcessor.FromKey(action, KeyCode.V,
 190                            modifiers: InputProcessor.Modifier.NeedsPointerLocked |
 191                                       InputProcessor.Modifier.FocusNotInInput);
 12917192                    break;
 193                case DCLAction_Trigger.ToggleNavMap:
 12917194                    if (allUIHidden)
 195                        break;
 12917196                    InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917197                    InputProcessor.FromKey(action, KeyCode.Tab, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917198                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917199                    break;
 200                case DCLAction_Trigger.ToggleFriends:
 12917201                    if (allUIHidden)
 202                        break;
 12917203                    InputProcessor.FromKey(action, KeyCode.L, modifiers: InputProcessor.Modifier.None);
 12917204                    break;
 205                case DCLAction_Trigger.ToggleWorldChat:
 12917206                    if (allUIHidden)
 207                        break;
 12917208                    InputProcessor.FromKey(action, KeyCode.Return, modifiers: InputProcessor.Modifier.None);
 12917209                    break;
 210                case DCLAction_Trigger.ToggleUIVisibility:
 12917211                    InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.None);
 12917212                    break;
 213                case DCLAction_Trigger.CloseWindow:
 12917214                    if (allUIHidden || DataStore.i.isSignUpFlow.Get())
 215                        break;
 12917216                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.None);
 12917217                    break;
 218                case DCLAction_Trigger.OpenExpressions:
 12917219                    if (allUIHidden)
 220                        break;
 12917221                    InputProcessor.FromKey(action, KeyCode.B, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917222                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917223                    break;
 224                case DCLAction_Trigger.ToggleControlsHud:
 12917225                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917226                    break;
 227                case DCLAction_Trigger.ToggleSettings:
 12917228                    InputProcessor.FromKey(action, KeyCode.P, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917229                    break;
 230                case DCLAction_Trigger.ToggleExploreHud:
 12917231                    if (allUIHidden)
 232                        break;
 12917233                    InputProcessor.FromKey(action, KeyCode.X, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917234                    break;
 235                case DCLAction_Trigger.Expression_Wave:
 12917236                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917237                    break;
 238                case DCLAction_Trigger.Expression_FistPump:
 12917239                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917240                    break;
 241                case DCLAction_Trigger.Expression_Robot:
 12917242                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917243                    break;
 244                case DCLAction_Trigger.Expression_RaiseHand:
 12917245                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917246                    break;
 247                case DCLAction_Trigger.Expression_Clap:
 12917248                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917249                    break;
 250                case DCLAction_Trigger.Expression_ThrowMoney:
 12917251                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917252                    break;
 253                case DCLAction_Trigger.Expression_SendKiss:
 12917254                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917255                    break;
 256                case DCLAction_Trigger.BuildEditModeChange:
 12917257                    InputProcessor.FromKey(action, KeyCode.K, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917258                    break;
 259                case DCLAction_Trigger.ToggleVoiceChatRecording:
 12917260                    InputProcessor.FromKey(action, KeyCode.T, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 12917261                    break;
 262                case DCLAction_Trigger.ToggleAvatarEditorHud:
 12917263                    InputProcessor.FromKey(action, KeyCode.I, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917264                    break;
 265                case DCLAction_Trigger.BuildEditModeToggleUI:
 0266                    InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0267                    break;
 268                case DCLAction_Trigger.BuildEditModeToggleChangeCamera:
 0269                    InputProcessor.FromKey(action, KeyCode.V, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0270                    break;
 271                case DCLAction_Trigger.BuildEditModeToggleControls:
 0272                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0273                    break;
 274                case DCLAction_Trigger.BuildEditModeToggleSnapMode:
 0275                    InputProcessor.FromKey(action, KeyCode.O, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0276                    break;
 277                case DCLAction_Trigger.BuildEditModeRedoAction:
 0278                    InputProcessor.FromKey(action, KeyCode.Y, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0279                    break;
 280                case DCLAction_Trigger.BuildEditModeUndoAction:
 0281                    InputProcessor.FromKey(action, KeyCode.Z, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0282                    break;
 283                case DCLAction_Trigger.BuildEditModeQuickBar1:
 0284                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0285                    break;
 286                case DCLAction_Trigger.BuildEditModeQuickBar2:
 0287                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0288                    break;
 289                case DCLAction_Trigger.BuildEditModeQuickBar3:
 0290                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0291                    break;
 292                case DCLAction_Trigger.BuildEditModeQuickBar4:
 0293                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0294                    break;
 295                case DCLAction_Trigger.BuildEditModeQuickBar5:
 0296                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0297                    break;
 298                case DCLAction_Trigger.BuildEditModeQuickBar6:
 0299                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0300                    break;
 301                case DCLAction_Trigger.BuildEditModeQuickBar7:
 0302                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0303                    break;
 304                case DCLAction_Trigger.BuildEditModeQuickBar8:
 0305                    InputProcessor.FromKey(action, KeyCode.Alpha8, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0306                    break;
 307                case DCLAction_Trigger.BuildEditModeQuickBar9:
 0308                    InputProcessor.FromKey(action, KeyCode.Alpha9, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0309                    break;
 310                case DCLAction_Trigger.BuildEditModeDelete:
 0311                    InputProcessor.FromKey(action, KeyCode.Delete, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0312                    InputProcessor.FromKey(action, KeyCode.Backspace, modifiers: InputProcessor.Modifier.FocusNotInInput
 0313                    break;
 314                case DCLAction_Trigger.BuildEditModeDuplicate:
 0315                    InputProcessor.FromKey(action, KeyCode.D, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0316                    break;
 317                case DCLAction_Trigger.BuildEditModeTranslate:
 0318                    InputProcessor.FromKey(action, KeyCode.G, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0319                    InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0320                    break;
 321                case DCLAction_Trigger.BuildEditModeRotate:
 0322                    InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0323                    break;
 324                case DCLAction_Trigger.BuildEditModeScale:
 0325                    InputProcessor.FromKey(action, KeyCode.S, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0326                    break;
 327                case DCLAction_Trigger.BuildEditModeFocusSelectedEntities:
 0328                    InputProcessor.FromKey(action, KeyCode.F, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0329                    break;
 330                case DCLAction_Trigger.BuildEditModeReset:
 0331                    InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0332                    break;
 333                case DCLAction_Trigger.BuildEditHideSelectedEntities:
 0334                    InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0335                    break;
 336                case DCLAction_Trigger.BuildEditShowAllEntities:
 0337                    InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0338                    break;
 339                case DCLAction_Trigger.BuildEditModeResetCamera:
 0340                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0341                    break;
 342                case DCLAction_Trigger.BuildEditModeZoomIn:
 0343                    InputProcessor.FromKey(action, KeyCode.KeypadPlus, modifiers: InputProcessor.Modifier.FocusNotInInpu
 0344                    break;
 345                case DCLAction_Trigger.BuildEditModeZoomOut:
 0346                    InputProcessor.FromKey(action, KeyCode.KeypadMinus, modifiers: InputProcessor.Modifier.FocusNotInInp
 0347                    break;
 348                case DCLAction_Trigger.ToggleQuestsPanelHud:
 12917349                    InputProcessor.FromKey(action, KeyCode.J, modifiers: InputProcessor.Modifier.FocusNotInInput);
 12917350                    break;
 351                default:
 0352                    throw new ArgumentOutOfRangeException();
 353            }
 354        }
 12917355    }
 356
 357    /// <summary>
 358    /// Map the hold actions to inputs + modifiers and check if their events must be triggered
 359    /// </summary>
 360    private void Update_Hold(InputAction_Hold[] holdActions)
 361    {
 206672362        for (var i = 0; i < holdActions.Length; i++)
 363        {
 90419364            var action = holdActions[i];
 90419365            switch (action.GetDCLAction())
 366            {
 367                case DCLAction_Hold.Sprint:
 12917368                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.NeedsPointerLocked);
 12917369                    break;
 370                case DCLAction_Hold.Jump:
 12917371                    InputProcessor.FromKey(action, KeyCode.Space, InputProcessor.Modifier.NeedsPointerLocked);
 12917372                    break;
 373                case DCLAction_Hold.FreeCameraMode:
 374                    //Disable until the fine-tuning is ready
 12917375                    if (ENABLE_THIRD_PERSON_CAMERA)
 12917376                        InputProcessor.FromKey(action, KeyCode.Y, InputProcessor.Modifier.NeedsPointerLocked);
 12917377                    break;
 378                case DCLAction_Hold.VoiceChatRecording:
 379                    // Push to talk functionality only triggers if no modifier key is pressed
 25834380                    InputProcessor.FromKey(action, KeyCode.T, InputProcessor.Modifier.FocusNotInInput, null);
 25834381                    break;
 382                case DCLAction_Hold.DefaultConfirmAction:
 12917383                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.None);
 12917384                    break;
 385                case DCLAction_Hold.DefaultCancelAction:
 12917386                    InputProcessor.FromKey(action, KeyCode.F, InputProcessor.Modifier.None);
 12917387                    break;
 388                case DCLAction_Hold.BuildEditModeMultiSelection:
 0389                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 0390                    break;
 391                case DCLAction_Hold.BuildEditModeSquareMultiSelection:
 0392                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 0393                    break;
 394                case DCLAction_Hold.BuildEditModeFirstPersonRotation:
 0395                    InputProcessor.FromKey(action, KeyCode.R, InputProcessor.Modifier.FocusNotInInput);
 0396                    break;
 397                case DCLAction_Hold.BuildEditModeCameraAdvanceFoward:
 0398                    InputProcessor.FromKey(action, KeyCode.UpArrow, InputProcessor.Modifier.FocusNotInInput);
 0399                    InputProcessor.FromKey(action, KeyCode.W, InputProcessor.Modifier.FocusNotInInput);
 0400                    break;
 401                case DCLAction_Hold.BuildEditModeCameraAdvanceBack:
 0402                    InputProcessor.FromKey(action, KeyCode.DownArrow, InputProcessor.Modifier.FocusNotInInput);
 0403                    InputProcessor.FromKey(action, KeyCode.S, InputProcessor.Modifier.FocusNotInInput);
 0404                    break;
 405                case DCLAction_Hold.BuildEditModeCameraAdvanceLeft:
 0406                    InputProcessor.FromKey(action, KeyCode.LeftArrow, InputProcessor.Modifier.FocusNotInInput);
 0407                    InputProcessor.FromKey(action, KeyCode.A, InputProcessor.Modifier.FocusNotInInput);
 0408                    break;
 409                case DCLAction_Hold.BuildEditModeCameraAdvanceRight:
 0410                    InputProcessor.FromKey(action, KeyCode.RightArrow, InputProcessor.Modifier.FocusNotInInput);
 0411                    InputProcessor.FromKey(action, KeyCode.D, InputProcessor.Modifier.FocusNotInInput);
 0412                    break;
 413                case DCLAction_Hold.BuildEditModeCameraAdvanceUp:
 0414                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.FocusNotInInput);
 0415                    break;
 416                case DCLAction_Hold.BuildEditModeCameraAdvanceDown:
 0417                    InputProcessor.FromKey(action, KeyCode.Q, InputProcessor.Modifier.FocusNotInInput);
 0418                    break;
 419                case DCLAction_Hold.BuildEditModeCameraPan:
 0420                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 0421                    break;
 422                default:
 0423                    throw new ArgumentOutOfRangeException();
 424            }
 425        }
 12917426    }
 427
 428    /// <summary>
 429    /// Map the measurable actions to inputs + modifiers and check if their events must be triggered
 430    /// </summary>
 431    private void Update_Measurable(InputAction_Measurable[] measurableActions)
 432    {
 129170433        for (var i = 0; i < measurableActions.Length; i++)
 434        {
 51668435            var action = measurableActions[i];
 51668436            switch (action.GetDCLAction())
 437            {
 438                case DCLAction_Measurable.CharacterXAxis:
 12917439                    InputProcessor.FromAxis(action, "Horizontal", InputProcessor.Modifier.NeedsPointerLocked);
 12917440                    break;
 441                case DCLAction_Measurable.CharacterYAxis:
 12917442                    InputProcessor.FromAxis(action, "Vertical", InputProcessor.Modifier.NeedsPointerLocked);
 12917443                    break;
 444                case DCLAction_Measurable.CameraXAxis:
 12917445                    InputProcessor.FromAxis(action, "Mouse X", InputProcessor.Modifier.NeedsPointerLocked);
 12917446                    break;
 447                case DCLAction_Measurable.CameraYAxis:
 12917448                    InputProcessor.FromAxis(action, "Mouse Y", InputProcessor.Modifier.NeedsPointerLocked);
 12917449                    break;
 450                default:
 0451                    throw new ArgumentOutOfRangeException();
 452            }
 453        }
 12917454    }
 455
 456    private void Stop_Measurable(InputAction_Measurable[] measurableActions)
 457    {
 2450458        for (var i = 0; i < measurableActions.Length; i++)
 459        {
 980460            measurableActions[i].RaiseOnValueChanged(0);
 461        }
 245462    }
 463}
 464
 465/// <summary>
 466/// Helper class that wraps the processing of inputs and modifiers to trigger actions events
 467/// </summary>
 468public static class InputProcessor
 469{
 470    private static readonly KeyCode[] MODIFIER_KEYS = new[] { KeyCode.LeftControl, KeyCode.LeftAlt, KeyCode.LeftShift, K
 471
 472    [Flags]
 473    public enum Modifier
 474    {
 475        //Set the values as bit masks
 476        None = 0b0000000, // No modifier needed
 477        NeedsPointerLocked = 0b0000001, // The pointer must be locked to the game
 478        FocusNotInInput = 0b0000010, // The game focus cannot be in an input field
 479    }
 480
 481    /// <summary>
 482    /// Check if the modifier keys are pressed
 483    /// </summary>
 484    /// <param name="modifierKeys"> Keycodes modifiers</param>
 485    /// <returns></returns>
 486    public static Boolean PassModifierKeys(KeyCode[] modifierKeys)
 487    {
 488        for (var i = 0; i < MODIFIER_KEYS.Length; i++)
 489        {
 490            var keyCode = MODIFIER_KEYS[i];
 491            var pressed = Input.GetKey(keyCode);
 492            if (modifierKeys == null)
 493            {
 494                if (pressed)
 495                    return false;
 496            }
 497            else
 498            {
 499                if (modifierKeys.Contains(keyCode) != pressed)
 500                    return false;
 501            }
 502        }
 503
 504        return true;
 505    }
 506
 507    /// <summary>
 508    /// Check if a miscellaneous modifiers are present. These modifiers are related to the meta-state of the application
 509    /// they can be anything such as mouse pointer state, where the focus is, camera mode...
 510    /// </summary>
 511    /// <param name="modifiers"></param>
 512    /// <returns></returns>
 513    public static bool PassModifiers(Modifier modifiers)
 514    {
 515        if (IsModifierSet(modifiers, Modifier.NeedsPointerLocked) && !DCL.Helpers.Utils.isCursorLocked)
 516            return false;
 517
 518        if (IsModifierSet(modifiers, Modifier.FocusNotInInput) && FocusIsInInputField())
 519            return false;
 520
 521        return true;
 522    }
 523
 524    /// <summary>
 525    /// Process an input action mapped to a keyboard key.
 526    /// </summary>
 527    /// <param name="action">Trigger Action to perform</param>
 528    /// <param name="key">KeyCode mapped to this action</param>
 529    /// <param name="modifierKeys">KeyCodes required to perform the action</param>
 530    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 531    public static void FromKey(InputAction_Trigger action, KeyCode key, KeyCode[] modifierKeys = null,
 532        Modifier modifiers = Modifier.None)
 533    {
 534        if (!PassModifiers(modifiers))
 535            return;
 536
 537        if (!PassModifierKeys(modifierKeys))
 538            return;
 539
 540        if (Input.GetKeyDown(key))
 541            action.RaiseOnTriggered();
 542    }
 543
 544    /// <summary>
 545    /// Process an input action mapped to a button.
 546    /// </summary>
 547    /// <param name="action">Trigger Action to perform</param>
 548    /// <param name="mouseButtonIdx">Index of the mouse button mapped to this action</param>
 549    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 550    public static void FromMouseButton(InputAction_Trigger action, int mouseButtonIdx,
 551        Modifier modifiers = Modifier.None)
 552    {
 553        if (!PassModifiers(modifiers))
 554            return;
 555
 556        if (Input.GetMouseButton(mouseButtonIdx))
 557            action.RaiseOnTriggered();
 558    }
 559
 560    /// <summary>
 561    /// Process an input action mapped to a keyboard key
 562    /// </summary>
 563    /// <param name="action">Hold Action to perform</param>
 564    /// <param name="key">KeyCode mapped to this action</param>
 565    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 566    public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers = Modifier.None)
 567    {
 568        if (!PassModifiers(modifiers))
 569            return;
 570
 571        if (Input.GetKeyDown(key))
 572            action.RaiseOnStarted();
 573        if (Input.GetKeyUp(key))
 574            action.RaiseOnFinished();
 575    }
 576
 577    /// <summary>
 578    /// Process an input action mapped to a keyboard key
 579    /// </summary>
 580    /// <param name="action">Hold Action to perform</param>
 581    /// <param name="key">KeyCode mapped to this action</param>
 582    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 583    /// <param name="modifierKeys">KeyCodes required to perform the action</param>
 584    public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers, KeyCode[] modifierKeys)
 585    {
 586        if (!PassModifierKeys(modifierKeys))
 587            return;
 588
 589        FromKey(action, key, modifiers);
 590    }
 591
 592    /// <summary>
 593    /// Process an input action mapped to a mouse button
 594    /// </summary>
 595    /// <param name="action">Hold Action to perform</param>
 596    /// <param name="mouseButtonIdx">Index of the mouse button</param>
 597    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 598    public static void FromMouse(InputAction_Hold action, int mouseButtonIdx, Modifier modifiers = Modifier.None)
 599    {
 600        if (!PassModifiers(modifiers))
 601            return;
 602
 603        if (Input.GetMouseButtonDown(mouseButtonIdx))
 604            action.RaiseOnStarted();
 605        if (Input.GetMouseButtonUp(mouseButtonIdx))
 606            action.RaiseOnFinished();
 607    }
 608
 609    /// <summary>
 610    /// Process an input action mapped to an axis
 611    /// </summary>
 612    /// <param name="action">Measurable Action to perform</param>
 613    /// <param name="axisName">Axis name</param>
 614    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 615    public static void FromAxis(InputAction_Measurable action, string axisName, Modifier modifiers = Modifier.None)
 616    {
 617        if (!PassModifiers(modifiers))
 618        {
 619            action.RaiseOnValueChanged(0);
 620            return;
 621        }
 622
 623        action.RaiseOnValueChanged(Input.GetAxis(axisName));
 624    }
 625
 626    /// <summary>
 627    /// Bitwise check for the modifiers flags
 628    /// </summary>
 629    /// <param name="modifiers">Modifier to check</param>
 630    /// <param name="value">Modifier mapped to a bit to check</param>
 631    /// <returns></returns>
 632    public static bool IsModifierSet(Modifier modifiers, Modifier value)
 633    {
 634        int flagsValue = (int)modifiers;
 635        int flagValue = (int)value;
 636
 637        return (flagsValue & flagValue) != 0;
 638    }
 639
 640    public static bool FocusIsInInputField()
 641    {
 642        if (EventSystem.current.currentSelectedGameObject != null &&
 643            (EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null ||
 644             EventSystem.current.currentSelectedGameObject.GetComponent<UnityEngine.UI.InputField>() != null))
 645        {
 646            return true;
 647        }
 648
 649        return false;
 650    }
 651}