Exemple #1
0
 void Update()
 {
     if (JoystickValue != null)
     {
         if (horizontalAxisEnabled || verticalAxisEnabled)
         {
             JoystickValue.Invoke(joystickValue);
         }
     }
     if (OnJoystickDown != null)
     {
         if (horizontalAxisEnabled || verticalAxisEnabled)
         {
             if (joystickValue.sqrMagnitude > .1f)
             {
                 OnJoystickDown.Invoke();
             }
         }
     }
     if (OnJoystickUp != null)
     {
         if (horizontalAxisEnabled || verticalAxisEnabled)
         {
             if (joystickValue.sqrMagnitude <= .1f)
             {
                 OnJoystickUp.Invoke();
             }
         }
     }
 }
Exemple #2
0
 protected virtual void Update()
 {
     if (JoystickValue != null)
     {
         JoystickValue.Invoke(joystickValue);
     }
     return;
 }
Exemple #3
0
 void Update()
 {
     if (IsDraging) //摇杆拖拽进行时驱动事件
     {
         joysticValue.x = handle.anchoredPosition.x / maxRadius;
         joysticValue.y = handle.anchoredPosition.y / maxRadius;
         OnValueChanged.Invoke(joysticValue);
     }
 }
 /// <summary>
 /// On Update we check for an orientation change if needed, and send our input values.
 /// </summary>
 protected virtual void Update()
 {
     if (JoystickValue != null)
     {
         if (HorizontalAxisEnabled || VerticalAxisEnabled)
         {
             JoystickValue.Invoke(_joystickValue);
         }
     }
 }
Exemple #5
0
 void Update()
 {
     if (!IsDraging)
     {
         return;            // 仅当摇杆拖拽时驱动事件
     }
     joystickValue.x = handle.anchoredPosition.x / maxRadius;
     joystickValue.y = handle.anchoredPosition.y / maxRadius;
     OnValueChanged.Invoke(joystickValue);// 1.发送事件
 }
        internal bool PerformJoystickEvent(Viewport viewport, JoystickInputEvent e)
        {
            var handled = OnJoystickEvent(viewport, e);

            if (!handled)
            {
                JoystickEvent?.Invoke(this, viewport, e, ref handled);
            }
            return(handled);
        }
Exemple #7
0
        public override void OnPointerUp(PointerEventData eventData)
        {
            if (FingerId != eventData.pointerId)
            {
                return;
            }

            ResetJoystick();
            mReleaseEvent.Invoke(eventData.position);
            EnumEventDispatcher.TriggerEvent(EnumEventType.JoystickRelease, eventData.position);
        }
Exemple #8
0
 void Update()
 {
     if (joystickInput != null)
     {
         joystickInput.Invoke(joystickValue);
         return;
     }
     else
     {
         return;
     }
 }
Exemple #9
0
 public override void OnPointerDown(PointerEventData eventData)
 {
     if (eventData.pointerId < -1 || IsDraging)
     {
         return;
     }
     IsDraging      = true;
     FingerId       = eventData.pointerId;
     InitializedPos = eventData.position;
     mPressEvent.Invoke(eventData.position);
     EnumEventDispatcher.TriggerEvent(EnumEventType.JoystickPress, eventData.position);
 }
Exemple #10
0
    public void OnDrag(PointerEventData eventData)
    {
        cam = null;
        if (canvas.renderMode == RenderMode.ScreenSpaceCamera)
        {
            cam = canvas.worldCamera;
        }

        Vector2 position = RectTransformUtility.WorldToScreenPoint(cam, background.position);
        Vector2 radius   = background.sizeDelta / 2;

        input = (eventData.position - position) / (radius * canvas.scaleFactor);
        FormatInput();
        HandleInput(input.magnitude, input.normalized, radius, cam);
        handle.anchoredPosition = input * radius * handleRange;
        onDrag.Invoke(Direction);
    }
Exemple #11
0
        void TouchControl()
        {
            //Finding current touch by fingerId
            if (clicked)
            {
                for (int i = 0; i < Input.touchCount; i++)
                {
                    if (Input.GetTouch(i).fingerId == fingerId)
                    {
                        touch = Input.GetTouch(i);
                        break;
                    }
                }
            }

            //Get fingerId from suitable touch
            for (int i = 0; i < Input.touchCount && !clicked; i++)
            {
                if (Input.GetTouch(i).phase == TouchPhase.Began)
                {
                    Vector2 touchWorldPos = cam.ScreenToWorldPoint(Input.GetTouch(i).position);
                    if (Vector2.Distance(touchWorldPos, (Vector2)transform.position) < touchZoneSize)
                    {
                        touch          = Input.GetTouch(i);
                        fingerId       = touch.fingerId;
                        stick.position = touchWorldPos;
                        if (stick.localPosition.magnitude > radius)
                        {
                            stick.localPosition = stick.localPosition.normalized * radius;
                        }

                        stickPrevPos = stick.localPosition;

                        clicked = true;
                    }
                }
            }

            if (clicked)
            {
                stick.position = (Vector2)cam.ScreenToWorldPoint(touch.position);
                if (stick.localPosition.magnitude > radius)
                {
                    stick.localPosition = stick.localPosition.normalized * radius;
                }

                Vector2 delta = (Vector2)stick.localPosition - stickPrevPos;
                stickPrevPos = stick.localPosition;

                if (touch.phase == TouchPhase.Ended)
                {
                    stick.localPosition = Vector3.zero;
                }

                onClick.Invoke(new JoystickInfo(stick.localPosition / radius, delta / radius));
            }

            if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
            {
                stick.localPosition = Vector3.zero;
                clicked             = false;
            }
        }
Exemple #12
0
 private void Update()
 {
     mValueChanged.Invoke(InnerTransform.localPosition / MaxRadius);
 }
Exemple #13
0
 public virtual void OnPointerDown(PointerEventData eventData)
 {
     OnDrag(eventData);
     onPointerDown.Invoke(Direction);
 }
Exemple #14
0
 protected virtual void Update()
 {
     onTick.Invoke(Direction);
 }
Exemple #15
0
 public virtual void OnPointerUp(PointerEventData eventData)
 {
     input = Vector2.zero;
     handle.anchoredPosition = Vector2.zero;
     onPointerUp.Invoke(Direction);
 }