unity手势控制、放大缩小、拖拽、滑动。单击

这篇博客介绍了如何在Unity中实现手势控制,包括单指触摸的放大、缩小、拖拽、滑动以及旋转操作。同时,它还涵盖了双指触控的缩放和旋转功能,以及使用陀螺仪进行设备方向感应。代码示例详细展示了实现这些功能的方法和逻辑。
摘要由CSDN通过智能技术生成
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using System.Collections.Generic;

public class TouchManager_Template : MonoBehaviour
{

    private TouchManager_Template() { }
    private static TouchManager_Template _instance = null;
    public static TouchManager_Template Instance
    {
        get { return _instance; }
        set { _instance = value; }
    }
    private GameObject _curModel;


    private Vector3 _ModelScreenPos;
    private Vector3 _ModelWorldPos;
    private Vector3 _MouseScreenPos;
    private Vector3 _Offset;

    private bool _Moved;

    private bool _Selected;

    private float _Scale = 5.0f;
    private float _ZoomDifference = 0;
    private float _ZoomSpeed = 100f;
    private float _ZoomMin = 1.0f;
    private float _ZoomMax = 2.0f;

    private float _StartAngle;
    private float _LastAngle;
    private Quaternion _curModelRotation;
    private Quaternion q = Quaternion.identity;
    private float _TurnAngle;

    private float _xMove;
    private float _yMove;

    public float _UpdateRotate = 220.00f;

    private Vector2 _TouchBegan = Vector2.zero;
    private Vector2 _TouchEnd = Vector2.zero;
    [Header("滑动误差")][Range(0,10)]
    public float _DragTolerance = 10.0f;
#if UNITY_EDITOR
    private float _MoveSpeed = 1.0f;
#elif UNITY_ANDROID
        private float _MoveSpeed = 2.0f;
#elif UNITY_IPHONE
            private float _MoveSpeed = 1.0f;
#endif



    public bool OneFingerRotate = true;
    void Awake()
    {
        _instance = this;
    }
    void Start()
    {
        _TurnAngle = 0;
        subscribeEvent();
        Input.gyro.enabled = true;
    }

    public static void subscribeEvent()
    {

    }
    public static void UnsubscribeEvent()
    {

    }

    void OnDestroy()
    {
        UnsubscribeEvent();
        Input.gyro.enabled = false;
    }

    GameObject getClosestObject(Vector3 _MousePos)
    {
        GameObject _go = null;

        List<GameObject> OnCardModelList = new List<GameObject>();

        if (OnCardModelList.Count > 0)
        {
            float _dis = 0;
            Vector3 p0 = new Vector3(_MousePos.x, _MousePos.y, 0f);

            foreach (var dic in OnCardModelList)
            {

                GameObject _tempGo = dic;

      
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值