public TDS_PlayerInfo(int _id, TDS_Controller _controller, PhotonPlayer _photonPlayer, PlayerType _type = PlayerType.Unknown)
 {
     PlayerID     = _id;
     PlayerType   = _type;
     Controller   = _controller;
     PhotonPlayer = _photonPlayer;
 }
Example #2
0
    /// <summary>
    /// Subscribes a controller for axis update to this Input Manager.
    /// </summary>
    /// <param name="_controller">Controller to subscribe.</param>
    public void SubscribeController(TDS_Controller _controller)
    {
        foreach (TDS_AxisToInput _axis in _controller.Axis)
        {
            OnUpdate += _axis.UpdateState;
        }

        foreach (TDS_Button _button in _controller.Buttons)
        {
            if (!string.IsNullOrEmpty(_button.Axis.AxisName) && (_button.Axis.AxisName != "Unknown Axis"))
            {
                OnUpdate += _button.Axis.UpdateState;
            }
        }
    }
    public static void CreateController()
    {
        TDS_InputSO _inputs = Resources.Load <TDS_InputSO>(INPUT_ASSET_PATH);

        if (!_inputs)
        {
            CreateInputAsset();
            _inputs = Resources.Load <TDS_InputSO>(INPUT_ASSET_PATH);
        }

        TDS_Controller[] _newControllers = new TDS_Controller[_inputs.Controllers.Length + 1];

        for (int _i = 0; _i < _newControllers.Length - 1; _i++)
        {
            _newControllers[_i] = _inputs.Controllers[_i];
        }

        _newControllers[_newControllers.Length - 1] = new TDS_Controller();
        _inputs.Controllers = _newControllers;
    }
    /// <summary>
    /// Check the inputs and call the methods used during the various states of the menu
    /// </summary>
    /// <param name="_state">State of the menu</param>
    /// <returns></returns>
    private IEnumerator CheckInputMenu(UIState _state)
    {
        if (_state == UIState.InMainMenu || _state == UIState.InGameOver)
        {
            yield break;
        }
        //Online
        Action       _cancelAction         = null;
        Action       _submitAction         = null;
        Action <int> _horizontalAxisAction = null;
        Action       _startAction          = null;
        //Local
        Action <int>      _cancelActionByPlayer         = null;
        Action <int>      _submitActionByPlayer         = null;
        Action <int, int> _horizontalAxisActionByPlayer = null;

        switch (_state)
        {
        case UIState.InRoomSelection:
            _cancelAction += () => ActivateMenu(UIState.InMainMenu);;
            _cancelAction += TDS_NetworkManager.Instance.InitDisconect;
            break;

        case UIState.InCharacterSelection:
            if (!characterSelectionManager)
            {
                break;
            }
            if (!PhotonNetwork.offlineMode)
            {
                _cancelAction = characterSelectionManager.CancelInOnlineCharacterSelection;
                _submitAction = characterSelectionManager.SubmitInOnlineCharacterSelection;
                while (characterSelectionManager.CharacterSelectionMenu.LocalElement == null)
                {
                    yield return(null);
                }
                _horizontalAxisAction = characterSelectionManager.CharacterSelectionMenu.LocalElement.ChangeImage;
                break;
            }
            _submitActionByPlayer         = characterSelectionManager.SubmitInLocalCharacterSelection;
            _cancelActionByPlayer         = characterSelectionManager.CancelInLocalCharacterSelection;
            _horizontalAxisActionByPlayer = characterSelectionManager.ChangeImageAtPlayer;
            break;

        case UIState.InGame:
            yield break;
            yield return(new WaitForEndOfFrame());

            _startAction = () => SetPause(true);
            break;

        case UIState.InPause:
            yield return(new WaitForEndOfFrame());

            _cancelAction = () => SetPause(false);
            break;

        default:
            break;
        }
        int _value = 0;

        if (_state == UIState.InGame)
        {
            while (UIState == _state)
            {
                if (TDS_GameManager.InputsAsset.Controllers[0].GetButtonDown(ButtonType.Pause))
                {
                    yield return(new WaitForEndOfFrame());

                    _startAction?.Invoke();
                    yield break;
                }
                yield return(null);
            }
            yield break;
        }
        if (_state == UIState.InPause)
        {
            while (UIState == _state)
            {
                if (TDS_GameManager.InputsAsset.Controllers[0].GetButtonDown(ButtonType.Pause) || TDS_GameManager.InputsAsset.Controllers[0].GetButtonDown(ButtonType.Cancel))
                {
                    yield return(new WaitForEndOfFrame());

                    _cancelAction?.Invoke();
                    yield break;
                }
                yield return(null);
            }
            yield break;
        }
        if (!PhotonNetwork.offlineMode)
        {
            while (UIState == _state)
            {
                if (TDS_GameManager.InputsAsset.Controllers[0].GetButtonDown(ButtonType.Cancel))
                {
                    yield return(new WaitForEndOfFrame());

                    _cancelAction?.Invoke();
                }
                else if (TDS_GameManager.InputsAsset.Controllers[0].GetButtonDown(ButtonType.Confirm))
                {
                    yield return(new WaitForEndOfFrame());

                    _submitAction?.Invoke();
                }
                else if (TDS_GameManager.InputsAsset.Controllers[0].GetAxisDown(AxisType.Horizontal, out _value))
                {
                    Debug.Log(_value);
                    _horizontalAxisAction?.Invoke(_value);
                }
                else if (TDS_GameManager.InputsAsset.Controllers[0].GetButtonDown(ButtonType.Pause))
                {
                    yield return(new WaitForEndOfFrame());

                    _startAction?.Invoke();
                }
                yield return(null);
            }
            yield break;
        }
        TDS_Controller _controller = null;

        while (UIState == _state)
        {
            for (int _i = 1; _i < TDS_GameManager.InputsAsset.Controllers.Length; _i++)
            {
                _controller = TDS_GameManager.InputsAsset.Controllers[_i];
                if (_controller.GetButtonDown(ButtonType.Cancel))
                {
                    _cancelActionByPlayer?.Invoke(_i);
                    continue;
                }
                else if (_controller.GetButtonDown(ButtonType.Confirm))
                {
                    _submitActionByPlayer?.Invoke(_i);
                    continue;
                }
                else if (_controller.GetAxisDown(AxisType.Horizontal, out _value))
                {
                    _horizontalAxisActionByPlayer?.Invoke(_i, _value);
                    continue;
                }
            }
            yield return(null);
        }
    }