예제 #1
0
    /// <summary>
    /// Returns true during the first frame the player releases the button
    /// </summary>
    /// <param name="buttonKey"></param>
    /// <param name="player"></param>
    public static bool GetButtonUp(PlayerButton button, IInputPlayer player = null)
    {
        string buttonKey = button.ToString();

        if (player == null)
        {
            bool result = keyboardController.GetButtonUp(KeyboardButtonLookUp(0, buttonKey));
            for (int i = 0; i < xboxControllers.Count; i++)
            {
                if (xboxControllers[i].IsConnected)
                {
                    result |= xboxControllers[i].GetButtonUp(XboxButtonLookUp(i, buttonKey));
                }
            }

            return(result);
        }
        else
        {
            if (player.InputMethod == InputMethod.Keyboard)
            {
                return(keyboardController.GetButtonUp(KeyboardButtonLookUp(player.PlayerIndex + 1, buttonKey)));
            }

            else if (player.InputMethod == InputMethod.XboxController)
            {
                return(xboxControllers[player.PlayerIndex].GetButtonUp(XboxButtonLookUp(player.PlayerIndex + 1, buttonKey)));
            }

            else
            {
                return(false);
            }
        }
    }
예제 #2
0
파일: PlayerHealth.cs 프로젝트: GDCASU/Rush
 private void Start()
 {
     pm     = GetComponent <PlayerMovement>();
     player = GetComponent <IInputPlayer>();
     //sp = GetComponent<SpriteRenderer>();
     HUDManager.singleton.setLiveCount(lives);
     _maxHealth = lives;
 }
예제 #3
0
    public bool freezeInPlace;    // player cannot move at all

    private void Start()
    {
        scaleX    = sprite.transform.localScale.x;
        inControl = true;
        rb        = GetComponent <Rigidbody2D>();
        player    = GetComponent <IInputPlayer>();
        //sp = GetComponent<SpriteRenderer>();
        anim = GetComponent <AnimationController>();
    }
예제 #4
0
 /// <summary>
 /// Resets the state of the button pressed by the player
 /// </summary>
 /// <param name="buttonKey"></param>
 /// <param name="player"></param>
 public static void ResetButton(XboxController.XboxButton button, IInputPlayer player)
 {
     if (player == null)
     {
         return;
     }
     else
     {
         xboxControllers[player.PlayerIndex].ResetButton(button);
     }
     Input.ResetInputAxes();
 }
예제 #5
0
    /// <summary>
    /// Resets the state of the button pressed by the player
    /// </summary>
    /// <param name="buttonKey"></param>
    /// <param name="player"></param>
    public static void ResetButton(PlayerButton button, IInputPlayer player)
    {
        string buttonKey = button.ToString();

        if (player == null)
        {
            return;
        }
        else
        {
            xboxControllers[player.PlayerIndex].ResetButton(XboxButtonLookUp(player.PlayerIndex + 1, buttonKey));
        }
        Input.ResetInputAxes();
    }
예제 #6
0
        public InputAction(IInputPlayer player, string id)
        {
            Player = player;
            Id     = id;

            Enabled = true;

            mouseButtons           = new List <MouseButton>();
            mouseButtonsNegative   = new List <MouseButton>();
            keyboardKeys           = new List <KeyboardKey>();
            keyboardKeysNegative   = new List <KeyboardKey>();
            gamepadButtons         = new List <GamepadButton>();
            gamepadButtonsNegative = new List <GamepadButton>();
            gamepadAxis            = new List <GamepadAxis>();

            ResetBindings();
        }
예제 #7
0
    /// <summary>
    /// Returns the axis value during the first frame the axis reaches its maximum aboslute value
    /// </summary>
    /// <param name="axisKey"></param>
    /// <param name="player"></param>
    public static float GetAxisDown(PlayerAxis axis, IInputPlayer player = null)
    {
        string axisKey = axis.ToString();

        if (player == null)
        {
            List <float> valueList = new List <float>();

            // Add keyboard values to list
            valueList.Add(keyboardController.GetAxisDown(KeyboardAxisLookUp(0, "(Pos)" + axisKey)));
            valueList.Add(-keyboardController.GetAxisDown(KeyboardAxisLookUp(0, "(Neg)" + axisKey)));

            // Add xbox values to list
            for (int i = 0; i < xboxControllers.Count; i++)
            {
                if (xboxControllers[i].IsConnected)
                {
                    valueList.Add(xboxControllers[i].GetAxisDown(XboxAxisLookUp(0, axisKey)));
                }
            }

            return(LargestAbsoluteValue(valueList));
        }
        else
        {
            if (player.InputMethod == InputMethod.Keyboard)
            {
                float keyboardPos = keyboardController.GetAxisDown(KeyboardAxisLookUp(player.PlayerIndex + 1, "(Pos)" + axisKey));
                float keyboardNeg = -keyboardController.GetAxisDown(KeyboardAxisLookUp(player.PlayerIndex + 1, "(Neg)" + axisKey));
                return(LargestAbsoluteValue(new List <float> {
                    keyboardPos, keyboardNeg
                }));
            }

            else if (player.InputMethod == InputMethod.XboxController)
            {
                return(xboxControllers[(int)player.PlayerIndex].GetAxisDown(XboxAxisLookUp(player.PlayerIndex + 1, axisKey)));
            }

            else
            {
                return(0);
            }
        }
    }
