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;
// }
//}
}