Unity_触摸屏_控制Camera的旋转和距离缩放(实现二)

我这里使用了 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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值