Класс написан для того, чтобы дать возможность жестами двух пальцев, зумить ортографическую камеру. НА вроде Google Maps в мобилке. Без особого труда, класс можно перекрутить на обычную камеру.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using UnityEngine;
//Creating by Neodrop
//neodrop@unity3d.ru
[RequireComponent(typeof(Camera))]
public class Zoomer : MonoBehaviour
{
     public float stepPerSecond = 1f, orthoMin = 3f, orthoMax = 6f;
     float lastDistance = 0f;

    void FixedUpdate()
    {
        if (iPhoneInput.touchCount != 2)
        {
             lastDistance = 0;
             return;
        }

        if (iPhoneInput.touches[0].phase != iPhoneTouchPhase.Moved && iPhoneInput.touches[1].phase != iPhoneTouchPhase.Moved)
        {
           lastDistance = 0;
           return;
        }

        iPhoneTouch[] touch = iPhoneInput.touches;

        float distance = Vector2.Distance(touch[0].position, touch[1].position);

        if (distance == lastDistance) return;

       float touchDistance = (touch[1].position - touch[0].position).magnitude;
       float lastTouchDistance = ((touch[1].position - touch[1].deltaPosition) - (touch[0].position - touch[0].deltaPosition)).magnitude;
       float deltaPinch = touchDistance - lastTouchDistance;

      camera.orthographicSize += deltaPinch * stepPerSecond * Time.deltaTime;

      if (camera.orthographicSize < orthoMin) camera.orthographicSize = orthoMin;
      else if (camera.orthographicSize > orthoMax) camera.orthographicSize = orthoMax;

     lastDistance = distance;
    }
}
VN:F [1.9.3_1094]
Rating: 8.8/10 (5 votes cast)
VN:F [1.9.3_1094]
Rating: +4 (from 4 votes)
Zoom для ортографической камеры, 8.8 out of 10 based on 5 ratings

4 комментария на «Zoom для ортографической камеры»

  1. Armando

    lewisohn@dora.progandist” rel=”nofollow”>.…

    спс….

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  2. Alfonso

    icicle@multitudinous.corrosion” rel=”nofollow”>.…

    благодарю!…

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  3. arnold

    irons@augment.descendents” rel=”nofollow”>.…

    благодарен!…

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  4. roland

    affair@ximenez.infective” rel=”nofollow”>.…

    благодарен….

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)

Ваш отзыв

Вы должны войти, чтобы оставлять комментарии.



Страница 1 of 0