Example #1
0
    void SwitchSticksInput(InputAction.CallbackContext ctx)
    {
        if (InputHandler.PCLayout)
        {
            return;
        }

        AudioMgr.PlayUISound("Swap");
        ActionRebindSlot slot1 = GetSlotAt(1);
        ActionRebindSlot slot2 = GetSlotAt(2);

        InputActionMap map = InputHandler.Inputs.actions.actionMaps[0]; //The PlayerInput map

        int index1 = FindRealBinding(slot1.ActionPath);
        int index2 = FindRealBinding(slot2.ActionPath);

        string path1 = slot1.ActionPath;
        string path2 = slot2.ActionPath;

        map.ApplyBindingOverride(index1, new InputBinding {
            overridePath = path2
        });
        map.ApplyBindingOverride(index2, new InputBinding {
            overridePath = path1
        });

        slot1.ActionPath = path2;
        slot2.ActionPath = path1;
        slot1.SetInputIcon();
        slot2.SetInputIcon();
    }
Example #2
0
    private void PerformInteractiveRebind(InputAction action, int bindingIndex, bool altAction, int slotIdx, bool allCompositeParts = false)
    {
        InputHandler.LockDeviceSwap = true;
        CurrentRebindOperation?.Cancel();
        m_CanvasGroup.interactable = false;
        WaitingRebindWindow.SetActive(true);

        CurrentRebindOperation = action.PerformInteractiveRebinding(bindingIndex).OnCancel((operation) =>
        {
            CurrentRebindOperation?.Dispose();
            CurrentRebindOperation = null;

            //Hide Rebind UI
            m_CurrentSlot = null;
            m_CanvasGroup.interactable = true;
            WaitingRebindWindow.SetActive(false);
            InputHandler.LockDeviceSwap = false;
        }).OnComplete((operation) =>
        {
            if (ActionAlreadyMap(action.bindings[bindingIndex].effectivePath, slotIdx, out string actionName))
            {
                string content = LocalizationSystem.GetEntry("inputs.replaceinput").Replace("%", actionName);
                UISystem.instance.CreatePopup(content, "menu.yes", "menu.no",
                                              () =>
                {
                    if (altAction)
                    {
                        m_CurrentSlot.AltPath = action.bindings[bindingIndex].effectivePath;
                        m_CurrentSlot.SetAltIcon();
                    }
                    else
                    {
                        m_CurrentSlot.ActionPath = action.bindings[bindingIndex].effectivePath;
                        m_CurrentSlot.SetInputIcon();
                    }

                    UISystem.instance.CloseCurrentWindow();
                    AudioMgr.PlayUISound("Swap");
                    InputHandler.LockDeviceSwap = false;
                },
                                              () =>
                {
                    InputActionMap map = InputHandler.Inputs.actions.actionMaps[0]; //The PlayerInput map
                    int idx            = FindRealBinding(action.bindings[bindingIndex].effectivePath);
                    map.ApplyBindingOverride(idx, new InputBinding {
                        overridePath = altAction ? m_CurrentSlot.AltPath : m_CurrentSlot.ActionPath
                    });
                    UISystem.instance.CloseCurrentWindow();
                    AudioMgr.PlayUISound("Cancel");
                    InputHandler.LockDeviceSwap = false;
                });
            }
            else
            {
                if (altAction)
                {
                    m_CurrentSlot.AltPath = action.bindings[bindingIndex].effectivePath;
                    m_CurrentSlot.SetAltIcon();
                }
                else
                {
                    m_CurrentSlot.ActionPath = action.bindings[bindingIndex].effectivePath;
                    m_CurrentSlot.SetInputIcon();
                }

                AudioMgr.PlayUISound("Swap");
                InputHandler.LockDeviceSwap = false;
            }

            m_CanvasGroup.interactable = true;
            WaitingRebindWindow.SetActive(false);
            CurrentRebindOperation?.Dispose();
            CurrentRebindOperation = null;
        });

        if (InputHandler.PCLayout)
        {
            CurrentRebindOperation.WithCancelingThrough("<Keyboard>/escape");
        }
        else
        {
            CurrentRebindOperation.WithCancelingThrough("<Gamepad>/start");
            CurrentRebindOperation.WithControlsExcluding("<Gamepad>/rightStick");
            CurrentRebindOperation.WithControlsExcluding("<Gamepad>/leftStick");
            CurrentRebindOperation.WithControlsExcluding("<DualShockGamepad>/touchpadButton");
        }

        CurrentRebindOperation.Start();
    }
Example #3
0
 public void RemapAltInput(ActionRebindSlot slot)
 {
     m_CurrentSlot = slot;
     MapControl(InputHandler.Inputs.actions.FindAction(slot.ID), slot.AltIndex, true, slot.SlotIndex);
 }