예제 #1
0
    public override void Update()
    {
        if (TouchUtility.Enabled && TouchUtility.TouchCount > 0)
        {
            Touch touch = TouchUtility.GetTouch(0);
            if (touch.phase == TouchPhase.Began && !TouchUtility.TouchedUI(touch.fingerId))
            {
                painter.Paint();
            }
        }

        targetTransform.Rotate(new Vector3(80f * Time.deltaTime, 0f, 0f));
    }
    void Update()
    {
        if (TouchUtility.Enabled && TouchUtility.TouchCount > 0)
        {
            Touch touch = TouchUtility.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                if (TouchUtility.TouchedUI(touch.fingerId))
                {
                    touched = false;
                    return;
                }

                Vector2 currentTouchPoint = mainCamera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, -mainCameraZPos));
                if ((currentTouchPoint.ToVector3() - transform.position).sqrMagnitude < dragRadius * dragRadius)
                {
                    touched            = true;
                    previousTouchPoint = currentTouchPoint;
                }
                else
                {
                    touched = false;
                }
            }

            if (touched == true && (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Ended))
            {
                Vector2 currentTouchPoint = mainCamera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, -mainCameraZPos));
                Vector2 delta             = (currentTouchPoint - previousTouchPoint).LimitLength(maxDragSpeed);

                if (delta.sqrMagnitude > 0f)
                {
                    Vector3 chiselPosition = transform.localPosition + delta.ToVector3();

                    if (chiselPosition.y > clampPositionY)
                    {
                        chiselPosition.y = clampPositionY;
                    }

                    transform.localPosition = chiselPosition;

                    previousTouchPoint = currentTouchPoint;
                }

                if (touch.phase == TouchPhase.Ended)
                {
                    touched = false;
                }
            }
        }
    }