1234567891011121314151617181920212223242526272829303132333435363738394041 |
- //==========================================================
- //
- // Copyright (c) Guangzhou Shixiang Technology Co.,Ltd.
- // All rights reserved.
- //
- //==========================================================
- using System;
- using GxrSdk;
- using UnityEngine;
- public class TouchHandle : GxrDraggableTouchBehavior
- {
- /// <summary>
- /// 在这里根据触摸位置来更新transform.position位置信息
- /// </summary>
- /// <param name="currentTouchPosition">范围[-1,1]</param>
- /// <param name="lastTouchPosition">范围[-1,1]</param>
- protected override void UpdateTransform(Vector2 currentTouchPosition, Vector2 lastTouchPosition)
- {
- var deltaPosition = currentTouchPosition - lastTouchPosition;
- var factorX = deltaPosition.x < 0 ? -1 : 1;
- var factorY = deltaPosition.y < 0 ? -1 : 1;
- var dx = Math.Abs(deltaPosition.x);
- var dy = Math.Abs(deltaPosition.y);
- if (dx >= dy)
- {
- // 左右滑动缩放
- }
- else
- {
- // 前后滑动远近
- IGxrPointer pointer = GxrPointerManager.Instance.MainPointer;
- var direct = pointer.Rotation * Vector3.forward;
- var targetPosition = transform.position + factorY * 0.4f * direct;
- transform.position = targetPosition;
- }
- }
- }
|