forked from TouchScript/TouchScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraController.cs
More file actions
54 lines (46 loc) · 1.79 KB
/
CameraController.cs
File metadata and controls
54 lines (46 loc) · 1.79 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* @author Valentin Simonov / http://va.lent.in/
*/
using UnityEngine;
using TouchScript.Gestures.TransformGestures;
namespace TouchScript.Examples.CameraControl
{
/// <exclude />
public class CameraController : MonoBehaviour
{
public ScreenTransformGesture TwoFingerMoveGesture;
public ScreenTransformGesture ManipulationGesture;
public float PanSpeed = 200f;
public float RotationSpeed = 200f;
public float ZoomSpeed = 10f;
private Transform pivot;
private Transform cam;
private void Awake()
{
pivot = transform.Find("Pivot");
cam = transform.Find("Pivot/Camera");
}
private void OnEnable()
{
TwoFingerMoveGesture.Transformed += twoFingerTransformHandler;
ManipulationGesture.Transformed += manipulationTransformedHandler;
}
private void OnDisable()
{
TwoFingerMoveGesture.Transformed -= twoFingerTransformHandler;
ManipulationGesture.Transformed -= manipulationTransformedHandler;
}
private void manipulationTransformedHandler(object sender, System.EventArgs e)
{
var rotation = Quaternion.Euler(ManipulationGesture.DeltaPosition.y / Screen.height * RotationSpeed,
-ManipulationGesture.DeltaPosition.x / Screen.width * RotationSpeed,
ManipulationGesture.DeltaRotation);
pivot.localRotation *= rotation;
cam.transform.localPosition += Vector3.forward * (ManipulationGesture.DeltaScale - 1f) * ZoomSpeed;
}
private void twoFingerTransformHandler(object sender, System.EventArgs e)
{
pivot.localPosition += pivot.rotation * TwoFingerMoveGesture.DeltaPosition * PanSpeed;
}
}
}