예제 #1
0
    // Awake
    void Awake()
    {
        DontDestroyOnLoad(settings);

        overrideBind(); // Applique les changement de contrôles préallables

        // J1
        // Avancer
        InputAction act       = settings.FindActionMap("Player1").FindAction("Avancer");
        var         bindIndex = act.bindings.IndexOf(x => x.isPartOfComposite && x.name == "positive");

        b_avancer.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);

        // Reculer
        bindIndex = act.bindings.IndexOf(x => x.isPartOfComposite && x.name == "negative");
        b_reculer.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);

        // Tourner Gauche
        act       = settings.FindActionMap("Player1").FindAction("Tourner");
        bindIndex = act.bindings.IndexOf(x => x.isPartOfComposite && x.name == "negative");
        b_gauche.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);

        // Tourner Droite
        bindIndex = act.bindings.IndexOf(x => x.isPartOfComposite && x.name == "positive");
        b_droite.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);

        // Tirer
        act = settings.FindActionMap("Player1").FindAction("Fire");
        b_tirer.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(0);


        // J2
        // Avancer
        act       = settings.FindActionMap("Player2").FindAction("Avancer");
        bindIndex = act.bindings.IndexOf(x => x.isPartOfComposite && x.name == "positive");
        b_avancer_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);

        // Reculer
        bindIndex = act.bindings.IndexOf(x => x.isPartOfComposite && x.name == "negative");
        b_reculer_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);

        // Tourner Gauche
        act       = settings.FindActionMap("Player2").FindAction("Tourner");
        bindIndex = act.bindings.IndexOf(x => x.isPartOfComposite && x.name == "negative");
        b_gauche_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);

        // Tourner Droite
        bindIndex = act.bindings.IndexOf(x => x.isPartOfComposite && x.name == "positive");
        b_droite_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);

        // Tirer
        act = settings.FindActionMap("Player2").FindAction("Fire");
        b_tirer_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(0);
    }
예제 #2
0
    private static string GetBindingDisplayString(InputAction inputAction, InputDevice inputDevice)
    {
        try
        {
            string combinedBindingDisplayStrings = inputAction.GetBindingDisplayString(InputBinding.DisplayStringOptions.DontOmitDevice);
            if (combinedBindingDisplayStrings.IsNullOrEmpty())
            {
                return("");
            }

            string[] bindingDisplayStrings   = combinedBindingDisplayStrings.Split(InputActionInfo.InfoSeparator);
            string   displayStringDeviceText = GetDisplayStringDeviceText(inputDevice);
            if (displayStringDeviceText.IsNullOrEmpty())
            {
                return("");
            }
            string matchingBindingDisplayString = bindingDisplayStrings
                                                  .FirstOrDefault(it => it.Contains(displayStringDeviceText));
            if (matchingBindingDisplayString.IsNullOrEmpty())
            {
                return("");
            }

            return(matchingBindingDisplayString
                   .Replace(displayStringDeviceText, "")
                   .Replace(" +", "+")
                   .Replace("+ ", "+")
                   .Trim());
        }
        catch (NotImplementedException e)
        {
            Log.Logger.Error(e, $"Could not determine BindingDisplayString for InputAction '{inputAction.name}'");
            return("");
        }
    }
예제 #3
0
    private static string GetBindingDisplayString(InputAction action)
    {
        StringBuilder sb = new StringBuilder();
        ReadOnlyArray <InputBinding> bindings = action.bindings;

        for (int i = 0; i < bindings.Count; ++i)
        {
            InputBinding binding = bindings[i];
            // Only consider actions that make use of connected devices.
            // And only create info text for a composite but not for its parts.
            if (binding.isPartOfComposite ||
                (!binding.isComposite && InputSystem.FindControl(binding.path) == null))
            {
                continue;
            }

            string text = action.GetBindingDisplayString(i, InputBinding.DisplayStringOptions.DontOmitDevice);
            if (sb.Length > 0)
            {
                sb.Append($" | {text}");
            }
            else
            {
                sb.Append(text);
            }
        }

        return(sb.ToString());
    }
예제 #4
0
        // Use this for initialization
        void Start()
        {
#if USE_GUI
            Panel.gameObject.SetActive(false);
            headerLabel.gameObject.SetActive(false);
            tweakField.gameObject.SetActive(false);
            tweakText.gameObject.SetActive(targetPlayer != null);

            if (targetPlayer)
            {
                previousCanLook    = TargetPlayer.Camera.CanLookAround;
                previousCanMove    = TargetPlayer.Movement.CanMoveAround;
                previousLockCursor = TargetPlayer.Camera.ShouldLockCursor;
                viewport.anchorMin = new Vector2(0, 0);
                viewport.anchorMax = new Vector2(1, 1);
                viewport.sizeDelta = new Vector2(0, 0);

                SetupUI();
            }

#if ENABLE_INPUT_SYSTEM && GOLD_PLAYER_NEW_INPUT
            tweakText.text = "Press " + toggleAction.GetBindingDisplayString() + " to tweak settings. Press " + resetSceneAction.GetBindingDisplayString() + " to reset scene.";
#else
            tweakText.text = "Press " + toggleKey.ToString() + " to tweak settings. Press " + resetSceneKey.ToString() + " to reset scene.";
#endif
#else
            Debug.LogWarning("GoldPlayerTweaker can't be used without UGUI!");
#endif
        }
