< 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:654
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    ToggleAvatarNamesHud = 130,
 28
 29    OpenExpressions = 200,
 30    Expression_Wave = 201,
 31    Expression_FistPump = 202,
 32    Expression_Robot = 203,
 33    Expression_RaiseHand = 204,
 34    Expression_Clap = 205,
 35    Expression_ThrowMoney = 206,
 36    Expression_SendKiss = 207,
 37
 38    //Builder In World 4xx
 39    BuildEditModeChange = 408,
 40    BuildEditModeToggleUI = 409,
 41    BuildEditModeToggleEntityList = 410,
 42    BuildEditModeToggleCatalog = 411,
 43    BuildEditModeToggleSceneInfo = 412,
 44    BuildEditModeToggleChangeCamera = 413,
 45    BuildEditModeToggleControls = 414,
 46    BuildEditModeToggleSnapMode = 415,
 47    BuildEditModeUndoAction = 417,
 48    BuildEditModeRedoAction = 418,
 49    BuildEditModeQuickBar1 = 419,
 50    BuildEditModeQuickBar2 = 420,
 51    BuildEditModeQuickBar3 = 421,
 52    BuildEditModeQuickBar4 = 422,
 53    BuildEditModeQuickBar5 = 423,
 54    BuildEditModeQuickBar6 = 424,
 55    BuildEditModeQuickBar7 = 425,
 56    BuildEditModeQuickBar8 = 426,
 57    BuildEditModeQuickBar9 = 427,
 58    BuildEditModeDuplicate = 428,
 59    BuildEditModeTranslate = 429,
 60    BuildEditModeRotate = 430,
 61    BuildEditModeScale = 431,
 62    BuildEditModeDelete = 434,
 63    BuildEditModeFocusSelectedEntities = 435,
 64    BuildEditModeReset = 443,
 65    BuildEditHideSelectedEntities = 444,
 66    BuildEditShowAllEntities = 445,
 67    BuildEditModeResetCamera = 446,
 68    BuildEditModeZoomIn = 447,
 69    BuildEditModeZoomOut = 448
 70}
 71
 72/// <summary>
 73/// Mapping for hold actions
 74/// </summary>
 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                case DCLAction_Trigger.ToggleAvatarNamesHud:
 352                    InputProcessor.FromKey(action, KeyCode.N, modifiers: InputProcessor.Modifier.FocusNotInInput);
 353                    break;
 354                default:
 355                    throw new ArgumentOutOfRangeException();
 356            }
 357        }
 358    }
 359
 360    /// <summary>
 361    /// Map the hold actions to inputs + modifiers and check if their events must be triggered
 362    /// </summary>
 363    private void Update_Hold(InputAction_Hold[] holdActions)
 364    {
 365        for (var i = 0; i < holdActions.Length; i++)
 366        {
 367            var action = holdActions[i];
 368            switch (action.GetDCLAction())
 369            {
 370                case DCLAction_Hold.Sprint:
 371                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.NeedsPointerLocked);
 372                    break;
 373                case DCLAction_Hold.Jump:
 374                    InputProcessor.FromKey(action, KeyCode.Space, InputProcessor.Modifier.NeedsPointerLocked);
 375                    break;
 376                case DCLAction_Hold.FreeCameraMode:
 377                    //Disable until the fine-tuning is ready
 378                    if (ENABLE_THIRD_PERSON_CAMERA)
 379                        InputProcessor.FromKey(action, KeyCode.Y, InputProcessor.Modifier.NeedsPointerLocked);
 380                    break;
 381                case DCLAction_Hold.VoiceChatRecording:
 382                    // Push to talk functionality only triggers if no modifier key is pressed
 383                    InputProcessor.FromKey(action, KeyCode.T, InputProcessor.Modifier.FocusNotInInput, null);
 384                    break;
 385                case DCLAction_Hold.DefaultConfirmAction:
 386                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.None);
 387                    break;
 388                case DCLAction_Hold.DefaultCancelAction:
 389                    InputProcessor.FromKey(action, KeyCode.F, InputProcessor.Modifier.None);
 390                    break;
 391                case DCLAction_Hold.BuildEditModeMultiSelection:
 392                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 393                    break;
 394                case DCLAction_Hold.BuildEditModeSquareMultiSelection:
 395                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 396                    break;
 397                case DCLAction_Hold.BuildEditModeFirstPersonRotation:
 398                    InputProcessor.FromKey(action, KeyCode.R, InputProcessor.Modifier.FocusNotInInput);
 399                    break;
 400                case DCLAction_Hold.BuildEditModeCameraAdvanceFoward:
 401                    InputProcessor.FromKey(action, KeyCode.UpArrow, InputProcessor.Modifier.FocusNotInInput);
 402                    InputProcessor.FromKey(action, KeyCode.W, InputProcessor.Modifier.FocusNotInInput);
 403                    break;
 404                case DCLAction_Hold.BuildEditModeCameraAdvanceBack:
 405                    InputProcessor.FromKey(action, KeyCode.DownArrow, InputProcessor.Modifier.FocusNotInInput);
 406                    InputProcessor.FromKey(action, KeyCode.S, InputProcessor.Modifier.FocusNotInInput);
 407                    break;
 408                case DCLAction_Hold.BuildEditModeCameraAdvanceLeft:
 409                    InputProcessor.FromKey(action, KeyCode.LeftArrow, InputProcessor.Modifier.FocusNotInInput);
 410                    InputProcessor.FromKey(action, KeyCode.A, InputProcessor.Modifier.FocusNotInInput);
 411                    break;
 412                case DCLAction_Hold.BuildEditModeCameraAdvanceRight:
 413                    InputProcessor.FromKey(action, KeyCode.RightArrow, InputProcessor.Modifier.FocusNotInInput);
 414                    InputProcessor.FromKey(action, KeyCode.D, InputProcessor.Modifier.FocusNotInInput);
 415                    break;
 416                case DCLAction_Hold.BuildEditModeCameraAdvanceUp:
 417                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.FocusNotInInput);
 418                    break;
 419                case DCLAction_Hold.BuildEditModeCameraAdvanceDown:
 420                    InputProcessor.FromKey(action, KeyCode.Q, InputProcessor.Modifier.FocusNotInInput);
 421                    break;
 422                case DCLAction_Hold.BuildEditModeCameraPan:
 423                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 424                    break;
 425                default:
 426                    throw new ArgumentOutOfRangeException();
 427            }
 428        }
 429    }
 430
 431    /// <summary>
 432    /// Map the measurable actions to inputs + modifiers and check if their events must be triggered
 433    /// </summary>
 434    private void Update_Measurable(InputAction_Measurable[] measurableActions)
 435    {
 436        for (var i = 0; i < measurableActions.Length; i++)
 437        {
 438            var action = measurableActions[i];
 439            switch (action.GetDCLAction())
 440            {
 441                case DCLAction_Measurable.CharacterXAxis:
 442                    InputProcessor.FromAxis(action, "Horizontal", InputProcessor.Modifier.NeedsPointerLocked);
 443                    break;
 444                case DCLAction_Measurable.CharacterYAxis:
 445                    InputProcessor.FromAxis(action, "Vertical", InputProcessor.Modifier.NeedsPointerLocked);
 446                    break;
 447                case DCLAction_Measurable.CameraXAxis:
 448                    InputProcessor.FromAxis(action, "Mouse X", InputProcessor.Modifier.NeedsPointerLocked);
 449                    break;
 450                case DCLAction_Measurable.CameraYAxis:
 451                    InputProcessor.FromAxis(action, "Mouse Y", InputProcessor.Modifier.NeedsPointerLocked);
 452                    break;
 453                default:
 454                    throw new ArgumentOutOfRangeException();
 455            }
 456        }
 457    }
 458
 459    private void Stop_Measurable(InputAction_Measurable[] measurableActions)
 460    {
 461        for (var i = 0; i < measurableActions.Length; i++)
 462        {
 463            measurableActions[i].RaiseOnValueChanged(0);
 464        }
 465    }
 466}
 467
 468/// <summary>
 469/// Helper class that wraps the processing of inputs and modifiers to trigger actions events
 470/// </summary>
 471public static class InputProcessor
 472{
 1473    private static readonly KeyCode[] MODIFIER_KEYS = new[] { KeyCode.LeftControl, KeyCode.LeftAlt, KeyCode.LeftShift, K
 474
 475    [Flags]
 476    public enum Modifier
 477    {
 478        //Set the values as bit masks
 479        None = 0b0000000, // No modifier needed
 480        NeedsPointerLocked = 0b0000001, // The pointer must be locked to the game
 481        FocusNotInInput = 0b0000010, // The game focus cannot be in an input field
 482    }
 483
 484    /// <summary>
 485    /// Check if the modifier keys are pressed
 486    /// </summary>
 487    /// <param name="modifierKeys"> Keycodes modifiers</param>
 488    /// <returns></returns>
 489    public static Boolean PassModifierKeys(KeyCode[] modifierKeys)
 490    {
 4168940491        for (var i = 0; i < MODIFIER_KEYS.Length; i++)
 492        {
 1675484493            var keyCode = MODIFIER_KEYS[i];
 1675484494            var pressed = Input.GetKey(keyCode);
 1675484495            if (modifierKeys == null)
 496            {
 1635944497                if (pressed)
 0498                    return false;
 499            }
 500            else
 501            {
 39540502                if (modifierKeys.Contains(keyCode) != pressed)
 19770503                    return false;
 504            }
 505        }
 506
 408986507        return true;
 508    }
 509
 510    /// <summary>
 511    /// Check if a miscellaneous modifiers are present. These modifiers are related to the meta-state of the application
 512    /// they can be anything such as mouse pointer state, where the focus is, camera mode...
 513    /// </summary>
 514    /// <param name="modifiers"></param>
 515    /// <returns></returns>
 516    public static bool PassModifiers(Modifier modifiers)
 517    {
 626526518        if (IsModifierSet(modifiers, Modifier.NeedsPointerLocked) && !DCL.Helpers.Utils.isCursorLocked)
 157840519            return false;
 520
 468686521        if (IsModifierSet(modifiers, Modifier.FocusNotInInput) && FocusIsInInputField())
 82522            return false;
 523
 468604524        return true;
 525    }
 526
 527    /// <summary>
 528    /// Process an input action mapped to a keyboard key.
 529    /// </summary>
 530    /// <param name="action">Trigger Action to perform</param>
 531    /// <param name="key">KeyCode mapped to this action</param>
 532    /// <param name="modifierKeys">KeyCodes required to perform the action</param>
 533    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 534    public static void FromKey(InputAction_Trigger action, KeyCode key, KeyCode[] modifierKeys = null,
 535        Modifier modifiers = Modifier.None)
 536    {
 409012537        if (!PassModifiers(modifiers))
 19804538            return;
 539
 389208540        if (!PassModifierKeys(modifierKeys))
 19770541            return;
 542
 369438543        if (Input.GetKeyDown(key))
 0544            action.RaiseOnTriggered();
 369438545    }
 546
 547    /// <summary>
 548    /// Process an input action mapped to a button.
 549    /// </summary>
 550    /// <param name="action">Trigger Action to perform</param>
 551    /// <param name="mouseButtonIdx">Index of the mouse button mapped to this action</param>
 552    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 553    public static void FromMouseButton(InputAction_Trigger action, int mouseButtonIdx,
 554        Modifier modifiers = Modifier.None)
 555    {
 0556        if (!PassModifiers(modifiers))
 0557            return;
 558
 0559        if (Input.GetMouseButton(mouseButtonIdx))
 0560            action.RaiseOnTriggered();
 0561    }
 562
 563    /// <summary>
 564    /// Process an input action mapped to a keyboard key
 565    /// </summary>
 566    /// <param name="action">Hold Action to perform</param>
 567    /// <param name="key">KeyCode mapped to this action</param>
 568    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 569    public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers = Modifier.None)
 570    {
 138418571        if (!PassModifiers(modifiers))
 59198572            return;
 573
 79220574        if (Input.GetKeyDown(key))
 0575            action.RaiseOnStarted();
 79220576        if (Input.GetKeyUp(key))
 0577            action.RaiseOnFinished();
 79220578    }
 579
 580    /// <summary>
 581    /// Process an input action mapped to a keyboard key
 582    /// </summary>
 583    /// <param name="action">Hold Action to perform</param>
 584    /// <param name="key">KeyCode mapped to this action</param>
 585    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 586    /// <param name="modifierKeys">KeyCodes required to perform the action</param>
 587    public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers, KeyCode[] modifierKeys)
 588    {
 39548589        if (!PassModifierKeys(modifierKeys))
 0590            return;
 591
 39548592        FromKey(action, key, modifiers);
 39548593    }
 594
 595    /// <summary>
 596    /// Process an input action mapped to a mouse button
 597    /// </summary>
 598    /// <param name="action">Hold Action to perform</param>
 599    /// <param name="mouseButtonIdx">Index of the mouse button</param>
 600    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 601    public static void FromMouse(InputAction_Hold action, int mouseButtonIdx, Modifier modifiers = Modifier.None)
 602    {
 0603        if (!PassModifiers(modifiers))
 0604            return;
 605
 0606        if (Input.GetMouseButtonDown(mouseButtonIdx))
 0607            action.RaiseOnStarted();
 0608        if (Input.GetMouseButtonUp(mouseButtonIdx))
 0609            action.RaiseOnFinished();
 0610    }
 611
 612    /// <summary>
 613    /// Process an input action mapped to an axis
 614    /// </summary>
 615    /// <param name="action">Measurable Action to perform</param>
 616    /// <param name="axisName">Axis name</param>
 617    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 618    public static void FromAxis(InputAction_Measurable action, string axisName, Modifier modifiers = Modifier.None)
 619    {
 79096620        if (!PassModifiers(modifiers))
 621        {
 78920622            action.RaiseOnValueChanged(0);
 78920623            return;
 624        }
 625
 176626        action.RaiseOnValueChanged(Input.GetAxis(axisName));
 176627    }
 628
 629    /// <summary>
 630    /// Bitwise check for the modifiers flags
 631    /// </summary>
 632    /// <param name="modifiers">Modifier to check</param>
 633    /// <param name="value">Modifier mapped to a bit to check</param>
 634    /// <returns></returns>
 635    public static bool IsModifierSet(Modifier modifiers, Modifier value)
 636    {
 0637        int flagsValue = (int)modifiers;
 0638        int flagValue = (int)value;
 639
 0640        return (flagsValue & flagValue) != 0;
 641    }
 642
 643    public static bool FocusIsInInputField()
 644    {
 376171645        if (EventSystem.current.currentSelectedGameObject != null &&
 646            (EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null ||
 647             EventSystem.current.currentSelectedGameObject.GetComponent<UnityEngine.UI.InputField>() != null))
 648        {
 82649            return true;
 650        }
 651
 376089652        return false;
 653    }
 654}