Exemplo n.º 1
0
        public void ReceiveInputFloat(float f, BA_InputType type)
        {
            if (!IsInputValid(type))
            {
                return;
            }

            if (type == BA_InputType.GAMEPAD_AXIS_LEFT_X)
            {
                _gamepadLeft.x = f;
            }
            else if (type == BA_InputType.GAMEPAD_AXIS_LEFT_Y)
            {
                _gamepadLeft.y = f;
            }
            else if (type == BA_InputType.GAMEPAD_AXIS_RIGHT_X)
            {
                _gamepadRight.x = f;
            }
            else if (type == BA_InputType.GAMEPAD_AXIS_RIGHT_Y)
            {
                _gamepadRight.y = f;
            }

            MoveInputVector2(_gamepadLeft);
            if (_gamepadRight != Vector2.zero)
            {
                gamepadToScreenPoint_xLOCAL = (Screen.width / 2) + Screen.width * _gamepadRight.x;
                gamepadToScreenPoint_yLOCAL = (Screen.height / 2) + Screen.height * _gamepadRight.y;

                DirectionalInputRightStick(new Vector2(gamepadToScreenPoint_xLOCAL, gamepadToScreenPoint_yLOCAL));
            }
        }
Exemplo n.º 2
0
        public void ReceiveInputSwipe(Vector2 start, Vector2 end, BA_InputType type)
        {
            if (!IsInputValid(type))
            {
                return;
            }

            //Dirty QuickFix: Get PlayerPosToScreenPoint for directions origin
            if (type == BA_InputType.TOUCH_0_SWIPE)
            {
                Vector2 direction = (end - start);/*.normalized*/
                //Debug.Log("start: " + start + " |   end: " + end + " |  direction not normalized: " + (end - start));
                //Vector2 mappedDirection = new Vector2(Screen.width / 2f + (Screen.width/2) * direction.x, Screen.height / 2f + (Screen.height/2) * direction.y);

                pPos = Camera.main.WorldToScreenPoint(DataPipe.instance.PlayerReferences.transform.position);

                mappedDirection = new Vector2((pPos.x) + direction.x, (pPos.y) + direction.y);

                //Debug.Log("direction: " + direction + " | mappedDirectionToPosition: " + mappedDirection);

                //Debug.Log("screenRay: " + direction.normalized);

                //GameObject.FindGameObjectWithTag("DebugUI2").GetComponent<RectTransform>().position = end;
                //GameObject.FindGameObjectWithTag("DebugUI").GetComponent<RectTransform>().position = mappedDirection;

                ActionKey_2.Invoke(mappedDirection);
            }
        }
Exemplo n.º 3
0
        public void ReceiveInputVector2(Vector2 vec, BA_InputType type)
        {
            if (!IsInputValid(type))
            {
                return;
            }

            _pointerPosition = vec;

            DirectionalInputMousePos?.Invoke(_pointerPosition);
        }
Exemplo n.º 4
0
        public void ReceiveInputTouch(Touch t, BA_InputType type)
        {
            if (!IsInputValid(type))
            {
                return;
            }

            _pointerPosition = t.position;
            _currentFingerID = t.fingerId;

            //Debug.Log("fingerID" + t.fingerId);
        }
Exemplo n.º 5
0
        private bool IsInputValid(BA_InputType type)
        {
            foreach (var context in _activeContexts)
            {
                foreach (var validType in context.AllowedInputs)
                {
                    if (validType == type)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        public void ReceiveInput(BA_InputType type)
        {
            if (!IsInputValid(type))
            {
                return;
            }

            if (type == BA_InputType.MOUSE_0_DOWN)
            {
                //float timeT = Time.time;

                int pointerID = -1;

                _ped = _inputModule.GetLastPointerEventDataCustom(pointerID);

                if (_ped == null)
                {
                    Debug.Log("ped is null in " + type + " ==  " + pointerID);
                }

                _raycastResults.Clear();

                _gRaycaster.Raycast(_ped, _raycastResults);

                //Debug.Log("raycast:" + (Time.time - timeT));

                //Debug.Log("raycast end:" + Time.time);

                //Move
                if (_raycastResults.Count == 0)
                {
                    MoveInputVector3(_pointerPosition);
                }
                //Delegate to UI Input Receiver
                else
                {
                    MouseInputUI(_ped);
                }
            }
            else if (type == BA_InputType.GAMEPAD_0_DOWN || type == BA_InputType.KEYBOARD_0_DOWN)
            {
                ActionKey?.Invoke();
            }
            else if (type == BA_InputType.GAMEPAD_1_DOWN)
            {
                float gamepadToScreenPoint_x = (Screen.width / 2) + Screen.width * _gamepadRight.x;
                float gamepadToScreenPoint_y = (Screen.height / 2) + Screen.height * _gamepadRight.y;

                ActionKey_2?.Invoke(new Vector2(gamepadToScreenPoint_x, gamepadToScreenPoint_y));
            }
            else if (type == BA_InputType.KEYBOARD_1_DOWN)
            {
                ActionKey_2?.Invoke(_pointerPosition);
            }
            else if (type == BA_InputType.TOUCH_0_UP)
            {
                _ped          = new PointerEventData(EventSystem.current);
                _ped.position = _pointerPosition;
                //_ped = _inputModule.GetLastPointerEventDataCustom(_currentFingerID);

                if (_ped == null)
                {
                    Debug.Log("ped is null in touch up");
                    Debug.Log("fingerID: " + _currentFingerID);
                }

                _raycastResults.Clear();

                _gRaycaster.Raycast(_ped, _raycastResults);

                foreach (var result in _raycastResults)
                {
                    if (result.gameObject.GetComponent <BA_BaseUIElement>() != null)
                    {
                        _ped.pointerEnter = result.gameObject;
                    }
                }

                if (_raycastResults.Count == 0)
                {
                    MoveInputVector3(_pointerPosition);
                }
                else
                {
                    TouchInputUI(_ped);
                }
            }
        }