Exemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (DeviceInputManager.GetMouseButton(0) || DeviceInputManager.GetMouseButton(1))
     {
         SyncParam();
     }
 }
Exemplo n.º 2
0
    private void LateUpdate()
    {
        if (Input.GetKeyDown(KeyCode.D))
        {
            debug = !debug;
            DeviceInputManager.Instance.debug = debug;
        }

        if (camTrans == null)
        {
            return;
        }

        //
        panDistance = Vector3.zero;

        MultiTouchUpdate();

        zoomDistance += DeviceInputManager.GetAxis("Mouse ScrollWheel") * zoomSensitivity;
        zoomDistance  = Mathf.Clamp(zoomDistance, zoomMinLimit, zoomMaxLimit);

        if (camTrans && DeviceInputManager.GetMouseButton(0) && DeviceInputManager.touchCount == 1)
        {
            // left mouse orbit
            x += (float)(DeviceInputManager.GetAxis("Mouse X") * xSpeed * 0.02);
            y -= (float)(DeviceInputManager.GetAxis("Mouse Y") * ySpeed * 0.02);

            y = ClampAngle(y, yMinLimit, yMaxLimit);
        }

        if (camTrans && DeviceInputManager.GetMouseButton(1))
        {
            // right mouse Pan
            panDistance = DeviceInputManager.GetTouch(0).deltaPosition * -0.01f;
        }
        this.transform.position += this.transform.rotation * new Vector3(panDistance.x, panDistance.y, 0);

        Vector3 position = new Vector3(0.0f, 0.0f, -zoomDistance);

        camTrans.localPosition = position;

        Quaternion rotation = Quaternion.Euler(y, x, 0);

//		this.transform.rotation = rotation;
        this.transform.rotation = initRot * rotation;
    }
Exemplo n.º 3
0
    //TODO: リファクタリング
    void MultiTouchUpdate()
    {
        if (DeviceInputManager.touchCount >= 2)
        {
            TouchObject touch1 = DeviceInputManager.GetTouch(0);
            TouchObject touch2 = DeviceInputManager.GetTouch(1);

            if (!isStartTowFinger)
            {
                // Start Two Finger;
                isStartTowFinger = true;

                zoomDeltaList.Clear();
                centerDeltaList.Clear();

                preCenter = (touch1.position + touch2.position) / 2.0f;
            }

            // Find out how the touches have moved relative to eachother:
            Vector2 curDist  = touch1.position - touch2.position;
            Vector2 prevDist = (touch1.position - touch1.deltaPosition) - (touch2.position - touch2.deltaPosition);

            Vector2 center      = (touch1.position + touch2.position) / 2.0f;
            Vector2 centerDelta = center - preCenter;
            preCenter = center;

            float   zoomDelta = (curDist.magnitude - prevDist.magnitude) * 0.01f;
            Vector2 panDelta  = (curDist - prevDist) * 0.01f;

            // avg
            zoomDeltaList.Add(Mathf.Abs(zoomDelta));
            if (zoomDeltaList.Count > avgBufferNum)
            {
                zoomDeltaList.RemoveAt(0);
            }

            float avgZoomDelta = 0;
            for (int i = 0; i < zoomDeltaList.Count; i++)
            {
                avgZoomDelta += zoomDeltaList [i];
            }
            avgZoomDelta /= zoomDeltaList.Count;
            //
            centerDeltaList.Add(Mathf.Abs(centerDelta.magnitude));
            if (centerDeltaList.Count > avgBufferNum)
            {
                centerDeltaList.RemoveAt(0);
            }

            float avgCenterDelta = 0;
            for (int i = 0; i < centerDeltaList.Count; i++)
            {
                avgCenterDelta += centerDeltaList [i];
            }
            avgCenterDelta /= centerDeltaList.Count;
            //

            if (avgZoomDelta > 0.05f)
            {
                zoomDistance += zoomDelta;
            }
            if (avgCenterDelta > 2.0f)
            {
                panDistance += -centerDelta * 0.01f;
            }
        }
        else
        {
            isStartTowFinger = false;
        }
    }