< 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:20
Coverable lines:56
Total lines:651
Line coverage:64.2% (36 of 56)
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%550100%
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%440100%

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{
 124    public static bool ENABLE_THIRD_PERSON_CAMERA = true;
 125
 126    [Header("General Input")]
 127    public InputAction_Trigger[] triggerTimeActions;
 128
 129    public InputAction_Hold[] holdActions;
 130    public InputAction_Measurable[] measurableActions;
 131
 132    [Header("BuildMode Input")]
 133    public InputAction_Trigger[] builderTriggerTimeActions;
 134
 135    public InputAction_Hold[] builderHoldActions;
 136    public InputAction_Trigger[] loadingBuilderTriggerTimeActions;
 137
 138    bool renderingEnabled => CommonScriptableObjects.rendererState.Get();
 139    bool allUIHidden => CommonScriptableObjects.allUIHidden.Get();
 140    public InputTypeMode inputTypeMode { get; set; } = InputTypeMode.GENERAL;
 141
 142    private void Update()
 143    {
 144        if (!renderingEnabled)
 145        {
 146            Stop_Measurable(measurableActions);
 147            return;
 148        }
 149
 150        switch (inputTypeMode)
 151        {
 152            case InputTypeMode.OFF:
 153                Stop_Measurable(measurableActions);
 154                return;
 155            case InputTypeMode.GENERAL:
 156                Update_Trigger(triggerTimeActions);
 157                Update_Hold(holdActions);
 158                Update_Measurable(measurableActions);
 159                break;
 160            case InputTypeMode.BUILD_MODE_LOADING:
 161                Update_Trigger(loadingBuilderTriggerTimeActions);
 162                Stop_Measurable(measurableActions);
 163                break;
 164            case InputTypeMode.BUILD_MODE:
 165                Update_Trigger(builderTriggerTimeActions);
 166                Update_Hold(builderHoldActions);
 167                Update_Measurable(measurableActions);
 168                break;
 169        }
 170    }
 171
 172    /// <summary>
 173    /// Map the trigger actions to inputs + modifiers and check if their events must be triggered
 174    /// </summary>
 175    public void Update_Trigger(InputAction_Trigger[] triggerTimeActions)
 176    {
 177        for (var i = 0; i < triggerTimeActions.Length; i++)
 178        {
 179            var action = triggerTimeActions[i];
 180
 181            if (action.isTriggerBlocked != null && action.isTriggerBlocked.Get())
 182                continue;
 183
 184            switch (action.GetDCLAction())
 185            {
 186                case DCLAction_Trigger.CameraChange:
 187                    //Disable until the fine-tuning is ready
 188                    if (ENABLE_THIRD_PERSON_CAMERA)
 189                        InputProcessor.FromKey(action, KeyCode.V,
 190                            modifiers: InputProcessor.Modifier.NeedsPointerLocked |
 191                                       InputProcessor.Modifier.FocusNotInInput);
 192                    break;
 193                case DCLAction_Trigger.ToggleNavMap:
 194                    if (allUIHidden)
 195                        break;
 196                    InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput);
 197                    InputProcessor.FromKey(action, KeyCode.Tab, modifiers: InputProcessor.Modifier.FocusNotInInput);
 198                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.FocusNotInInput);
 199                    break;
 200                case DCLAction_Trigger.ToggleFriends:
 201                    if (allUIHidden)
 202                        break;
 203                    InputProcessor.FromKey(action, KeyCode.L, modifiers: InputProcessor.Modifier.None);
 204                    break;
 205                case DCLAction_Trigger.ToggleWorldChat:
 206                    if (allUIHidden)
 207                        break;
 208                    InputProcessor.FromKey(action, KeyCode.Return, modifiers: InputProcessor.Modifier.None);
 209                    break;
 210                case DCLAction_Trigger.ToggleUIVisibility:
 211                    InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.None);
 212                    break;
 213                case DCLAction_Trigger.CloseWindow:
 214                    if (allUIHidden || DataStore.i.isSignUpFlow.Get())
 215                        break;
 216                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.None);
 217                    break;
 218                case DCLAction_Trigger.OpenExpressions:
 219                    if (allUIHidden)
 220                        break;
 221                    InputProcessor.FromKey(action, KeyCode.B, modifiers: InputProcessor.Modifier.FocusNotInInput);
 222                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.FocusNotInInput);
 223                    break;
 224                case DCLAction_Trigger.ToggleControlsHud:
 225                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput);
 226                    break;
 227                case DCLAction_Trigger.ToggleSettings:
 228                    InputProcessor.FromKey(action, KeyCode.P, modifiers: InputProcessor.Modifier.FocusNotInInput);
 229                    break;
 230                case DCLAction_Trigger.ToggleExploreHud:
 231                    if (allUIHidden)
 232                        break;
 233                    InputProcessor.FromKey(action, KeyCode.X, modifiers: InputProcessor.Modifier.FocusNotInInput);
 234                    break;
 235                case DCLAction_Trigger.Expression_Wave:
 236                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput);
 237                    break;
 238                case DCLAction_Trigger.Expression_FistPump:
 239                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput);
 240                    break;
 241                case DCLAction_Trigger.Expression_Robot:
 242                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput);
 243                    break;
 244                case DCLAction_Trigger.Expression_RaiseHand:
 245                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput);
 246                    break;
 247                case DCLAction_Trigger.Expression_Clap:
 248                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput);
 249                    break;
 250                case DCLAction_Trigger.Expression_ThrowMoney:
 251                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput);
 252                    break;
 253                case DCLAction_Trigger.Expression_SendKiss:
 254                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput);
 255                    break;
 256                case DCLAction_Trigger.BuildEditModeChange:
 257                    InputProcessor.FromKey(action, KeyCode.K, modifiers: InputProcessor.Modifier.FocusNotInInput);
 258                    break;
 259                case DCLAction_Trigger.ToggleVoiceChatRecording:
 260                    InputProcessor.FromKey(action, KeyCode.T, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 261                    break;
 262                case DCLAction_Trigger.ToggleAvatarEditorHud:
 263                    InputProcessor.FromKey(action, KeyCode.I, modifiers: InputProcessor.Modifier.FocusNotInInput);
 264                    break;
 265                case DCLAction_Trigger.BuildEditModeToggleUI:
 266                    InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.FocusNotInInput);
 267                    break;
 268                case DCLAction_Trigger.BuildEditModeToggleChangeCamera:
 269                    InputProcessor.FromKey(action, KeyCode.V, modifiers: InputProcessor.Modifier.FocusNotInInput);
 270                    break;
 271                case DCLAction_Trigger.BuildEditModeToggleControls:
 272                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput);
 273                    break;
 274                case DCLAction_Trigger.BuildEditModeToggleSnapMode:
 275                    InputProcessor.FromKey(action, KeyCode.O, modifiers: InputProcessor.Modifier.FocusNotInInput);
 276                    break;
 277                case DCLAction_Trigger.BuildEditModeRedoAction:
 278                    InputProcessor.FromKey(action, KeyCode.Y, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 279                    break;
 280                case DCLAction_Trigger.BuildEditModeUndoAction:
 281                    InputProcessor.FromKey(action, KeyCode.Z, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 282                    break;
 283                case DCLAction_Trigger.BuildEditModeQuickBar1:
 284                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput);
 285                    break;
 286                case DCLAction_Trigger.BuildEditModeQuickBar2:
 287                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput);
 288                    break;
 289                case DCLAction_Trigger.BuildEditModeQuickBar3:
 290                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput);
 291                    break;
 292                case DCLAction_Trigger.BuildEditModeQuickBar4:
 293                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput);
 294                    break;
 295                case DCLAction_Trigger.BuildEditModeQuickBar5:
 296                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput);
 297                    break;
 298                case DCLAction_Trigger.BuildEditModeQuickBar6:
 299                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput);
 300                    break;
 301                case DCLAction_Trigger.BuildEditModeQuickBar7:
 302                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput);
 303                    break;
 304                case DCLAction_Trigger.BuildEditModeQuickBar8:
 305                    InputProcessor.FromKey(action, KeyCode.Alpha8, modifiers: InputProcessor.Modifier.FocusNotInInput);
 306                    break;
 307                case DCLAction_Trigger.BuildEditModeQuickBar9:
 308                    InputProcessor.FromKey(action, KeyCode.Alpha9, modifiers: InputProcessor.Modifier.FocusNotInInput);
 309                    break;
 310                case DCLAction_Trigger.BuildEditModeDelete:
 311                    InputProcessor.FromKey(action, KeyCode.Delete, modifiers: InputProcessor.Modifier.FocusNotInInput);
 312                    InputProcessor.FromKey(action, KeyCode.Backspace, modifiers: InputProcessor.Modifier.FocusNotInInput
 313                    break;
 314                case DCLAction_Trigger.BuildEditModeDuplicate:
 315                    InputProcessor.FromKey(action, KeyCode.D, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 316                    break;
 317                case DCLAction_Trigger.BuildEditModeTranslate:
 318                    InputProcessor.FromKey(action, KeyCode.G, modifiers: InputProcessor.Modifier.FocusNotInInput);
 319                    InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput);
 320                    break;
 321                case DCLAction_Trigger.BuildEditModeRotate:
 322                    InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput);
 323                    break;
 324                case DCLAction_Trigger.BuildEditModeScale:
 325                    InputProcessor.FromKey(action, KeyCode.S, modifiers: InputProcessor.Modifier.FocusNotInInput);
 326                    break;
 327                case DCLAction_Trigger.BuildEditModeFocusSelectedEntities:
 328                    InputProcessor.FromKey(action, KeyCode.F, modifiers: InputProcessor.Modifier.FocusNotInInput);
 329                    break;
 330                case DCLAction_Trigger.BuildEditModeReset:
 331                    InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 332                    break;
 333                case DCLAction_Trigger.BuildEditHideSelectedEntities:
 334                    InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput);
 335                    break;
 336                case DCLAction_Trigger.BuildEditShowAllEntities:
 337                    InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 338                    break;
 339                case DCLAction_Trigger.BuildEditModeResetCamera:
 340                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 341                    break;
 342                case DCLAction_Trigger.BuildEditModeZoomIn:
 343                    InputProcessor.FromKey(action, KeyCode.KeypadPlus, modifiers: InputProcessor.Modifier.FocusNotInInpu
 344                    break;
 345                case DCLAction_Trigger.BuildEditModeZoomOut:
 346                    InputProcessor.FromKey(action, KeyCode.KeypadMinus, modifiers: InputProcessor.Modifier.FocusNotInInp
 347                    break;
 348                case DCLAction_Trigger.ToggleQuestsPanelHud:
 349                    InputProcessor.FromKey(action, KeyCode.J, modifiers: InputProcessor.Modifier.FocusNotInInput);
 350                    break;
 351                default:
 352                    throw new ArgumentOutOfRangeException();
 353            }
 354        }
 355    }
 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    {
 362        for (var i = 0; i < holdActions.Length; i++)
 363        {
 364            var action = holdActions[i];
 365            switch (action.GetDCLAction())
 366            {
 367                case DCLAction_Hold.Sprint:
 368                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.NeedsPointerLocked);
 369                    break;
 370                case DCLAction_Hold.Jump:
 371                    InputProcessor.FromKey(action, KeyCode.Space, InputProcessor.Modifier.NeedsPointerLocked);
 372                    break;
 373                case DCLAction_Hold.FreeCameraMode:
 374                    //Disable until the fine-tuning is ready
 375                    if (ENABLE_THIRD_PERSON_CAMERA)
 376                        InputProcessor.FromKey(action, KeyCode.Y, InputProcessor.Modifier.NeedsPointerLocked);
 377                    break;
 378                case DCLAction_Hold.VoiceChatRecording:
 379                    // Push to talk functionality only triggers if no modifier key is pressed
 380                    InputProcessor.FromKey(action, KeyCode.T, InputProcessor.Modifier.FocusNotInInput, null);
 381                    break;
 382                case DCLAction_Hold.DefaultConfirmAction:
 383                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.None);
 384                    break;
 385                case DCLAction_Hold.DefaultCancelAction:
 386                    InputProcessor.FromKey(action, KeyCode.F, InputProcessor.Modifier.None);
 387                    break;
 388                case DCLAction_Hold.BuildEditModeMultiSelection:
 389                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 390                    break;
 391                case DCLAction_Hold.BuildEditModeSquareMultiSelection:
 392                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 393                    break;
 394                case DCLAction_Hold.BuildEditModeFirstPersonRotation:
 395                    InputProcessor.FromKey(action, KeyCode.R, InputProcessor.Modifier.FocusNotInInput);
 396                    break;
 397                case DCLAction_Hold.BuildEditModeCameraAdvanceFoward:
 398                    InputProcessor.FromKey(action, KeyCode.UpArrow, InputProcessor.Modifier.FocusNotInInput);
 399                    InputProcessor.FromKey(action, KeyCode.W, InputProcessor.Modifier.FocusNotInInput);
 400                    break;
 401                case DCLAction_Hold.BuildEditModeCameraAdvanceBack:
 402                    InputProcessor.FromKey(action, KeyCode.DownArrow, InputProcessor.Modifier.FocusNotInInput);
 403                    InputProcessor.FromKey(action, KeyCode.S, InputProcessor.Modifier.FocusNotInInput);
 404                    break;
 405                case DCLAction_Hold.BuildEditModeCameraAdvanceLeft:
 406                    InputProcessor.FromKey(action, KeyCode.LeftArrow, InputProcessor.Modifier.FocusNotInInput);
 407                    InputProcessor.FromKey(action, KeyCode.A, InputProcessor.Modifier.FocusNotInInput);
 408                    break;
 409                case DCLAction_Hold.BuildEditModeCameraAdvanceRight:
 410                    InputProcessor.FromKey(action, KeyCode.RightArrow, InputProcessor.Modifier.FocusNotInInput);
 411                    InputProcessor.FromKey(action, KeyCode.D, InputProcessor.Modifier.FocusNotInInput);
 412                    break;
 413                case DCLAction_Hold.BuildEditModeCameraAdvanceUp:
 414                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.FocusNotInInput);
 415                    break;
 416                case DCLAction_Hold.BuildEditModeCameraAdvanceDown:
 417                    InputProcessor.FromKey(action, KeyCode.Q, InputProcessor.Modifier.FocusNotInInput);
 418                    break;
 419                case DCLAction_Hold.BuildEditModeCameraPan:
 420                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 421                    break;
 422                default:
 423                    throw new ArgumentOutOfRangeException();
 424            }
 425        }
 426    }
 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    {
 433        for (var i = 0; i < measurableActions.Length; i++)
 434        {
 435            var action = measurableActions[i];
 436            switch (action.GetDCLAction())
 437            {
 438                case DCLAction_Measurable.CharacterXAxis:
 439                    InputProcessor.FromAxis(action, "Horizontal", InputProcessor.Modifier.NeedsPointerLocked);
 440                    break;
 441                case DCLAction_Measurable.CharacterYAxis:
 442                    InputProcessor.FromAxis(action, "Vertical", InputProcessor.Modifier.NeedsPointerLocked);
 443                    break;
 444                case DCLAction_Measurable.CameraXAxis:
 445                    InputProcessor.FromAxis(action, "Mouse X", InputProcessor.Modifier.NeedsPointerLocked);
 446                    break;
 447                case DCLAction_Measurable.CameraYAxis:
 448                    InputProcessor.FromAxis(action, "Mouse Y", InputProcessor.Modifier.NeedsPointerLocked);
 449                    break;
 450                default:
 451                    throw new ArgumentOutOfRangeException();
 452            }
 453        }
 454    }
 455
 456    private void Stop_Measurable(InputAction_Measurable[] measurableActions)
 457    {
 458        for (var i = 0; i < measurableActions.Length; i++)
 459        {
 460            measurableActions[i].RaiseOnValueChanged(0);
 461        }
 462    }
 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{
 1470    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    {
 3151118488        for (var i = 0; i < MODIFIER_KEYS.Length; i++)
 489        {
 1265612490            var keyCode = MODIFIER_KEYS[i];
 1265612491            var pressed = Input.GetKey(keyCode);
 1265612492            if (modifierKeys == null)
 493            {
 1239788494                if (pressed)
 0495                    return false;
 496            }
 497            else
 498            {
 25824499                if (modifierKeys.Contains(keyCode) != pressed)
 12912500                    return false;
 501            }
 502        }
 503
 309947504        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    {
 452095515        if (IsModifierSet(modifiers, Modifier.NeedsPointerLocked) && !DCL.Helpers.Utils.isCursorLocked)
 103104516            return false;
 517
 348991518        if (IsModifierSet(modifiers, Modifier.FocusNotInInput) && FocusIsInInputField())
 105519            return false;
 520
 348886521        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    {
 310008534        if (!PassModifiers(modifiers))
 12983535            return;
 536
 297025537        if (!PassModifierKeys(modifierKeys))
 12912538            return;
 539
 284113540        if (Input.GetKeyDown(key))
 0541            action.RaiseOnTriggered();
 284113542    }
 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    {
 0553        if (!PassModifiers(modifiers))
 0554            return;
 555
 0556        if (Input.GetMouseButton(mouseButtonIdx))
 0557            action.RaiseOnTriggered();
 0558    }
 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    {
 90419568        if (!PassModifiers(modifiers))
 38674569            return;
 570
 51745571        if (Input.GetKeyDown(key))
 0572            action.RaiseOnStarted();
 51745573        if (Input.GetKeyUp(key))
 0574            action.RaiseOnFinished();
 51745575    }
 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    {
 25834586        if (!PassModifierKeys(modifierKeys))
 0587            return;
 588
 25834589        FromKey(action, key, modifiers);
 25834590    }
 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    {
 0600        if (!PassModifiers(modifiers))
 0601            return;
 602
 0603        if (Input.GetMouseButtonDown(mouseButtonIdx))
 0604            action.RaiseOnStarted();
 0605        if (Input.GetMouseButtonUp(mouseButtonIdx))
 0606            action.RaiseOnFinished();
 0607    }
 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    {
 51668617        if (!PassModifiers(modifiers))
 618        {
 51552619            action.RaiseOnValueChanged(0);
 51552620            return;
 621        }
 622
 116623        action.RaiseOnValueChanged(Input.GetAxis(axisName));
 116624    }
 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    {
 0634        int flagsValue = (int)modifiers;
 0635        int flagValue = (int)value;
 636
 0637        return (flagsValue & flagValue) != 0;
 638    }
 639
 640    public static bool FocusIsInInputField()
 641    {
 271286642        if (EventSystem.current.currentSelectedGameObject != null &&
 643            (EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null ||
 644             EventSystem.current.currentSelectedGameObject.GetComponent<UnityEngine.UI.InputField>() != null))
 645        {
 105646            return true;
 647        }
 648
 271181649        return false;
 650    }
 651}