예제 #5
0
    public void UpdateUIElements()
    {
        InputActionMap map;
        InputActionMap mapActions = inputs.FindActionMap("Actions");
        InputActionMap mapMenu    = inputs.FindActionMap("MainMenu");

        for (int j = 0; j < groupNames.Length; j++)
        {
            for (int i = 0; i < actionNames.Length; i++)
            {
                if (texts[j].Length > i)
                {
                    if (i < mapSwitchIndex)
                    {
                        map = mapActions;
                    }
                    else
                    {
                        map = mapMenu;
                    }
                    InputAction action       = map.FindAction(actionNames[i]);
                    int         bindingIndex = action.GetBindingIndex(InputBinding.MaskByGroup(groupNames[j]));
                    texts[j][i].text = action.GetBindingDisplayString(bindingIndex);
                }
            }
        }
    }
예제 #6
0
    void changeTirer(int player)
    {
        k = settings.FindActionMap("Player" + player.ToString());

        b_save.interactable = false;

        InputAction act = k.FindAction("Fire");

        var rebind = act.PerformInteractiveRebinding();

        rebind?.Cancel();
        void CleanUp()
        {
            rebind?.Dispose();
            rebind = null;
            finishedRebind();
        }

        void saveChanges()
        {
            if (player == 1)
            {
                b_tirer.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(0);
            }
            if (player == 2)
            {
                b_tirer_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(0);
            }
            PlayerPrefs.SetString("FirePlayer" + player, act.bindings[0].overridePath);
        }

        rebind = act.PerformInteractiveRebinding();

        rebind.WithControlsExcluding("Mouse");
        rebind.WithCancelingThrough("<Keyboard>/escape");
        rebind.OnMatchWaitForAnother(0.1f);
        rebind.Start().OnCancel(x => CleanUp()).OnComplete(x =>
        {
            saveChanges();
            CleanUp();
        });
    }
예제 #7
0
        /// <summary>
        /// Get <see cref="InputAction"/> key by name and binging index.
        /// </summary>
        public string GetActionKey(string name, int bindingIndex)
        {
            string      result = "";
            InputAction action = controls.asset.FindAction(name);

            if (action != null)
            {
                result = action.GetBindingDisplayString(bindingIndex);
            }
            return(result);
        }
 public void Init(InputAction inputAction)
 {
     if (isInit)
     {
         return;
     }
     action                 = inputAction;
     keybindName.text       = inputAction.name;
     keybindInputField.text = inputAction.GetBindingDisplayString().Split('|')[0];
     isInit                 = true;
 }
예제 #9
0
    public string ConvertControlInString(string original)
    {
        Match match = inputRegex.Match(original);

        if (match.Success)
        {
            InputAction action = playerInput.currentActionMap.FindAction(match.Groups[1].Value);
            return(inputRegex.Replace(original, action.GetBindingDisplayString()));
        }

        return(original);
    }
예제 #10
0
    public void UpdateSingleElement(InputAction action, int bindingIndex, string actionMap)
    {
        InputActionMap map = inputs.FindActionMap(actionMap);

        for (int i = 0; i < actionNames.Length; i++)
        {
            if (action == map.FindAction(actionNames[i]))
            {
                texts[bindingIndex][i].text = action.GetBindingDisplayString(bindingIndex);
            }
        }
    }
예제 #11
0
    public void ChangeKeyBind()
    {
        if (!isComposite)
        {
            var rebindOperation = selectedAction.PerformInteractiveRebinding()
                                  .Start()
                                  .OnComplete(result =>
            {
                Debug.LogFormat("Rebinded {0} to {1}"
                                , keyToChange.ToString()
                                , selectedAction.GetBindingDisplayString());


                GameManager.Manager.SavePlayerBindings();
                UpdateText();
                result.Dispose();
            });
        }
        else
        {
            var bindingToChange = selectedAction.bindings[compositeId];

            var rebindComposite = selectedAction.PerformInteractiveRebinding()
                                  .WithTargetBinding(compositeId)
                                  .Start()
                                  .OnComplete(result =>
            {
                Debug.LogFormat("Rebinded {0} to {1}"
                                , bindingToChange.ToDisplayString()
                                , selectedAction.GetBindingDisplayString(bindingIndex: compositeId));

                GameManager.Manager.SavePlayerBindings();
                UpdateText();
                result.Dispose();
            });
        }


        UpdateText("Press any key to rebind");
    }