예제 #8
0
    public void SetButton(XboxController.XboxButton passed)
    {
        List <string> xboxCodes = canvas.GetComponent <MenuOptions>().xboxCodes;

        player = GameObject.Find("Player").GetComponentInChildren <IInputPlayer>();
        foreach (string xKey in xboxCodes)
        {
            if (passed.ToString() == xKey)
            {
                return;
            }
        }
        InputManager.RemapXboxButton(action, passed, player);
        xboxCodes.Remove(keyName);
        keyName = passed.ToString();
        xboxCodes.Add(keyName);
        GetComponentInChildren <Text>().text = keyName;
    }
예제 #9
0
    public void SetButton(KeyCode passed)
    {
        List <string> keyboardCodes = canvas.GetComponent <MenuOptions>().keyboardCodes;

        player = GameObject.Find("Player").GetComponentInChildren <IInputPlayer>();
        foreach (string key in keyboardCodes)
        {
            if (passed.ToString() == key)
            {
                return;
            }
        }
        InputManager.RemapKeyboardButton(action, passed, player);
        keyboardCodes.Remove(keyName);
        keyName = passed.ToString();
        keyboardCodes.Add(keyName);
        text.GetComponentInChildren <Text>().text = keyName;
    }
예제 #10
0
 /// <summary>
 /// If the player is not null, returns the first xbox button pressed by the player.
 /// If the player is null, returns the first xbox button pressed by any player.
 /// If no player exists, returns None
 /// </summary>
 /// <param name="player"></param>
 public static XboxController.XboxButton GetNextXboxButton(IInputPlayer player = null)
 {
     if (player == null)
     {
         foreach (XboxController xc in xboxControllers)
         {
             XboxController.XboxButton nextButton;
             if ((nextButton = xc.NextXboxButton) != XboxController.XboxButton.None)
             {
                 return(nextButton);
             }
         }
         return(XboxController.XboxButton.None);
     }
     else
     {
         return(xboxControllers[(int)player.PlayerIndex].NextXboxButton);
     }
 }
예제 #11
0
        public IInputPlayer AddPlayer(string playerId)
        {
            IInputPlayer result = null;

            foreach (var player in players)
            {
                if (player.Id == playerId)
                {
                    result = player;
                    break;
                }
            }

            if (result == null)
            {
                result = new InputPlayer(playerId);
                players.Add(result);
            }

            return(result);
        }
예제 #12
0
파일: MenuOptions.cs 프로젝트: GDCASU/Rush
 // Start is called before the first frame update
 void Start()
 {
     player = transform.parent.gameObject.GetComponentInChildren <IInputPlayer>();
     keyboardCodes.Add("W");
     keyboardCodes.Add("S");
     keyboardCodes.Add("D");
     keyboardCodes.Add("A");
     foreach (InputManager.Button b in GameObject.Find("Managers").GetComponent <InputManager>().buttons)
     {
         keyboardCodes.Add(b.keyboardButton.ToString());
         xboxCodes.Add(b.xboxButton.ToString());
     }
     isTitle = (SceneManager.GetActiveScene().name == "Title") ? true : false;
     if (isTitle)
     {
         current = 1;
         panels[current].SetActive(true);
     }
     else
     {
         current = 0;
         panels[current].SetActive(true);
     }
 }
예제 #13
0
    /// <summary>
    /// Remaps/Updates the Keyboard Axis/Button dictionaries with a new key
    /// </summary>
    /// <param name="buttonKey"></param>
    /// <param name="key"></param>
    /// <param name="player"></param>
    public static void RemapKeyboardButton(PlayerButton button, KeyCode key, IInputPlayer player)
    {
        string buttonKey = button.ToString();

        if (player == null)
        {
            return;
        }
        else
        {
            if (keyboardAxisDictList[player.PlayerIndex + 1].ContainsKey(buttonKey))
            {
                keyboardAxisDictList[player.PlayerIndex + 1][buttonKey] = key;
            }
            else if (keyboardButtonDictList[player.PlayerIndex + 1].ContainsKey(buttonKey))
            {
                keyboardButtonDictList[player.PlayerIndex + 1][buttonKey] = key;
            }
            else
            {
                Debug.InputLog("No keyboard dictionary contains the key: " + buttonKey, Debug.LogType.Warning);
            }
        }
    }
예제 #14
0
 public void RemovePlayer(IInputPlayer player)
 {
     players.Remove(player);
 }
예제 #15
0
    /// <summary>
    /// Remaps/Updates the Xbox button dictionary with a new button
    /// </summary>
    /// <param name="buttonKey"></param>
    /// <param name="button"></param>
    /// <param name="player"></param>
    public static void RemapXboxButton(PlayerButton button, XboxController.XboxButton xButton, IInputPlayer player)
    {
        string buttonKey = button.ToString();

        // !!!NOTE!!! - Currently remapping xbox axis is not supported
        if (player == null)
        {
            return;
        }
        else
        {
            xboxButtonDictList[(int)player.PlayerIndex + 1][buttonKey] = xButton;
        }
    }
예제 #16
0
 void Start()
 {
     player        = GetComponent <IInputPlayer>();
     pMovement     = GetComponent <PlayerMovement>();
     originalSpeed = pMovement.speed;
 }