Beispiel #1
0
    void Awake()
    {
        gamepadInfo = new GamepadInfo
        {
            position   = Vector2.zero,
            touchState = TouchStates.Idle
        };

        lastTouchPosition = Vector2.zero;
    }
    private void SetStandaloneInputModule(GamepadInfo gi)
    {
        string h = GamepadInput.GetAxisName("Horizontal", gi.Type, gi.Id);

        _standaloneInputModule.horizontalAxis = h.Equals("") ? "Joystick" + gi.Id + "Axis1" : h;
        string v = GamepadInput.GetAxisName("Vertical", gi.Type, gi.Id);

        _standaloneInputModule.verticalAxis = v.Equals("") ? "Joystick" + gi.Id + "Axis2" : v;
        _standaloneInputModule.submitButton = GamepadInput.GetButtonForUI("Submit", gi.Type, gi.Id);
        _standaloneInputModule.cancelButton = GamepadInput.GetButtonForUI("Cancel", gi.Type, gi.Id);
    }
Beispiel #3
0
    private void UpdateForGamepadManager()
    {
        _state = GamepadManager.Instance.GetAssignedGamepad(0);

        if (!_state.IsConnected())
        {
            return;
        }

        float h = GamepadInput.GetAxis("Horizontal", _state.Type, _state.Id);
        float v = GamepadInput.GetAxis("Vertical", _state.Type, _state.Id);

        _player.SetMoveValue(h, v);

        if (GamepadInput.GetButtonDown("Fire1", _state.Type, _state.Id))
        {
            _player.SetRunValue(true);
        }

        if (GamepadInput.GetButtonUp("Fire1", _state.Type, _state.Id))
        {
            _player.SetRunValue(true);
        }

        switch (currentShootType)
        {
        case ShootType.WithButtons:


            if (GamepadInput.GetButtonDown("Fire4", _state.Type, _state.Id))
            {
                _player.InitShootAttack();
            }

            if (GamepadInput.GetButton("Fire4", _state.Type, _state.Id))
            {
                _player.UpdateShootAttack();
            }

            if (GamepadInput.GetButtonUp("Fire4", _state.Type, _state.Id))
            {
                _player.FinalizeShootAttack();
            }
            break;
        }
    }
