using System.Collections.Generic;
using Rokid.UXR.Utility;
using UnityEngine;
using UnityEngine.EventSystems;namespace Rokid.UXR.Interaction
{/// <summary>/// Draggable 拖拽組件/// </summary>// [RequireComponent(typeof(RayInteractable))]public class Draggable : MonoBehaviour, IBezierCurveDrag, IRayBeginDrag, IRayDragToTarget, IRayEndDrag, IDraggable{[SerializeField, Tooltip("The min point to relative to the camera")]private Vector3 minPoint = new Vector3(-2, -0.8f, -2);[SerializeField, Tooltip("The farthest point to relative to the camera")]private Vector3 maxPoint = new Vector3(2, 1.2f, 2);[SerializeField, Tooltip("The drag obj is look at camera")]private bool lookAtCamera = false;[SerializeField, Tooltip("The drag obj is clamp in target filed")]private bool clampInTargetFiled = false;[SerializeField, Tooltip("The obj follow this drag obj")]private Transform followObj;[SerializeField, Tooltip("The drag smooth speed")]private int smoothSpeed = 10;[SerializeField, Tooltip("The look at change threshold")]private float lookAtChangeThreshold = 0.3f;private Vector3 offsetPos, dragOffset;private Dictionary<int, BezierPointerData> bezierPointerDatas = new Dictionary<int, BezierPointerData>();private bool dragging = false;private void Start(){if (followObj != null){offsetPos = transform.InverseTransformPoint(followObj.position);}}public void SetOrUpdateFollowObj(Transform followObj){this.followObj = followObj;offsetPos = transform.InverseTransformPoint(followObj.position);}private void AddBezierPointerData(PointerEventData eventData){BezierPointerData bezierPointerData = new BezierPointerData{pointerId = eventData.pointerId,hitLocalNormal = transform.InverseTransformVector(eventData.pointerCurrentRaycast.worldNormal),hitLocalPos = transform.InverseTransformPoint(eventData.pointerCurrentRaycast.worldPosition)};if (bezierPointerDatas.ContainsKey(bezierPointerData.pointerId)){bezierPointerDatas[bezierPointerData.pointerId] = bezierPointerData;}else{bezierPointerDatas.Add(bezierPointerData.pointerId, bezierPointerData);}}private void RemoveBezierPointerData(PointerEventData eventData){bezierPointerDatas.Remove(eventData.pointerId);