TouchHandle.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //==========================================================
  2. //
  3. // Copyright (c) Guangzhou Shixiang Technology Co.,Ltd.
  4. // All rights reserved.
  5. //
  6. //==========================================================
  7. using System;
  8. using GxrSdk;
  9. using UnityEngine;
  10. public class TouchHandle : GxrDraggableTouchBehavior
  11. {
  12. /// <summary>
  13. /// 在这里根据触摸位置来更新transform.position位置信息
  14. /// </summary>
  15. /// <param name="currentTouchPosition">范围[-1,1]</param>
  16. /// <param name="lastTouchPosition">范围[-1,1]</param>
  17. protected override void UpdateTransform(Vector2 currentTouchPosition, Vector2 lastTouchPosition)
  18. {
  19. var deltaPosition = currentTouchPosition - lastTouchPosition;
  20. var factorX = deltaPosition.x < 0 ? -1 : 1;
  21. var factorY = deltaPosition.y < 0 ? -1 : 1;
  22. var dx = Math.Abs(deltaPosition.x);
  23. var dy = Math.Abs(deltaPosition.y);
  24. if (dx >= dy)
  25. {
  26. // 左右滑动缩放
  27. }
  28. else
  29. {
  30. // 前后滑动远近
  31. IGxrPointer pointer = GxrPointerManager.Instance.MainPointer;
  32. var direct = pointer.Rotation * Vector3.forward;
  33. var targetPosition = transform.position + factorY * 0.4f * direct;
  34. transform.position = targetPosition;
  35. }
  36. }
  37. }