我这里使用了 EasyTouch插件
实例代码:
using UnityEngine;
using System;
using System.Collections;
using HedgehogTeam.EasyTouch;
public class CameraController : MonoBehaviour
{
public bool isRotate = true;
//摄像机的距离
public float fieldOfView;
//用来改变摄像机的距离
public float frameIndex = 60;
//是否可以 双指缩放摄像机
public bool isPinchCamera = true;
// Text m_debugTip;
public bool canRotation_X = true;
public bool canRotation_Y = true;
public bool canScale = true;
#region Field and Property
/// <summary>
/// Around center.
/// </summary>
//public Transform target;
/// <summary>
/// Settings of mouse button, pointer and scrollwheel.
/// </summary>
public MouseSettings mouseSettings = new MouseSettings(0, 10, 10);
/// <summary>
/// Range limit of angle.
/// </summary>
public Range angleRange = new Range(-90, 90);
/// <summary>
/// Range limit of distance.
/// </summary>
public Range distanceRange = new Range(1, 10);
/// <summary>
/// Damper for move and rotate.
/// </summary>
[Range(0, 15)]
public float damper = 5;
/// <summary>
/// Camera current angls.
/// </summary>
public Vector2 CurrentAngles { protected set; get; }
/// <summary>
/// Current distance from camera to target.
/// </summary>
public float CurrentDistance { protected set; get; }
/// <summary>
/// Camera target angls.
/// </summary>
protected Vector2 targetAngles;
/// <summary>
/// Target distance from camera to target.
/// </summary>
protected float targetDistance;
#endregion
#region Protected Method
protected virtual void Start()
{
// m_debugTip = GameObject.Find("Text").GetComponent<Text>();
CurrentAngles = targetAngles = transform.eulerAngles;
//CurrentDistance = targetDistance = Vector3.Distance(transform.position, target.position);
}
protected virtual void LateUpdate()
{
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
AroundByMouseInput();
#elif UNITY_ANDROID || UNITY_IPHONE
AroundByMobileInput();
#endif
}
private void Awake()
{
isRotate = true;
}
// Update is called once per frame
void FixedUpdate()
{
//获取当前触摸点
Gesture gesture = EasyTouch.current;
if (gesture != null && EasyTouch.EvtType.On_Swipe == gesture.type)
{
// OnSwiper(gesture);
}
//if (gesture != null && EasyTouch.EvtType.On_Pinch == gesture.type)
//{
// OnPinch(gesture);
//}
if (gesture != null && EasyTouch.EvtType.On_PinchIn == gesture.type)
{
On_PinchIn(gesture);
}
if (gesture != null && EasyTouch.EvtType.On_PinchOut == gesture.type)
{
On_PinchOut(gesture);
}
if (gesture != null && EasyTouch.EvtType.On_PinchEnd == gesture.type)
{
On_PinchEnd(gesture);
}
if (gesture != null && EasyTouch.EvtType.On_TouchUp == gesture.type)
{
On_TouchUp(gesture);
}
//i