using System.Collections; using UnityEngine; using UnityEngine.XR.Interaction.Toolkit.Interactables; public class MemoryFragmentReset : MonoBehaviour { [Header("References")] [SerializeField] private XRGrabInteractable grabInteractable; [SerializeField] private Rigidbody rb; [Header("Reset")] [SerializeField] private Transform resetPoint; [Tooltip("리셋 후 다시 잡을 수 있게 되기까지의 시간")] [SerializeField] private float reEnableDelay = 0.15f; [Header("Debug")] [SerializeField] private bool showDebugLog = true; private Vector3 startPosition; private Quaternion startRotation; private Transform startParent; private Coroutine resetRoutine; private void Awake() { if (grabInteractable == null) grabInteractable = GetComponent(); if (rb == null) rb = GetComponent(); startPosition = transform.position; startRotation = transform.rotation; startParent = transform.parent; } public void ResetFragment() { if (resetRoutine != null) StopCoroutine(resetRoutine); resetRoutine = StartCoroutine(ResetRoutine()); } private IEnumerator ResetRoutine() { if (grabInteractable != null) grabInteractable.enabled = false; if (rb != null) { rb.linearVelocity = Vector3.zero; rb.angularVelocity = Vector3.zero; rb.isKinematic = true; } transform.SetParent(startParent, true); if (resetPoint != null) { transform.position = resetPoint.position; transform.rotation = resetPoint.rotation; } else { transform.position = startPosition; transform.rotation = startRotation; } yield return new WaitForSeconds(reEnableDelay); if (rb != null) rb.isKinematic = false; if (grabInteractable != null) grabInteractable.enabled = true; if (showDebugLog) Debug.Log("[MemoryFragmentReset] 기억의 조각을 원래 위치로 되돌렸습니다.", this); resetRoutine = null; } }