예제 #12
0
    private void Start()
    {
        PlayerInputAction actions     = GameManager.Manager.InputActions;
        InputAction       inputAction = null;

        if (keyActionText != null)
        {
            keyActionText.text = currControl.ToString();
        }

        switch (currControl)
        {
        case GameControls.Interact:
            inputAction = actions.PlayerControls.Pickup;
            break;

        case GameControls.Repair:
            inputAction = actions.PlayerControls.Repair;
            break;

        case GameControls.Switch:
            inputAction = actions.PlayerControls.Switch;
            break;
        }

        if (keyRebindText == null)
        {
            return;
        }

        if (isComposite)
        {
            keyRebindText.text = inputAction.GetBindingDisplayString(bindingIndex: compositeId + 1);
        }
        else
        {
            keyRebindText.text = inputAction.GetBindingDisplayString();
        }
    }
예제 #13
0
    public void OnEnable()
    {
        label.text           = input_action.name;
        current_binding.text = input_action.GetBindingDisplayString();

        binding = input_action.bindings[input_action.bindings.IndexOf((x) => x.name == binding.name)]; // Refresh binding incase they were changed, we assume that the name stayed the same
        if (binding.isComposite)
        {
            button.gameObject.SetActive(false);
            current_binding.gameObject.SetActive(false);
        }
        else if (binding.isPartOfComposite)
        {
            label.text           = $" - {binding.name}";
            current_binding.text = binding.ToDisplayString();
        }
    }
예제 #14
0
파일: Tooltip.cs 프로젝트: MaraSlavk/novel
    private void ShowTooltip(TooltipData data)
    {
        // Try get action
        InputAction action   = MainSingleton.Instance.input.actions.FindAction(data.title);
        string      shortcut = null;

        if (action != null)
        {
            shortcut = action.GetBindingDisplayString(DisplayStringOptions.DontIncludeInteractions, MainSingleton.Instance.input.currentControlScheme);
        }
        // Format
        tooltipText.text =
            $"<b>{data.title}</b>{(shortcut != null ? $"<align=\"flush\"> {shortcut.ToUpper()}</align>" : "")}" +
            $"{(!string.IsNullOrEmpty(data.description) ? $"\n<size=80%>{data.description}" : "")}" +
            $"{(!string.IsNullOrEmpty(data.footnote) ? $"\n<size=80%><i>{data.footnote}" : "")}";

        canvasGroup.alpha = 1;
        LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)transform);
    }
예제 #15
0
 private void UpdateKeyName()
 {
     keyName.text = action.GetBindingDisplayString(bindingId, displayOptions);
 }
예제 #16
0
    void change(string sensAxe, string action, int player)
    {
        k = settings.FindActionMap("Player" + player.ToString());
        Debug.Log("Player" + player.ToString());

        b_save.interactable = false;

        InputAction act       = k.FindAction(action);
        var         bindIndex = act.bindings.IndexOf(x => x.isPartOfComposite && x.name == sensAxe);

        var rebind = act.PerformInteractiveRebinding();

        rebind?.Cancel();
        void CleanUp()
        {
            rebind?.Dispose();
            rebind = null;
            finishedRebind();
        }

        void saveChanges()
        {
            if (action == "Avancer")
            {
                if (sensAxe == "positive")
                {
                    if (player == 1)
                    {
                        b_avancer.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);
                    }
                    if (player == 2)
                    {
                        b_avancer_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);
                    }
                }
                if (sensAxe == "negative")
                {
                    if (player == 1)
                    {
                        b_reculer.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);
                    }
                    if (player == 2)
                    {
                        b_reculer_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);
                    }
                }
            }
            if (action == "Tourner")
            {
                if (sensAxe == "positive")
                {
                    if (player == 1)
                    {
                        b_droite.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);
                    }
                    if (player == 2)
                    {
                        b_droite_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);
                    }
                }
                if (sensAxe == "negative")
                {
                    if (player == 1)
                    {
                        b_gauche.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);
                    }
                    if (player == 2)
                    {
                        b_gauche_j2.GetComponentInChildren <Text>().text = act.GetBindingDisplayString(bindIndex);
                    }
                }
            }
            PlayerPrefs.SetString("Player" + player + action + sensAxe, act.bindings[bindIndex].overridePath);
        }

        //rebind = act.PerformInteractiveRebinding();

        rebind.WithControlsExcluding("Mouse");
        rebind.WithTargetBinding(bindIndex);
        rebind.WithCancelingThrough("<Keyboard>/escape");
        rebind.OnMatchWaitForAnother(0.1f);
        rebind.Start().OnCancel(x =>
        {
            CleanUp();
        }).OnComplete(x =>
        {
            saveChanges();
            CleanUp();
        });
    }