육지도착

This commit is contained in:
2026-06-22 16:58:32 +09:00
parent f7a71e11d6
commit 74afff5be8
23 changed files with 1500 additions and 54 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
public class ClamOpenClose : MonoBehaviour
{
@@ -22,7 +23,7 @@ public class ClamOpenClose : MonoBehaviour
[SerializeField] private float maxOpenTime = 2.0f;
[SerializeField] private float openDuration = 1.5f;
[SerializeField] private float closeDuration = 0.18f;
[SerializeField] private float closeDuration = 0.2f;
[Header("Motion")]
[SerializeField] private AnimationCurve openCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
@@ -32,15 +33,20 @@ public class ClamOpenClose : MonoBehaviour
[SerializeField] private bool useSnapClose = true;
[Tooltip("닫힐 때 살짝 더 닫히는 오버슈트 각도입니다.")]
[SerializeField] private float snapCloseOvershootX = 5f;
[SerializeField] private float snapCloseOvershootX = 3f;
[Tooltip("쾅 하고 닫힌 뒤 원래 닫힌 위치로 돌아오는 시간입니다.")]
[SerializeField] private float snapCloseOvershootDuration = 0.06f;
[SerializeField] private float snapCloseOvershootDuration = 0.02f;
[Header("Start Option")]
[SerializeField] private bool startAutomatically = true;
[SerializeField] private bool startOpened = false;
[Header("Events")]
public UnityEvent onOpened;
public UnityEvent onCloseStarted;
public UnityEvent onClosed;
private Quaternion upClosedRot;
private Quaternion downClosedRot;
@@ -49,8 +55,10 @@ public class ClamOpenClose : MonoBehaviour
private Coroutine routine;
private bool isOpen;
private bool isClosing;
public bool IsOpen => isOpen;
public bool IsClosing => isClosing;
private void Awake()
{
@@ -72,13 +80,11 @@ private void Awake()
return;
}
// 현재 Scene에서 맞춰둔 로컬 회전을 닫힌 상태로 저장
upClosedRot = upShell.localRotation;
if (downShell != null)
downClosedRot = downShell.localRotation;
// 닫힌 상태 기준으로 X축 회전 추가
upOpenedRot = upClosedRot * Quaternion.Euler(upShellOpenX, 0f, 0f);
if (downShell != null)
@@ -120,7 +126,8 @@ private IEnumerator OpenCloseRoutine()
float closedWait = Random.Range(minClosedTime, maxClosedTime);
yield return new WaitForSeconds(closedWait);
// 천천히 열기
isClosing = false;
yield return MoveShells(
upClosedRot,
upOpenedRot,
@@ -131,11 +138,15 @@ private IEnumerator OpenCloseRoutine()
);
isOpen = true;
isClosing = false;
onOpened?.Invoke();
float openWait = Random.Range(minOpenTime, maxOpenTime);
yield return new WaitForSeconds(openWait);
// 빠르게 닫기
isClosing = true;
onCloseStarted?.Invoke();
yield return MoveShells(
upOpenedRot,
upClosedRot,
@@ -147,11 +158,13 @@ private IEnumerator OpenCloseRoutine()
isOpen = false;
// 쾅 닫히는 느낌
if (useSnapClose)
{
yield return SnapCloseEffect();
}
isClosing = false;
onClosed?.Invoke();
}
}
@@ -197,7 +210,6 @@ private IEnumerator SnapCloseEffect()
if (downShell != null)
downSnapRot = downClosedRot * Quaternion.Euler(-snapCloseOvershootX * 0.3f, 0f, 0f);
// 살짝 더 닫힘
if (upShell != null)
upShell.localRotation = upSnapRot;
@@ -206,7 +218,6 @@ private IEnumerator SnapCloseEffect()
yield return new WaitForSeconds(snapCloseOvershootDuration);
// 원래 닫힌 상태로 복귀
if (upShell != null)
upShell.localRotation = upClosedRot;
@@ -223,6 +234,7 @@ private void SetClosedImmediately()
downShell.localRotation = downClosedRot;
isOpen = false;
isClosing = false;
}
private void SetOpenedImmediately()
@@ -234,5 +246,6 @@ private void SetOpenedImmediately()
downShell.localRotation = downOpenedRot;
isOpen = true;
isClosing = false;
}
}