정리 중
This commit is contained in:
@@ -41,6 +41,7 @@ private enum StartState
|
||||
|
||||
private StartState state = StartState.Ready;
|
||||
private Coroutine startRoutine;
|
||||
private bool areRhinosRunning;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -49,15 +50,19 @@ private void Start()
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (state != StartState.WaitingForKeyGrab)
|
||||
return;
|
||||
|
||||
if (!waitForKeyGrab)
|
||||
return;
|
||||
|
||||
if (steeringKey != null && steeringKey.IsGrabbed)
|
||||
if (state == StartState.WaitingForKeyGrab)
|
||||
{
|
||||
BeginRaftRide();
|
||||
if (waitForKeyGrab && steeringKey != null && steeringKey.IsGrabbed)
|
||||
{
|
||||
BeginRaftRide();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == StartState.Starting || state == StartState.Riding)
|
||||
{
|
||||
SyncRhinosWithSteeringKey();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +83,7 @@ private void SetupStartState()
|
||||
raftHealth.ResetHealth();
|
||||
}
|
||||
|
||||
StopAllRhinos();
|
||||
SetRhinosRunning(false, true);
|
||||
|
||||
if (fairyObject != null)
|
||||
{
|
||||
@@ -135,7 +140,7 @@ private IEnumerator StartRaftSmoothly()
|
||||
raftController.SetSpeedMultiplier(0f);
|
||||
raftController.ResumeRaft();
|
||||
|
||||
StartAllRhinos();
|
||||
SyncRhinosWithSteeringKey(true);
|
||||
|
||||
if (showDebugLog)
|
||||
{
|
||||
@@ -160,6 +165,7 @@ private IEnumerator StartRaftSmoothly()
|
||||
raftController.SetSpeedMultiplier(1f);
|
||||
|
||||
state = StartState.Riding;
|
||||
SyncRhinosWithSteeringKey(true);
|
||||
|
||||
if (showDebugLog)
|
||||
{
|
||||
@@ -179,7 +185,7 @@ public void OnRaftArrived()
|
||||
raftController.SetSpeedMultiplier(0f);
|
||||
}
|
||||
|
||||
StopAllRhinos();
|
||||
SetRhinosRunning(false, true);
|
||||
|
||||
if (showDebugLog)
|
||||
{
|
||||
@@ -200,7 +206,7 @@ public void OnRaftFailed()
|
||||
raftController.SetSpeedMultiplier(0f);
|
||||
}
|
||||
|
||||
StopAllRhinos();
|
||||
SetRhinosRunning(false, true);
|
||||
|
||||
if (showDebugLog)
|
||||
{
|
||||
@@ -208,6 +214,36 @@ public void OnRaftFailed()
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncRhinosWithSteeringKey(bool force = false)
|
||||
{
|
||||
SetRhinosRunning(ShouldRhinosRunForCurrentInput(), force);
|
||||
}
|
||||
|
||||
private bool ShouldRhinosRunForCurrentInput()
|
||||
{
|
||||
if (!waitForKeyGrab)
|
||||
return true;
|
||||
|
||||
return steeringKey != null && steeringKey.IsGrabbed;
|
||||
}
|
||||
|
||||
private void SetRhinosRunning(bool shouldRun, bool force = false)
|
||||
{
|
||||
if (!force && areRhinosRunning == shouldRun)
|
||||
return;
|
||||
|
||||
if (shouldRun)
|
||||
{
|
||||
StartAllRhinos();
|
||||
}
|
||||
else
|
||||
{
|
||||
StopAllRhinos();
|
||||
}
|
||||
|
||||
areRhinosRunning = shouldRun;
|
||||
}
|
||||
|
||||
private void StartAllRhinos()
|
||||
{
|
||||
if (rhinos == null)
|
||||
|
||||
@@ -33,6 +33,8 @@ public class RhinoObstacle : MonoBehaviour
|
||||
[SerializeField] private bool startAutomatically = true;
|
||||
[SerializeField] private bool loop = true;
|
||||
[SerializeField] private bool showDebugLog = true;
|
||||
[SerializeField] private bool showLifecycleDebugLog = false;
|
||||
[SerializeField] private bool showRoutineDebugLog = false;
|
||||
|
||||
private Coroutine routine;
|
||||
private bool isRunning;
|
||||
@@ -82,19 +84,25 @@ private void ResolveReferences()
|
||||
|
||||
public void StartRhino()
|
||||
{
|
||||
if (isRunning && routine != null)
|
||||
return;
|
||||
|
||||
if (routine != null)
|
||||
{
|
||||
StopCoroutine(routine);
|
||||
routine = null;
|
||||
}
|
||||
|
||||
isRunning = true;
|
||||
routine = StartCoroutine(RhinoRoutine());
|
||||
|
||||
Log("시작");
|
||||
Log("Start");
|
||||
}
|
||||
|
||||
public void StopRhino()
|
||||
{
|
||||
bool wasActive = isRunning || routine != null || isSurfaced;
|
||||
|
||||
isRunning = false;
|
||||
|
||||
if (routine != null)
|
||||
@@ -107,7 +115,10 @@ public void StopRhino()
|
||||
ForceIdleAnimation();
|
||||
MoveImmediatelyToUnderwater();
|
||||
|
||||
Log("정지");
|
||||
if (wasActive)
|
||||
{
|
||||
Log("Stop");
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator RhinoRoutine()
|
||||
@@ -120,7 +131,7 @@ private IEnumerator RhinoRoutine()
|
||||
ForceIdleAnimation();
|
||||
|
||||
float hiddenWait = Random.Range(minHiddenTime, maxHiddenTime);
|
||||
Log($"물속 대기 {hiddenWait:0.0}초");
|
||||
LogRoutine($"물속 대기 {hiddenWait:0.0}초");
|
||||
|
||||
yield return new WaitForSeconds(hiddenWait);
|
||||
|
||||
@@ -128,7 +139,7 @@ private IEnumerator RhinoRoutine()
|
||||
break;
|
||||
|
||||
// 2. 수면 위로 떠오름
|
||||
Log("떠오름 시작");
|
||||
LogRoutine("떠오름 시작");
|
||||
yield return MoveToSurface();
|
||||
|
||||
if (!isRunning)
|
||||
@@ -139,7 +150,7 @@ private IEnumerator RhinoRoutine()
|
||||
SetDamageActive(true);
|
||||
ForceIdleAnimation();
|
||||
|
||||
Log("수면 위 도착 / 데미지 콜라이더 ON");
|
||||
LogRoutine("수면 위 도착 / 데미지 콜라이더 ON");
|
||||
|
||||
yield return new WaitForSeconds(surfaceIdleTime);
|
||||
|
||||
@@ -147,13 +158,13 @@ private IEnumerator RhinoRoutine()
|
||||
break;
|
||||
|
||||
// 4. 공격 실행
|
||||
Log("공격 시작");
|
||||
LogRoutine("공격 시작");
|
||||
PlayHitAnimation();
|
||||
|
||||
yield return new WaitForSeconds(attackStayTime);
|
||||
|
||||
// 5. 공격 종료 후 Idle 복귀
|
||||
Log("공격 종료 / Idle 복귀");
|
||||
LogRoutine("공격 종료 / Idle 복귀");
|
||||
ForceIdleAnimation();
|
||||
|
||||
if (!isRunning)
|
||||
@@ -163,7 +174,7 @@ private IEnumerator RhinoRoutine()
|
||||
isSurfaced = false;
|
||||
SetDamageActive(false);
|
||||
|
||||
Log("잠수 시작 / 데미지 콜라이더 OFF");
|
||||
LogRoutine("잠수 시작 / 데미지 콜라이더 OFF");
|
||||
yield return MoveToUnderwater();
|
||||
|
||||
if (!loop)
|
||||
@@ -228,7 +239,7 @@ private IEnumerator MoveToUnderwater()
|
||||
SetDamageActive(false);
|
||||
ForceIdleAnimation();
|
||||
|
||||
Log("잠수 완료");
|
||||
LogRoutine("잠수 완료");
|
||||
}
|
||||
|
||||
private void PlayHitAnimation()
|
||||
@@ -298,7 +309,13 @@ private float Smooth01(float t)
|
||||
|
||||
private void Log(string message)
|
||||
{
|
||||
if (showDebugLog)
|
||||
if (showDebugLog && showLifecycleDebugLog)
|
||||
Debug.Log($"[RhinoObstacle] {name} / {message}");
|
||||
}
|
||||
|
||||
private void LogRoutine(string message)
|
||||
{
|
||||
if (showDebugLog && showRoutineDebugLog)
|
||||
Debug.Log($"[RhinoObstacle] {name} / {message}");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user