Beispiel #4
0
    private void UpdateForGamepadManager()
    {
        _state = GamepadManager.Instance.GetAssignedGamepad(0);

        if (!_state.IsConnected())
        {
            return;
        }

        float ah = GamepadInput.GetAxis("AltHorizontal", _state.Type, _state.Id);
        float av = GamepadInput.GetAxis("AltVertical", _state.Type, _state.Id);

        _assist.SetMoveValue(ah, av);

        if (GamepadInput.GetButton("Fire5", _state.Type, _state.Id))
        {
            _assist.SetState(-1f);
        }

        if (GamepadInput.GetButton("Fire6", _state.Type, _state.Id))
        {
            _assist.SetState(1f);
        }

        float rt = GamepadInput.GetAxis("RightTrigger", _state.Type, _state.Id);

        if (rt > 0f && _prevRT == 0f)  // RT Down
        {
            _assist.SetHead(true);
        }
        _prevRT = rt;

        float lt = GamepadInput.GetAxis("LeftTrigger", _state.Type, _state.Id);

        if (lt > 0f && _prevLT == 0f)  // LT Down
        {
            _assist.SetHead(false);
        }
        _prevLT = lt;
    }
    private void UpdateForGamepadManager()
    {
        _state = GamepadManager.Instance.GetAssignedGamepad(0);

        if (!_state.IsConnected())
        {
            return;
        }

        float ah = GamepadInput.GetAxis("AltHorizontal", _state.Type, _state.Id);
        float av = GamepadInput.GetAxis("AltVertical", _state.Type, _state.Id);

        _assist.SetMoveValue(ah, av);

        if (GamepadInput.GetButton("Fire1", _state.Type, _state.Id))
        {
            _assist.SetState(AssistBehavior.AssistState.Shield);
        }

        if (GamepadInput.GetButton("Fire2", _state.Type, _state.Id))
        {
            _assist.SetState(AssistBehavior.AssistState.AutoFire);
        }

        if (GamepadInput.GetButton("Fire3", _state.Type, _state.Id))
        {
            _assist.SetState(AssistBehavior.AssistState.MultiplyFire);
        }

        if (GamepadInput.GetButton("Fire4", _state.Type, _state.Id))
        {
            _assist.SetState(AssistBehavior.AssistState.MultiplyVelocity);
        }

        _assist.AlignWithPlayer(GamepadInput.GetButton("Fire5", _state.Type, _state.Id));
    }
    protected override void OnEnable()
    {
        base.OnEnable();

        _eventTrigger.triggers.Clear();
        _eventTrigger.triggers.TrimExcess();

        foreach (EventTrigger.Entry entry in _entryOnCancel ?? Enumerable.Empty <EventTrigger.Entry>())
        {
            _eventTrigger.triggers.Add(entry);
        }

        for (int i = 0; i < nbJoystick; i++)
        {
            GamepadInfo padInfo = GamepadManager.Instance.GetAssignedGamepad(i);

            if ((int)padInfo.Player > 0 && (int)padInfo.Id > 0 && (int)padInfo.Type > 0)
            {
                joystickSlotsText[(int)padInfo.Player - 1].text   = "#" + padInfo.Id;
                joystickSlotsIcon[(int)padInfo.Player - 1].sprite = joystickIcons[(int)padInfo.Type - 1];
                joystickSlots[(int)padInfo.Player - 1].SetActive(true);
            }
        }
    }
    private void UpdateManagerState()
    {
        switch (_currentManagerState)
        {
        case GamepadManagerState.WaitForFirstJoystick:
            UpdateJoystickState();

            for (int i = 0; i < _detectedGamepads.Length; i++)
            {
                if (_detectedGamepads[i].Type != Gamepad.None && _detectedGamepads[i].Type != Gamepad.Unknown)
                {
                    bool pressL = GamepadInput.GetButton("Fire5", _detectedGamepads[i].Type, i + 1);
                    bool pressR = GamepadInput.GetButton("Fire6", _detectedGamepads[i].Type, i + 1);

                    string submit = GamepadInput.GetButtonForUI("Submit", _detectedGamepads[i].Type, i + 1);

                    if ((pressL && pressR) || Input.GetButtonDown(submit))
                    {
                        int emptySlot = GetNextJoystickEmptySlot();

                        if (emptySlot != -1)
                        {
                            _mainGamepad.Player = _assignedGamepads[emptySlot].Player = Player.One;
                            _mainGamepad.Id     = _assignedGamepads[emptySlot].Id = i + 1;
                            _mainGamepad.Type   = _assignedGamepads[emptySlot].Type = _detectedGamepads[i].Type;

                            _detectedGamepads[i].Selected = true;

                            SetStandaloneInputModule(_mainGamepad);

                            //Debug.Log("Joystick #" + _assignedGamepeds[0].Id);

                            whenWaitForFirstJoystickSuccess.Invoke();

                            _currentManagerState = GamepadManagerState.WaitForDisconnection;
                        }
                    }
                }
            }
            break;

        case GamepadManagerState.CheckForOneJoystick:
        case GamepadManagerState.CheckForTwoJoystick:
        case GamepadManagerState.CheckForThreeJoystick:
        case GamepadManagerState.CheckForFourJoystick:
            UpdateJoystickState();

            if (!GamepadAreConfigured((int)_currentManagerState - 1))
            {
                _currentPanel.SetOnSubmitActive(false);

                for (int i = 0; i < _detectedGamepads.Length; i++)
                {
                    if (_detectedGamepads[i].Type != Gamepad.None && _detectedGamepads[i].Type != Gamepad.Unknown && !_detectedGamepads[i].Selected)
                    {
                        bool pressL = GamepadInput.GetButton("Fire5", _detectedGamepads[i].Type, i + 1);
                        bool pressR = GamepadInput.GetButton("Fire6", _detectedGamepads[i].Type, i + 1);

                        if (pressL && pressR)
                        {
                            int emptySlotIndex = GetNextJoystickEmptySlot();

                            if (emptySlotIndex != -1)
                            {
                                _assignedGamepads[emptySlotIndex].Player = (Player)(emptySlotIndex + 1);
                                _assignedGamepads[emptySlotIndex].Id     = i + 1;
                                _assignedGamepads[emptySlotIndex].Type   = _detectedGamepads[i].Type;

                                _detectedGamepads[i].Selected = true;

                                if (emptySlotIndex == 0)
                                {
                                    _mainGamepad = _assignedGamepads[emptySlotIndex];
                                    SetStandaloneInputModule(_mainGamepad);
                                }

                                //Debug.Log("Joystick #" + _assignedGamepeds[emptySlotIndex].Id);

                                _currentPanel.AddJoystickSlot(emptySlotIndex, _assignedGamepads[emptySlotIndex]);
                            }
                        }
                    }
                }
            }
            else
            {
                _currentPanel.SetOnSubmitActive(true);
            }
            break;

        case GamepadManagerState.WaitForDisconnection:
            UpdateJoystickState();
            //TODO
            break;
        }
    }
Beispiel #8
0
 public abstract void NewInputs(GamepadInfo gamepadInfo);
