Exemplo n.º 1
0
    private void GetCorrectPlayer(string p, KeybindEnum command, KeyCode keyValue)
    {
        var temp = playerKeybinds.ToList().FindIndex(playerIndex => string.Compare(playerIndex.GetPlayerIdentity(), p) == 0);

        if (temp != -1)
        {
            playerKeybinds[temp].SetKey(command, keyValue);
        }
    }
Exemplo n.º 2
0
    /*
     * Will change the KeyCode in the array and dictionary.
     */
    public void SetKey(KeybindEnum command, KeyCode toSet, bool reset = false)
    {
        var commandPosition = playerInput.ToList().FindIndex(k => k.command == command);

        if (keyBindingsDictionary.ContainsKey(command) == false || commandPosition <= -1)
        {
            Debug.LogError($"Error when trying to set the key of command {command}.");
            return;
        }
        if (!reset)
        {
            CheckOverlappingKeybinds(toSet);
        }
        playerInput[commandPosition].keyCode = toSet;
        keyBindingsDictionary[command]       = toSet;
    }
Exemplo n.º 3
0
 /*  -----------------------------------------------
  *  PRIVATE METHODS
  *  -----------------------------------------------*/
 /*
  * Listener method to change keybindings.
  */
 private IEnumerator ListenForKeyInput(KeybindEnum command, string p)
 {
     while (!Input.GetKeyDown(KeyCode.Escape))
     {
         foreach (KeyCode keyValue in System.Enum.GetValues(typeof(KeyCode)))
         {
             if (Input.GetKeyDown(keyValue))
             {
                 if (IgnoreInput(keyValue))
                 {
                     continue;
                 }
                 GetCorrectPlayer(p, command, keyValue);
                 SetGameObjectTexts(false);
                 listeningForInput = null;
                 yield break;
             }
         }
         yield return(new WaitForSecondsRealtime(0));
     }
     SetGameObjectTexts(false);
     listeningForInput = null;
 }
Exemplo n.º 4
0
 /*
  * Method to help organize the UI.
  */
 private int FindCorrectCommand(KeybindEnum toFind, InputKeys[] searchArea) => searchArea.ToList().FindIndex(a => a.command == toFind);
Exemplo n.º 5
0
 /*
  * Use this method to set the value of keys as text. eg in options menu
  */
 public string GetKeyAsString(KeybindEnum command) => keyBindingsDictionary[command].ToString();
Exemplo n.º 6
0
 /*  -----------------------------------------------
  *     PUBLIC METHODS
  *  -----------------------------------------------*/
 /*
  * Use this method with Input.GetKey(...);
  */
 public KeyCode GetKeyCode(KeybindEnum command) => keyBindingsDictionary[command];