Exemplo n.º 1
0
    public void OnBeginDrag(PointerEventData eventData)
    {
        /*1.OnBeginDrag converts the touch position to a local Vector2 using the
         *   RectTransformUtility.ScreenPointToLocalPointInRectangle method.
         * 2.If the magnitude of the calculated vector is less than the radius variable, then the
         *   vector is reset so that it’s between a value of 0 and 1.isHeld is set true, then this
         *  statement updates the d-pad sprite and invokes the OnValueChange event.*/

        if (!IsActive())
        {
            return;
        }

        RectTransform thisRect = transform as RectTransform;
        Vector2       touchDir;
        bool          didConvert =
            RectTransformUtility.ScreenPointToLocalPointInRectangle(thisRect, eventData.position,
                                                                    eventData.enterEventCamera, out touchDir);

        if (touchDir.sqrMagnitude > radius * radius)
        {
            touchDir.Normalize();
            isHeld = true;
            ActionPadDirection currentDirection = UpdateTouchSprite(touchDir);
            OnValueChange.Invoke(currentDirection);
        }
    }
Exemplo n.º 2
0
        public void SetAxis(Vector2 axis)
        {
            _DisplayAxis = axis;

            float fMagnitude = _DisplayAxis.magnitude;

            if (fMagnitude > 1f)
            {
                _DisplayAxis = _DisplayAxis / fMagnitude;
            }

            if (fMagnitude > _DeadZone)
            {
                _InputAxis  = _DisplayAxis;
                _InputAxis *= _OutputCurve.Evaluate(fMagnitude);
            }
            else
            {
                _InputAxis = Vector2.zero;
            }

            if (!_DontCallEvent && OnValueChange != null)
            {
                OnValueChange.Invoke(_InputAxis);
            }

            UpdateJoystickGraphic();
        }
Exemplo n.º 3
0
    public void OnBeginDrag(PointerEventData eventData)
    {
        if (!IsActive())
        {
            return;
        }

        RectTransform thisRect = transform as RectTransform;
        Vector2       touchDir;
        bool          didConvert = RectTransformUtility.ScreenPointToLocalPointInRectangle(thisRect, eventData.position, eventData.enterEventCamera, out touchDir);

        if (touchDir.sqrMagnitude > radius * radius)
        {
            touchDir.Normalize();
            isHeld = true;
            ActionPadDirection currentDirection = UpdateTouchSprite(touchDir);
            OnValueChange.Invoke(currentDirection);
        }
    }
Exemplo n.º 4
0
        private void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                startPosition = RaycastUtils.raycastPositionWith(cam, y: 1);
            }

            if (Input.GetMouseButton(0))
            {
                Vector3?position = RaycastUtils.raycastPositionWith(cam, y: 1);
                if (position.HasValue)
                {
                    onJoystickMove.Invoke(position.Value);
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                startPosition = null;
                onFingerReleased.Invoke();
            }
        }
Exemplo n.º 5
0
 public static void InvokeJoystickMove(bool move)
 {
     JoystickMoveEvent.Invoke(move);
 }