Beispiel #9
0
        void xna_init_input()
        {
            int tot, i, j, k;
            string buf = "";

            for (i = 0; i < 4; i++)
            {
                joy[i] = new GamepadInfo();
            }
            tot = 0;

            /* first of all, map mouse buttons */
            //for (j = 0; j < 3; j++)
            //{
            //    buf = sprintf("MOUSE B%d", j + 1);
            //    joynames[tot] = buf;
            //    joylist[tot] = new JoystickInfo();
            //    joylist[tot].name = joynames[tot];
            //    joylist[tot].code = MOUSE_BUTTON(j + 1);
            //    tot++;
            //}

            for (i = 0; i < num_joysticks; i++)
            {
                for (j = 0; j < joy[i].num_sticks; j++)
                {
                    for (k = 0; k < joy[i].stick[j].num_axis; k++)
                    {
                        joylist[tot] = new JoystickInfo();
                        joynames[tot] = sprintf(buf, "J%d %s %s -", i + 1, joy[i].stick[j].name, joy[i].stick[j].axis[k].name);
                        joylist[tot].name = joynames[tot];
                        joylist[tot].code = (uint)JOYCODE(i + 1, j + 1, k + 1, 1);
                        tot++;

                        joylist[tot] = new JoystickInfo();

                        joynames[tot] = sprintf("J%d %s %s +", i + 1, joy[i].stick[j].name, joy[i].stick[j].axis[k].name);
                        joylist[tot].name = joynames[tot];
                        joylist[tot].code = (uint)JOYCODE(i + 1, j + 1, k + 1, 2);
                        tot++;
                    }
                }
                for (j = 0; j < joy[i].num_buttons; j++)
                {
                    joynames[tot] = sprintf(buf, "J%d %s", i + 1, joy[i].button[j].name);
                    joylist[tot] = new JoystickInfo();
                    joylist[tot].name = joynames[tot];
                    joylist[tot].code = (uint)JOYCODE(i + 1, 0, j + 1, 0);
                    tot++;
                }
            }
            joylist[tot] = new JoystickInfo();
            /* terminate array */
            joylist[tot].name = null;
            joylist[tot].code = 0;
            joylist[tot].standardcode = 0;

            /* fill in equivalences */
            for (i = 0; i < tot; i++)
            {
                joylist[i].standardcode = (uint)InputCodes.CODE_OTHER;

                j = 0;
                while (joyequiv[j][0] != 0)
                {
                    if (joyequiv[j][0] == joylist[i].code)
                    {
                        joylist[i].standardcode = (uint)joyequiv[j][1];
                        break;
                    }
                    j++;
                }
            }
        }
    private void UpdateForGamepadManager()
    {
        _state = GamepadManager.Instance.GetAssignedGamepad(0);

        if (!_state.IsConnected())
        {
            return;
        }

        float h = GamepadInput.GetAxis("Horizontal", _state.Type, _state.Id);
        float v = GamepadInput.GetAxis("Vertical", _state.Type, _state.Id);

        _player.SetMoveValue(h, v);

        float lt = GamepadInput.GetAxis("LeftTrigger", _state.Type, _state.Id);

        if (lt > 0f && _prevLT == 0f)  // LT Down
        {
            _player.SetRunValue(true);
        }
        else if (lt == 0f && _prevLT > 0f) // LT Up
        {
            _player.SetRunValue(false);
        }
        _prevLT = lt;

        switch (currentShootType)
        {
        case ShootType.WithTriggers:
            float rt = GamepadInput.GetAxis("RightTrigger", _state.Type, _state.Id);
            if (rt > 0f && _prevRT == 0f)      // RT Down
            {
                _player.InstantShootAttack();
            }
            else if (rt > 0f && _prevRT > 0f)     // RT Stay
            {
                _player.InstantShootAttack();
            }
            _prevRT = rt;

            if (GamepadInput.GetButtonDown("Fire6", _state.Type, _state.Id))
            {
                _player.InitShootAttack();
            }

            if (GamepadInput.GetButton("Fire6", _state.Type, _state.Id))
            {
                _player.UpdateShootAttack();
            }

            if (GamepadInput.GetButtonUp("Fire6", _state.Type, _state.Id))
            {
                _player.FinalizeShootAttack();
            }
            break;

        case ShootType.WithStick:
            float ah = GamepadInput.GetAxis("AltHorizontal", _state.Type, _state.Id);
            float av = GamepadInput.GetAxis("AltVertical", _state.Type, _state.Id);
            _player.InstantShootAttack(ah, av);
            break;
        }
    }
Beispiel #11
0
 public override void NewInputs(GamepadInfo gamepadInfo)
 {
     Jump(gamepadInfo.swipeDirection);
     Move(gamepadInfo.swipeDirection);
     Spin(gamepadInfo.swipeDirection);
 }
 public void AddJoystickSlot(int slot, GamepadInfo joyInfo)
 {
     joystickSlotsText[slot].text   = "#" + joyInfo.Id;
     joystickSlotsIcon[slot].sprite = joystickIcons[((int)joyInfo.Type) - 1];
     joystickSlots[slot].SetActive(true);
 }
Beispiel #13
0
 void Awake()
 {
     gamepadInfo = new GamepadInfo();
     gamepadInfo.swipeDirection = Vector2.zero;
 }