安卓版本 双指缩放 单指旋转 缩放限制大小 旋转360度旋转 可选旋转或者缩放功能 限制区域选择缩放

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Mogoson.Tooltip;
using HighlightingSystem;
using HedgehogTeam.EasyTouch;

public class RotateOBJ : MonoBehaviour
{

//需要放大缩小旋转的物体
public GameObject rotateAndEnlargeObj;
public bool isRotate = true;
public bool isEnlarge = true;
//是否可以旋转模型
//public  bool Isa = false;
//public Vector3 oriRotate;

// Start is called before the first frame update
void Start()
{
    tempV = rotateAndEnlargeObj.transform.localRotation.eulerAngles;      
}
void OnEnable()
{
    if (isRotate)
    {
        EasyTouch.On_Drag += OnDrag;
        EasyTouch.On_Swipe += OnSwipe;
       
    }

    if (isEnlarge)
    {
        
        EasyTouch.On_PinchIn += OnPinchIn;
        EasyTouch.On_PinchOut += OnPinchOut;
    }

    EasyTouch.On_SimpleTap += OnSimpleTap;
    EasyTouch.On_DoubleTap += OnDoubleTap;

}
void OnDisable()
{
    if (isRotate)
    {
        EasyTouch.On_Drag -= OnDrag;
        EasyTouch.On_Swipe -= OnSwipe;
    }

    if (isEnlarge)
    {
        EasyTouch.On_PinchIn -= OnPinchIn;
        EasyTouch.On_PinchOut -= OnPinchOut;
    }

    EasyTouch.On_SimpleTap -= OnSimpleTap;
    EasyTouch.On_DoubleTap -= OnDoubleTap;
}
void OnSimpleTap(Gesture gest)
{
    if (gest.pickedObject != null)
    {
        SimpleTap(gest);
    }
    else
    {
        //Vuforia.CameraDevice.Instance.SetFocusMode(Vuforia.CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO);
    }
}
protected virtual void SimpleTap(Gesture gest)
{

}
void OnDoubleTap(Gesture gest)
{
    if (gest.pickedObject != null)
    {
        DoubleTap(gest);

       // Debug.Log("x:"+ Input.mousePosition.x+ "y:" + Input.mousePosition.y);
        //if (Input.mousePosition.y > 800 && Input.mousePosition.y < 2340 && Input.mousePosition.x > 240 && Input.mousePosition.x < 1250)//开始滑动的时候 判定一下鼠标在屏幕的坐标  如果符合 就可以 滑动
        //{
        //    Isa = true;
            
        //}
        //else
        //{

        //    Isa = false;
        //}
        
    }
    
}
protected virtual void DoubleTap(Gesture gest)
{

}

/// <summary>
/// 单指旋转
/// </summary>
/// <param name="gest"></param>
/// 
Vector3 tempV = new Vector3(0,0,0);
void OnDrag(Gesture gest)
{
   
    if (gest.pickedObject != null)
    { 
        if (rotateAndEnlargeObj != null)
        {

            //if(Isa==true)
            //{
                Vector3 v = tempV;

                v.z -= gest.deltaPosition.x * 10f * Time.deltaTime;
                v.x += gest.deltaPosition.y * 10f * Time.deltaTime;
                tempV = v;
                rotateAndEnlargeObj.transform.localRotation = Quaternion.Euler(tempV);
                Vector3 vector3 = new Vector3();
            
                
            //}

        }
    }

}
void OnSwipe(Gesture gest)
{
 
    if (rotateAndEnlargeObj != null)
    {
        //if (Isa == true)
        //{
            //Debug.Log(gest.deltaPosition.x);
            if(Input.mousePosition.x>340 && Input.mousePosition.x<1250 && Input.mousePosition.y>800&& Input.mousePosition.y<2200)
             {
                Vector3 v = tempV;
                // Debug.Log(v);
                v.z -= gest.deltaPosition.x * 10f * Time.deltaTime;
                v.x += gest.deltaPosition.y * 10f * Time.deltaTime;
                tempV = v;
                rotateAndEnlargeObj.transform.localRotation = Quaternion.Euler(tempV);
                //Debug.Log("x:" + Input.mousePosition.x + "y:" + Input.mousePosition.y);
             }
            
        //}
    }

}

/// <summary>
/// 双指缩放
/// </summary>
/// <param name="gest"></param>
void OnPinchIn(Gesture gest)
{
   // Debug.Log("1");
   
        if (rotateAndEnlargeObj != null)
        {
            Vector3 localScale = rotateAndEnlargeObj.transform.localScale;
            float num = (0.01f * gest.deltaPinch);
            rotateAndEnlargeObj.transform.localScale = new Vector3(localScale.x - num, localScale.y - num, localScale.z - num);
            if (rotateAndEnlargeObj.transform.localScale.x < 0.5)
            {
                rotateAndEnlargeObj.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
            }
        }
    

}



    void OnPinchOut(Gesture gest)
{
   // Debug.Log("2");
    
        if (rotateAndEnlargeObj != null)
        {
            Vector3 localScale = rotateAndEnlargeObj.transform.localScale;
            float num = (0.01f * gest.deltaPinch);
            rotateAndEnlargeObj.transform.localScale = new Vector3(localScale.x + num, localScale.y + num, localScale.z + num);
            if (rotateAndEnlargeObj.transform.localScale.x > 4)
            {
                rotateAndEnlargeObj.transform.localScale = new Vector3(3, 3, 3);
            }
        }
    
}
// void Update()
//{
//    //检测手指点击位置
//    if (Input.touchCount > 0)
//    {
//        Vector3 tmp = Input.GetTouch(0).position;
//        //Debug.Log(tmp);
//        if (Point(tmp))
//        {
//            isRotate = true;
//        }
//    }
//}

判断点是否在可滑动的区域内
//private bool Point(Vector3 vector)
//{
//    Debug.Log(vector.x + "x" + vector.y + "y");
//    if (vector.x > 240 && vector.x < 1250 && vector.y > 800 && vector.y < 2340)
//    {
//        return true;
//    }
//    else
//    {
//        return false;
//    }
//}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值