コード例 #1
0
    public void OnDrag(PointerEventData eventData)
    {
        if (Input.touchCount == 2)
        {
            Vector2 currentMousePositionOne = Input.GetTouch(0).position;
            Vector2 currentMousePositionTwo = Input.GetTouch(1).position;

            Vector2 lastPointOneFromCenter = lastMousePositionOneTouch - screenCenter;
            Vector2 lastPointTwoFromCenter = lastMousePositionTwoTouch - screenCenter;

            Vector2 currPointOneFromLastPoint = currentMousePositionOne - lastMousePositionOneTouch;
            Vector2 currPointTwoFromLastPoint = currentMousePositionTwo - lastMousePositionTwoTouch;

            float amount = Vector2.Dot(lastPointOneFromCenter, currPointOneFromLastPoint) + Vector2.Dot(lastPointTwoFromCenter, currPointTwoFromLastPoint);

            Debug.Log(amount);
            if (Mathf.Abs(amount) > 10000f)
            {
                camWork.CloseUp((-1f) * amount / 1000000f);
                lastMousePositionOneTouch = Input.GetTouch(0).position;
                lastMousePositionTwoTouch = Input.GetTouch(1).position;
            }
        }

        else if (Input.touchCount == 1)
        {
            Vector2 currentMousePositionOne = Input.GetTouch(0).position;
            Vector2 currPointFromLastPoint  = currentMousePositionOne - lastMousePositionOneTouch;

            float h = currPointFromLastPoint.x;
            float v = currPointFromLastPoint.y;

            camWork.RotateCamera(h / 100f, v / 100f);

            lastMousePositionOneTouch = Input.GetTouch(0).position;
        }
    }