コード例 #1
0
    /// <summary>
    ///
    /// </summary>
    void Update()
    {
        DeathArea = CenterReference.position;
        //If this not free (not touched) then not need continue
        if (!isFree)
        {
            Vector3 position = JoystickUtils.TouchPosition(m_Canvas, GetTouchID);
            if (position != lastPosition)
            {
                if (Vector2.Distance(DeathArea, position) < radio)
                {
                    StickRect.position = position;
                }
                else
                {
                    StickRect.position = DeathArea + (position - DeathArea).normalized * radio;
                }
            }
        }

        if (isFree)
        {
            //Return to default position with a smooth movement
            StickRect.position = Vector3.SmoothDamp(StickRect.position, DeathArea, ref currentVelocity, smoothTime);
            //When is in default position, we not need continue update this
            if (Vector3.Distance(StickRect.position, DeathArea) < .1f)
            {
                StickRect.position = DeathArea;
                isFree             = false;
            }
        }
    }
コード例 #2
0
    public void OnDrag(PointerEventData data)
    {
        //If this touch id is the first touch in the event
        if (data.pointerId == lastId)
        {
            isFree = false;
            //Get Position of current touch
            Vector3 position = JoystickUtils.TouchPosition(m_Canvas, GetTouchID);

            //Rotate into the area circumferential of joystick
            if (Vector2.Distance(DeathArea, position) < radio)
            {
                StickRect.position = position;
            }
            else
            {
                StickRect.position = DeathArea + (position - DeathArea).normalized * radio;
            }
            OnEndDrag(data);
        }
    }