unity开发 相机旋转、缩放、拖动、抖动等控制
日期: 2020-12-13 分类: 跨站数据测试 582次阅读
下面展示一些 相机旋转、缩放、拖动、抖动等控制
。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HedgehogTeam.EasyTouch;
using MR_LBS.Client.Unity3D;
using UnityEngine.EventSystems;
/***
* 相机移动旋转
* **/
public class CameraController : MonoBehaviour
{
[HideInInspector]
public static CameraController instance;
[HideInInspector]
public bool dragSign;
//拖动
public float size = 45;
public float maxSize = 55;
public float minSize = 25;
private float desiredDistance;
private Vector3 desiredPosition;//单指拖动后,相机的未来坐标
public float xSpeed = 20.0f;
public float ySpeed = 20.0f;
public float pinchSpeed = 10f;
private float xDeg = 0.0f;
private float yDeg = 0.0f;
//抖屏
public float shakeLevel = 4f;// 震动幅度
public float setShakeTime = 0.7f; // 震动时间
public float shakeFps = 45f; // 震动的FPS
/// <summary>
/// 震动标志
/// </summary>
private bool isshakeCamera = true;
/// <summary>
/// 是否允许抖屏(防止投兵出问题)
/// </summary>
private bool enableIsshake = true;
private float fps;
private float shakeTime = 0.0f;
private float frameTime = 0.0f;
private float shakeDelta = 0.005f;
private Camera selfCamera;
MainView mainView;
private void Awake()
{
instance = this;
EasyTouch.AddCamera(Camera.main);//给easytouch的相机赋值
}
void Start()
{
dragSign = true;
Init();
mainView = MainView.instance;
}
private void Update()
{
// Debug.Log(Vector3.Magnitude(transform.position - target.position));
}
/// <summary>
/// 在OnEnable中注册EasyTouch事件
/// </summary>
void OnEnable()
{
Init();
//添加委托
EasyTouch.On_Drag += On_Drag;
//EasyTouch.On_DragStart += On_DragStart;
//EasyTouch.On_DragEnd += On_DragEnd;
//EasyTouch.On_TouchStart2Fingers += On_TouchStart2Fingers;
EasyTouch.On_PinchIn += On_PinchIn;
EasyTouch.On_PinchOut += On_PinchOut;
EasyTouch.On_OverUIElement += On_OverUIElement;
EasyTouch.On_UIElementTouchUp += On_UIElementTouchUp;
//EasyTouch.On_PinchEnd += On_PinchEnd;
//屏幕抖动
selfCamera = gameObject.GetComponent<Camera>();
shakeTime = setShakeTime;
fps = shakeFps;
frameTime = 0.03f;
shakeDelta = 0.005f;
}
/// <summary>
/// 在OnDisable中取消注册事件
/// </summary>
void OnDisable()
{
UnsubscribeEvent_Drag();
UnsubscribeEvent_Pinch();
}
/// <summary>
/// 在OnDestroy中删除注册事件
/// </summary>
void OnDestroy()
{
UnsubscribeEvent_Drag();
UnsubscribeEvent_Pinch();
}
void UnsubscribeEvent_Pinch()
{
//删除委托
//EasyTouch.On_TouchStart2Fingers -= On_TouchStart2Fingers;
EasyTouch.On_PinchIn -= On_PinchIn;
EasyTouch.On_PinchOut -= On_PinchOut;
EasyTouch.On_Drag -= On_Drag;
EasyTouch.On_OverUIElement -= On_OverUIElement;
EasyTouch.On_UIElementTouchUp -= On_UIElementTouchUp;
//EasyTouch.On_PinchEnd -= On_PinchEnd;
}
void UnsubscribeEvent_Drag()
{
EasyTouch.On_Drag -= On_Drag;
//EasyTouch.On_DragStart -= On_DragStart;
//EasyTouch.On_DragEnd -= On_DragEnd;
}
public void Init()
{
transform.position = new Vector3(-36, 70, 0);
this.GetComponent<Camera>().orthographicSize = size;
}
/// <summary>
/// 相机归位
/// </summary>
public void CameraHoming()
{
Init();
}
/// <summary>
/// 开启屏幕抖动
/// </summary>
public void OpenShakeCamera()
{
#if Cheng
if (isshakeCamera && enableIsshake)
StartCoroutine(ShakeCamera());
#endif
}
IEnumerator ShakeCamera()
{
isshakeCamera = false;
shakeTime = setShakeTime;
while (shakeTime > 0)
{
yield return new WaitForSecondsRealtime(Time.deltaTime);
shakeTime -= Time.deltaTime;
frameTime += Time.deltaTime;
if (frameTime > 1.0 / fps)
{
frameTime = 0;
selfCamera.rect = new Rect(shakeDelta * (-1.0f + shakeLevel * Random.value), shakeDelta * (-1.0f + shakeLevel * Random.value), 1.0f, 1.0f);
}
}
selfCamera.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
isshakeCamera = true;
}
void On_DragStart(Gesture gesture)
{
}
void On_Drag(Gesture gesture)
{
//Debug.Log("2222");
//单指拖动移动
if (gesture.touchCount > 1 || !dragSign)
{
//Debug.Log("禁止多指拖动");
return;
}
xDeg = gesture.deltaPosition.x * xSpeed * 0.001f;
yDeg = gesture.deltaPosition.y * ySpeed * 0.001f;
desiredPosition = new Vector3(transform.position.x - yDeg, 70, transform.position.z + xDeg * 0.6f);
desiredPosition.z = Mathf.Clamp(desiredPosition.z, -6, 6);
desiredPosition.x = Mathf.Clamp(desiredPosition.x, -45, -32);
transform.position = desiredPosition;
}
void On_DragEnd(Gesture gesture)
{
}
private void On_TouchStart2Fingers(Gesture gesture)
{
//Debug.Log("pinch111");
//Verification that the action on the object
//if (gesture.pickedObject == gameObject)
//{
// // disable twist gesture recognize for a real pinch end
// EasyTouch.SetEnableTwist(false);
// EasyTouch.SetEnablePinch(true);
//}
}
// At the pinch in
private void On_PinchIn(Gesture gesture)
{
desiredDistance = this.GetComponent<Camera>().orthographicSize;
desiredDistance += gesture.deltaPinch * Time.deltaTime * pinchSpeed * 0.1f;//Input.GetAxis("Mouse Y") * 0.02f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//
//Debug.Log(desiredDistance);
desiredDistance = Mathf.Clamp(desiredDistance, minSize, maxSize);
this.GetComponent<Camera>().orthographicSize = desiredDistance;
}
// At the pinch out
private void On_PinchOut(Gesture gesture)
{
desiredDistance = this.GetComponent<Camera>().orthographicSize;
desiredDistance -= gesture.deltaPinch * Time.deltaTime * pinchSpeed * 0.1f;//Input.GetAxis("Mouse Y") * 0.02f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//
//Debug.Log(desiredDistance);
desiredDistance = Mathf.Clamp(desiredDistance, minSize, maxSize);
this.GetComponent<Camera>().orthographicSize = desiredDistance;
}
// At the pinch end
private void On_PinchEnd(Gesture gesture)
{
}
[HideInInspector]
public PetButton petButtonTemp;
[HideInInspector]
public BigSkillButton skillButtonTemp;
public Transform wormholePet;
Vector3 parentMove;
Color green = new Color(145/225f, 1f, 220/225f, 230 / 255f);
Color red = new Color(255 / 255f, 83 / 255f, 0f, 230 / 255f);
SpriteRenderer effectScopeTemp;
SpriteRenderer shotRangeTemp;
int changeMesh = 0;
private Vector3 changePos = new Vector3(30,0,0);
private Vector3 targetPos = new Vector3(0, 0, 0);
private Vector3 tempPos = new Vector3(0, 0, 0);
/// <summary>
/// 是否允许卡牌解锁(拖动大招时禁止解锁)
/// </summary>
[HideInInspector]
public bool openLockSign = true;
/// <summary>
/// 获取点击的UI(持续每帧获取)
/// </summary>
/// <param name="gesture"></param>
void On_OverUIElement(Gesture gesture)
{
//Debug.Log(gesture.position.y);
//GuideController.instance.CloseGuide();
if (gesture.touchCount > 1)
{
//Debug.Log("存在多指点击");
mainView.closeSkillS.SetActive(false);
return;
}
if (gesture.pickedUIElement != null )
{
enableIsshake = false;
if (gesture.pickedUIElement.name == "PetButton")
{
petButtonTemp = gesture.pickedUIElement.GetComponent<PetButton>();
if (petButtonTemp.petPrefab != null)
{
//投兵拖动ing
if (!petButtonTemp.canPickUp)
{
//Debug.Log(111);
//跟随手指移动
tempPos = Camera.main.ScreenToWorldPoint(gesture.position) + changePos;
if (tempPos.x > -1)
targetPos.x = -1;
else if (tempPos.x < -31)
targetPos.x = -31;
else
targetPos.x = tempPos.x;
if (tempPos.z > 19)
targetPos.z = 19;
else if (tempPos.z < -19)
targetPos.z = -19;
else
targetPos.z = tempPos.z;
targetPos.y = 0;//petButtonTemp.petPrefab.transform.position.y;
petButtonTemp.petPrefab.transform.position = targetPos;
if (gesture.position.y > Camera.main.WorldToScreenPoint(wormholePet.position).y)
{
petButtonTemp.dragClose.SetActive(true);//打开拖动取消图标
petButtonTemp.petPrefab.SetActive(true);
if (GuideController.instance.StepSign < 5)
{
GuideController.instance.StepControl(5, 0);//投兵区域引导
}
}
}
//投兵开始拖动
else if (petButtonTemp.canPickUp)
{
foreach (PetButton tempButton in mainView.buttonToggle)
{
if (tempButton.gameObject != gesture.pickedUIElement)
{
tempButton.canPickUp = true;
tempButton.transform.localScale = tempButton.minScale;
}
else
{
petButtonTemp.canPickUp = false;
//dragSign = false;//禁止拖动场景
petButtonTemp.transform.localScale = petButtonTemp.maxScale;
}
petButtonTemp.TapSign = false;
}
if (petButtonTemp.Prefab.tag == "AirForce")
{
petButtonTemp.areaTip_All.SetActive(true);//打开投放区域提示
petButtonTemp.areaTip_4.SetActive(false);
}
else
{
petButtonTemp.areaTip_All.SetActive(true);//打开投放区域提示
petButtonTemp.areaTip_4.SetActive(true);
}
petButtonTemp.getGeneratePos = false;
}
}
else
{
petButtonTemp = null;
}
skillButtonTemp = null;
}
else if (gesture.pickedUIElement.name == "SkillButton")
{
skillButtonTemp = gesture.pickedUIElement.GetComponent<BigSkillButton>();
//大招拖动
if (skillButtonTemp.petSubControl != null)
{
GuideController.instance.CloseGuide();
gesture.pickedUIElement.transform.localScale = skillButtonTemp.maxScale;
//控制大招区域跟随宠物一起动,同时高度不变
parentMove = skillButtonTemp.petSubControl.gameObject.transform.position;
parentMove.y = skillButtonTemp.petSubControl.bigSkillArea.transform.position.y;
if (IsPointerOverUIObject("CloseSkillS"))
{
//变成红色
skillButtonTemp.petSubControl.shotRange.GetComponent<SpriteRenderer>().color = red;
if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragPosition)
{
skillButtonTemp.petSubControl.effectScope.GetComponent<CapsuleCollider>().enabled = false;
skillButtonTemp.petSubControl.effectScope.GetComponent<SpriteRenderer>().color = red;
}
else if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragRotation)
{
//petButtonTemp.petSubControl.effectScope.GetComponent<CapsuleCollider>().enabled = false;
skillButtonTemp.petSubControl.rotateDirection.transform.Find("GameObject/Direction").GetComponent<SpriteRenderer>().color = red;
}
//Debug.Log("变红");
}
else
{
//变成绿色
skillButtonTemp.petSubControl.shotRange.GetComponent<SpriteRenderer>().color = green;
mainView.closeSkillS.SetActive(true);
if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragPosition)
{
skillButtonTemp.petSubControl.effectScope.GetComponent<CapsuleCollider>().enabled = true;
skillButtonTemp.petSubControl.effectScope.GetComponent<SpriteRenderer>().color = green;
}
else if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragRotation)
{
//petButtonTemp.petSubControl.effectScope.GetComponent<CapsuleCollider>().enabled = false;
skillButtonTemp.petSubControl.rotateDirection.transform.Find("GameObject/Direction").GetComponent<SpriteRenderer>().color = green;
}
}
skillButtonTemp.petSubControl.bigSkillArea.SetActive(true);
skillButtonTemp.petSubControl.bigSkillArea.transform.position = parentMove;
if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragRotation)
{
skillButtonTemp.petSubControl.rotateDirection.SetActive(true);
skillButtonTemp.petSubControl.rotateDirection.transform.position = parentMove;
}
}
else
{
skillButtonTemp = null;
mainView.closeSkillS.SetActive(false);
}
petButtonTemp = null;
}
//Debug.Log(gesture.pickedUIElement.name);
}
//label.text = "You touch UI Element : " + gesture.pickedUIElement.name + " (from On_OverUIElement event)";
}
void On_UIElementTouchUp(Gesture gesture)
{
if (!BattleController.instance.startBattleSign)
return;
//投兵区域判定
if (petButtonTemp != null && petButtonTemp.petPrefab != null && !petButtonTemp.canPickUp)
{
//Debug.Log(222);
//已被打开,说明触发了拖动
if (petButtonTemp.petPrefab.activeInHierarchy)
{
petButtonTemp.petPrefab.SetActive(false);
//如果放在按钮上,取消投放
if (!IsPointerOverUIObject("PetButton"))
{
petButtonTemp.DragGeneratePos(petButtonTemp.petPrefab.transform.position);
//投放后按钮设为空
//petButtonTemp = null;
}
else
{
SoundManager.Instance.PlaySound(SoundSkill.errorTips);
}
foreach (PetButton tempButton in mainView.buttonToggle)
{
tempButton.canPickUp = true;
tempButton.dragClose.SetActive(false);
tempButton.transform.localScale = tempButton.minScale;
tempButton.areaTip_All.SetActive(false);//关闭投放区域提示
tempButton.areaTip_4.SetActive(false);
}
}
//没打开,说明未出发拖动,是点击事件
else
{
//Debug.Log("等待点击投兵");
foreach (PetButton tempButton in mainView.buttonToggle)
{
if (tempButton.gameObject != gesture.pickedUIElement)
{
tempButton.canPickUp = true;
tempButton.transform.localScale = petButtonTemp.minScale;
}
tempButton.dragClose.SetActive(false);
}
petButtonTemp.StartGeneratePos();
}
}
else if (skillButtonTemp != null && skillButtonTemp.petPrefab != null)
{
if (!IsPointerOverUIObject("CloseSkillS"))
{
if (GuideController.instance.StepSign == 5)
GuideController.instance.StepControl(6, 10f);
switch (skillButtonTemp.petSubControl.bigSkillType)
{
case BigSkillType.click:
skillButtonTemp.petSubControl.bTree.SetVariableValue("OnBigSkill", true);
break;
case BigSkillType.dragPosition:
DragPositionCon(skillButtonTemp.petSubControl);
skillButtonTemp.petSubControl.bTree.SetVariableValue("OnBigSkill", true);
break;
case BigSkillType.dragRotation:
DragRotateCon(skillButtonTemp.petSubControl);
skillButtonTemp.petSubControl.bigSkillPostion = skillButtonTemp.petSubControl.effectScope.transform.position;
//碰撞检测
skillButtonTemp.petSubControl.bTree.SetVariableValue("OnBigSkill", true);
break;
}
}
else
Debug.LogError("取消释放");
skillButtonTemp.petSubControl.bigSkillArea.SetActive(false);
if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragPosition)
{
skillButtonTemp.petSubControl.effectScope.transform.localPosition = new Vector3(0, 0, 0);
//恢复变白的宠物
skillButtonTemp.petSubControl.effectScope.GetComponent<DragSkillController>().CloseFX();
}
else if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragRotation)
{
skillButtonTemp.petSubControl.effectScope.transform.localPosition = new Vector3(1, 0, 0);
skillButtonTemp.petSubControl.rotateDirection.SetActive(false);
}
}
//抬起后按钮设为空
skillButtonTemp = null;
petButtonTemp = null;
mainView.closeSkillS.SetActive(false);
enableIsshake = true;
}
private Vector3 startPoint = new Vector3(0, 15, 0);//圆柱形触发器上部位置
private Vector3 endPoint = new Vector3(0, -5, 0);//圆柱形触发器下部位置
private Collider[] hitColliders;
/// <summary>
/// 范围性技能,目标获取方法
/// </summary>
/// <param name="petSubControl"></param>
public void DragPositionCon(PetSubControl petSubControl) {
startPoint.x = petSubControl.effectScope.transform.position.x;
startPoint.z = petSubControl.effectScope.transform.position.z;
endPoint.x = startPoint.x;
endPoint.z = startPoint.z;
hitColliders = Physics.OverlapCapsule(startPoint, endPoint, 0.1f, 1<<12, QueryTriggerInteraction.Collide);
if (hitColliders.Length > 0)
{
petSubControl.bigSkillTarget = hitColliders[0].gameObject;
//Debug.LogError(petSubControl.bigSkillTarget.name);
}
else {
petSubControl.bigSkillPostion = petSubControl.effectScope.transform.position;
petSubControl.bigSkillPostion.y = 2;
//Debug.LogError(petSubControl.bigSkillPostion);
}
}
/// <summary>
/// 指向性技能,目标获取方法
/// </summary>
/// <param name="petSubControl"></param>
public void DragRotateCon(PetSubControl petSubControl) {
if(petSubControl.rotateDirection.transform.Find("GameObject/Direction").GetComponent<RotateSkillController>().target != null)
petSubControl.bigSkillTarget = petSubControl.rotateDirection.transform.Find("GameObject/Direction").GetComponent<RotateSkillController>().target;
//Debug.Log(petSubControl.bigSkillTarget.name);
}
MonsterControlBase enemyControlBase;
/// <summary>
/// 判断拖动大招后,抬起的位置是否在取消大招的按钮位置
/// </summary>
/// <param name="targetName"></param>
/// <returns></returns>
public bool IsPointerOverUIObject(string targetName)
{
PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE)
eventDataCurrentPosition.position = Input.GetTouch(0).position;
#else
eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
#endif
List<RaycastResult> results = new List<RaycastResult>();
if (EventSystem.current)
{
EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
}
foreach(var temps in results)
{
if (temps.gameObject.name == targetName)//LayerMask.NameToLayer("UI"))
{
//Debug.LogError(temps.gameObject.name);
return true;
}
}
return false;
}
}
#region 相机旋转方法
//using System.Collections;
//using System.Collections.Generic;
//using UnityEngine;
//using HedgehogTeam.EasyTouch;
//public class CameraCon : MonoBehaviour
//{
// public Transform target;
// public Vector3 targetOffset;
// public float distance = 32;//5.0f;
// public float maxDistance = 33;//20;
// public float minDistance = 5;//.6f;
// public float xSpeed = 20.0f;
// public float ySpeed = 20.0f;
// public int yMinLimit = 30;//-80;
// public int yMaxLimit = 90;
// public int zoomRate = 40;
// //public float panSpeed = 0.3f;
// public float zoomDampening = 5.0f;
// //public float autoRotate = 1;
// private float xDeg = 0.0f;
// private float yDeg = 0.0f;
// private float currentDistance;
// private float desiredDistance;
// private Quaternion currentRotation;
// private Quaternion desiredRotation;
// private Quaternion rotation;
// private Vector3 position;
// private float idleTimer = 0.0f;
// private float idleSmooth = 0.0f;
// void Start() { Init(); }
// /// <summary>
// /// 在OnEnable中注册EasyTouch事件
// /// </summary>
// void OnEnable()
// {
// Init();
// //添加委托
// EasyTouch.On_Drag += On_Drag;
// EasyTouch.On_DragStart += On_DragStart;
// EasyTouch.On_DragEnd += On_DragEnd;
// EasyTouch.On_TouchStart2Fingers += On_TouchStart2Fingers;
// EasyTouch.On_PinchIn += On_PinchIn;
// EasyTouch.On_PinchOut += On_PinchOut;
// EasyTouch.On_PinchEnd += On_PinchEnd;
// }
// /// <summary>
// /// 在OnDisable中取消注册事件
// /// </summary>
// void OnDisable()
// {
// UnsubscribeEvent_Drag();
// UnsubscribeEvent_Pinch();
// }
// /// <summary>
// /// 在OnDestroy中删除注册事件
// /// </summary>
// void OnDestroy()
// {
// UnsubscribeEvent_Drag();
// UnsubscribeEvent_Pinch();
// }
// void UnsubscribeEvent_Pinch()
// {
// //删除委托
// EasyTouch.On_TouchStart2Fingers -= On_TouchStart2Fingers;
// EasyTouch.On_PinchIn -= On_PinchIn;
// EasyTouch.On_PinchOut -= On_PinchOut;
// EasyTouch.On_PinchEnd -= On_PinchEnd;
// }
// void UnsubscribeEvent_Drag()
// {
// EasyTouch.On_Drag -= On_Drag;
// EasyTouch.On_DragStart -= On_DragStart;
// EasyTouch.On_DragEnd -= On_DragEnd;
// }
// public void Init()
// {
// //If there is no target, create a temporary target at 'distance' from the cameras current viewpoint
// if (!target)
// {
// GameObject go = new GameObject("Cam Target");
// go.transform.position = transform.position + (transform.forward * distance);
// target = go.transform;
// }
// //distance = Vector3.Distance(transform.position, target.position);
// currentDistance = distance;
// desiredDistance = distance;
// //be sure to grab the current rotations as starting points.
// position = transform.position;
// rotation = transform.rotation;
// currentRotation = transform.rotation;
// desiredRotation = transform.rotation;
// xDeg = Vector3.Angle(Vector3.right, transform.right);
// yDeg = Vector3.Angle(Vector3.up, transform.up);
// position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
// }
// void On_DragStart(Gesture gesture)
// {
// }
// void On_Drag(Gesture gesture)
// {
// if (gesture.touchCount > 1)
// {
// Debug.Log("禁止单指拖动");
// return;
// }
// xDeg += gesture.deltaPosition.x * xSpeed * 0.02f;//Input.GetAxis("Mouse X") * xSpeed * 0.02f;
// yDeg -= gesture.deltaPosition.y * xSpeed * 0.02f;//Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
// //Clamp the vertical axis for the orbit
// yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
// // set camera rotation
// desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
// currentRotation = transform.rotation;
// rotation = Quaternion.Lerp(currentRotation, desiredRotation, 0.02f * zoomDampening);
// transform.rotation = rotation;
// / Reset idle timers
// idleTimer = 0;
// idleSmooth = 0;
// //Orbit Position
// // affect the desired Zoom distance if we roll the scrollwheel
// desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * 0.02f * zoomRate * Mathf.Abs(desiredDistance);
// //clamp the zoom min/max
// desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
// // For smoothing of the zoom, lerp distance
// currentDistance = Mathf.Lerp(currentDistance, desiredDistance, 0.02f * zoomDampening);
// //calculate position based on the new currentDistance
// position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
// transform.position = position;
// }
// void On_DragEnd(Gesture gesture)
// {
// }
// private void On_TouchStart2Fingers(Gesture gesture)
// {
// //Debug.Log("pinch111");
// //Verification that the action on the object
// //if (gesture.pickedObject == gameObject)
// //{
// // // disable twist gesture recognize for a real pinch end
// // EasyTouch.SetEnableTwist(false);
// // EasyTouch.SetEnablePinch(true);
// //}
// }
// // At the pinch in
// private void On_PinchIn(Gesture gesture)
// {
// // Debug.Log("pinch222");
// desiredDistance -= Input.GetAxis("Mouse Y") * 0.02f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//gesture.deltaPosition.y * 0.002f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);
// // affect the desired Zoom distance if we roll the scrollwheel
// desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * 0.02f * zoomRate * Mathf.Abs(desiredDistance);
// //clamp the zoom min/max
// desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
// // For smoothing of the zoom, lerp distance
// currentDistance = Mathf.Lerp(currentDistance, desiredDistance, 0.02f * zoomDampening);
// // calculate position based on the new currentDistance
// position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
// transform.position = position;
// }
// // At the pinch out
// private void On_PinchOut(Gesture gesture)
// {
// desiredDistance -= Input.GetAxis("Mouse Y") * 0.02f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//gesture.deltaPosition.y * 0.002f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//
// // affect the desired Zoom distance if we roll the scrollwheel
// desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * 0.02f * zoomRate * Mathf.Abs(desiredDistance);
// //clamp the zoom min/max
// desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
// // For smoothing of the zoom, lerp distance
// currentDistance = Mathf.Lerp(currentDistance, desiredDistance, 0.02f * zoomDampening);
// // calculate position based on the new currentDistance
// position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
// transform.position = position;
// //Debug.Log("pinch333");
// }
// // At the pinch end
// private void On_PinchEnd(Gesture gesture)
// {
// //ragCon.GetComponent<DragCon>().enabled = true;
// Debug.Log("pinch444");
// }
// private static float ClampAngle(float angle, float min, float max)
// {
// if (angle < -360)
// angle += 360;
// if (angle > 360)
// angle -= 360;
// return Mathf.Clamp(angle, min, max);
// }
//}
#endregion
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
精华推荐