示例#1
0
    void SetPlayerControlls()
    {
        if (_State == GameLogicStatics.GameStates.FirstStart)
        {
            return;
        }

        foreach (InputDevice device in InputManager.Devices)
        {
            if (device.AnyButtonWasPressed)
            {
                bool deviceInUse = false;

                //check if device is already in use
                foreach (IPlayerInput playerInput in playerInputs)
                {
                    if (playerInput.GetControlls() != null && playerInput.GetControlls().GetDevice() == device)
                    {
                        deviceInUse = true;
                        break;
                    }
                }

                if (deviceInUse)
                {
                    continue;
                }

                //set device for player if free
                foreach (IPlayerInput playerInput in playerInputs)
                {
                    if (playerInput.GetControlls() == null)
                    {
                        ICharacterControlls cc = new CharacterControlls();
                        cc.SetController(device);

                        playerInput.SetControlls(cc);

                        if (_State == GameLogicStatics.GameStates.WaitForPlayers)
                        {
                            spawner.AwakePlayer(playerInput.GetGameObject());
                        }
                    }
                }
            }
        }


        foreach (KeyboardControlls kc in keyboardControlls)
        {
            if (Input.GetKeyDown(kc.Cast))
            {
                bool deviceInUse = false;

                foreach (IPlayerInput playerInput in playerInputs)
                {
                    if (playerInput.GetControlls() != null && playerInput.GetControlls().GetKeyboardControlls() == kc)
                    {
                        deviceInUse = true;
                        break;
                    }
                }

                if (deviceInUse)
                {
                    continue;
                }

                foreach (IPlayerInput playerInput in playerInputs)
                {
                    if (playerInput.GetControlls() == null)
                    {
                        ICharacterControlls cc = new CharacterControlls();
                        cc.SetMouseKeyboard(kc);

                        playerInput.SetControlls(cc);

                        if (_State == GameLogicStatics.GameStates.WaitForPlayers || _State == GameLogicStatics.GameStates.ReadyToStart)
                        {
                            spawner.AwakePlayer(playerInput.GetGameObject());
                        }

                        break;
                    }
                }
            }
        }
    }