블랙잭 끝
This commit is contained in:
@@ -9,11 +9,13 @@ public class HookWalkToTable : MonoBehaviour
|
||||
public Transform tableFrontPoint;
|
||||
public Transform chairFrontPoint;
|
||||
|
||||
[Header("Sit Point")]
|
||||
[Header("Sit / Stand Point")]
|
||||
public Transform sitPoint;
|
||||
public Transform standPoint;
|
||||
|
||||
[Header("Move Setting")]
|
||||
public float arriveBuffer = 0.15f;
|
||||
public float navMeshSampleDistance = 1.5f;
|
||||
|
||||
[Header("Animator")]
|
||||
public Animator animator;
|
||||
@@ -21,8 +23,16 @@ public class HookWalkToTable : MonoBehaviour
|
||||
public string sitTriggerName = "sitTrigger";
|
||||
public string standTriggerName = "standTrigger";
|
||||
|
||||
[Header("Force Stand Animation")]
|
||||
public bool forcePlayStandState = true;
|
||||
public string standStateName = "Sit To Stand 0";
|
||||
|
||||
[Header("Stand Up Setting")]
|
||||
public float standUpDuration = 1.5f;
|
||||
public bool disableAgentAfterStandUp = true;
|
||||
|
||||
[Header("After Match")]
|
||||
public bool blockWalkingAfterStandUp = true;
|
||||
|
||||
[Header("Collision")]
|
||||
public bool disableCollidersWhenSitting = true;
|
||||
@@ -37,16 +47,21 @@ public class HookWalkToTable : MonoBehaviour
|
||||
|
||||
private int step = 0;
|
||||
private bool isMoving = false;
|
||||
private bool hasArrived = false;
|
||||
private bool isSitting = false;
|
||||
private bool isStandingUp = false;
|
||||
private bool hasStoodUpAfterMatch = false;
|
||||
|
||||
private Vector3 currentDestination;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
|
||||
if (animator == null)
|
||||
{
|
||||
animator = GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
if (agent != null)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
@@ -57,32 +72,37 @@ void Start()
|
||||
|
||||
if (animator != null)
|
||||
{
|
||||
animator.applyRootMotion = false;
|
||||
animator.SetBool(walkBoolName, false);
|
||||
animator.ResetTrigger(sitTriggerName);
|
||||
animator.ResetTrigger(standTriggerName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Hook Animator is missing.");
|
||||
}
|
||||
|
||||
if (hookColliders == null || hookColliders.Length == 0)
|
||||
{
|
||||
hookColliders = GetComponentsInChildren<Collider>();
|
||||
}
|
||||
|
||||
Debug.Log("HookWalkToTable ready.");
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
// 테스트용: T 누르면 테이블로 이동 후 앉기
|
||||
if (Keyboard.current != null && Keyboard.current[testStartKey].wasPressedThisFrame)
|
||||
{
|
||||
StartWalking();
|
||||
}
|
||||
|
||||
// 테스트용: Y 누르면 일어나기
|
||||
if (Keyboard.current != null && Keyboard.current[testStandUpKey].wasPressedThisFrame)
|
||||
{
|
||||
StandUp();
|
||||
}
|
||||
|
||||
if (!isMoving || agent == null)
|
||||
if (!isMoving || agent == null || !agent.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -102,6 +122,12 @@ void Update()
|
||||
|
||||
public void StartWalking()
|
||||
{
|
||||
if (blockWalkingAfterStandUp && hasStoodUpAfterMatch)
|
||||
{
|
||||
Debug.Log("Hook already stood up after match. StartWalking ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (agent == null)
|
||||
{
|
||||
Debug.LogWarning("NavMeshAgent is missing.");
|
||||
@@ -116,23 +142,28 @@ public void StartWalking()
|
||||
|
||||
if (isMoving || isSitting || isStandingUp)
|
||||
{
|
||||
Debug.Log("Hook cannot start walking now.");
|
||||
return;
|
||||
}
|
||||
|
||||
step = 0;
|
||||
hasArrived = false;
|
||||
isMoving = true;
|
||||
|
||||
EnableHookColliders();
|
||||
|
||||
if (animator != null)
|
||||
{
|
||||
animator.applyRootMotion = false;
|
||||
animator.ResetTrigger(sitTriggerName);
|
||||
animator.ResetTrigger(standTriggerName);
|
||||
animator.SetBool(walkBoolName, true);
|
||||
}
|
||||
|
||||
agent.enabled = true;
|
||||
if (!agent.enabled)
|
||||
{
|
||||
agent.enabled = true;
|
||||
}
|
||||
|
||||
agent.isStopped = false;
|
||||
|
||||
MoveTo(tableFrontPoint);
|
||||
@@ -140,11 +171,18 @@ public void StartWalking()
|
||||
Debug.Log("Hook starts walking to table front point.");
|
||||
}
|
||||
|
||||
void MoveTo(Transform target)
|
||||
private void MoveTo(Transform target)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
Debug.LogWarning("Move target is null.");
|
||||
StopWalking();
|
||||
return;
|
||||
}
|
||||
|
||||
NavMeshHit hit;
|
||||
|
||||
if (NavMesh.SamplePosition(target.position, out hit, 1.5f, NavMesh.AllAreas))
|
||||
if (NavMesh.SamplePosition(target.position, out hit, navMeshSampleDistance, NavMesh.AllAreas))
|
||||
{
|
||||
currentDestination = hit.position;
|
||||
agent.SetDestination(currentDestination);
|
||||
@@ -158,7 +196,7 @@ void MoveTo(Transform target)
|
||||
}
|
||||
}
|
||||
|
||||
void GoNextStep()
|
||||
private void GoNextStep()
|
||||
{
|
||||
step++;
|
||||
|
||||
@@ -173,44 +211,41 @@ void GoNextStep()
|
||||
}
|
||||
}
|
||||
|
||||
void ArriveAndSit()
|
||||
private void ArriveAndSit()
|
||||
{
|
||||
isMoving = false;
|
||||
hasArrived = true;
|
||||
isSitting = true;
|
||||
isStandingUp = false;
|
||||
|
||||
// 1. 이동 중지
|
||||
if (agent != null)
|
||||
if (agent != null && agent.enabled)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
agent.ResetPath();
|
||||
agent.enabled = false;
|
||||
}
|
||||
|
||||
// 2. 앉아 있는 동안 후크 콜라이더 끄기
|
||||
if (disableCollidersWhenSitting)
|
||||
{
|
||||
DisableHookColliders();
|
||||
}
|
||||
|
||||
// 3. 실제 앉을 위치로 강제 이동
|
||||
if (sitPoint != null)
|
||||
{
|
||||
transform.position = sitPoint.position;
|
||||
transform.rotation = sitPoint.rotation;
|
||||
transform.SetPositionAndRotation(sitPoint.position, sitPoint.rotation);
|
||||
}
|
||||
else if (chairFrontPoint != null)
|
||||
{
|
||||
transform.rotation = chairFrontPoint.rotation;
|
||||
}
|
||||
|
||||
// 4. 앉는 애니메이션 실행
|
||||
if (animator != null)
|
||||
{
|
||||
animator.applyRootMotion = false;
|
||||
animator.SetBool(walkBoolName, false);
|
||||
animator.ResetTrigger(standTriggerName);
|
||||
animator.ResetTrigger(sitTriggerName);
|
||||
|
||||
Debug.Log("Sit trigger call: " + sitTriggerName);
|
||||
animator.SetTrigger(sitTriggerName);
|
||||
}
|
||||
|
||||
@@ -219,31 +254,61 @@ void ArriveAndSit()
|
||||
|
||||
public void StandUp()
|
||||
{
|
||||
if (!isSitting || isStandingUp)
|
||||
if (isStandingUp)
|
||||
{
|
||||
Debug.Log("Hook is already standing up.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isSitting)
|
||||
{
|
||||
Debug.LogWarning("Hook is not sitting. StandUp ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
StartCoroutine(StandUpRoutine());
|
||||
}
|
||||
|
||||
IEnumerator StandUpRoutine()
|
||||
private IEnumerator StandUpRoutine()
|
||||
{
|
||||
isStandingUp = true;
|
||||
isSitting = false;
|
||||
isMoving = false;
|
||||
|
||||
if (agent != null && agent.enabled)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
agent.ResetPath();
|
||||
agent.enabled = false;
|
||||
}
|
||||
|
||||
if (animator != null)
|
||||
{
|
||||
animator.applyRootMotion = false;
|
||||
|
||||
animator.SetBool(walkBoolName, false);
|
||||
animator.ResetTrigger(sitTriggerName);
|
||||
animator.ResetTrigger(standTriggerName);
|
||||
|
||||
Debug.Log("Stand trigger call: " + standTriggerName);
|
||||
animator.SetTrigger(standTriggerName);
|
||||
|
||||
if (forcePlayStandState && !string.IsNullOrEmpty(standStateName))
|
||||
{
|
||||
animator.CrossFadeInFixedTime(standStateName, 0.08f, 0);
|
||||
Debug.Log("Force play stand state: " + standStateName);
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log("Hook started stand up animation.");
|
||||
|
||||
yield return new WaitForSeconds(standUpDuration);
|
||||
|
||||
if (standPoint != null)
|
||||
{
|
||||
transform.SetPositionAndRotation(standPoint.position, standPoint.rotation);
|
||||
}
|
||||
|
||||
if (enableCollidersAfterStandUp)
|
||||
{
|
||||
EnableHookColliders();
|
||||
@@ -251,18 +316,51 @@ IEnumerator StandUpRoutine()
|
||||
|
||||
if (agent != null)
|
||||
{
|
||||
agent.enabled = true;
|
||||
agent.isStopped = true;
|
||||
agent.ResetPath();
|
||||
if (disableAgentAfterStandUp)
|
||||
{
|
||||
agent.enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!agent.enabled)
|
||||
{
|
||||
agent.enabled = true;
|
||||
}
|
||||
|
||||
agent.isStopped = true;
|
||||
agent.ResetPath();
|
||||
}
|
||||
}
|
||||
|
||||
hasArrived = false;
|
||||
hasStoodUpAfterMatch = true;
|
||||
isStandingUp = false;
|
||||
|
||||
Debug.Log("Hook stood up.");
|
||||
}
|
||||
|
||||
void DisableHookColliders()
|
||||
public void ResetHookAfterMatchBlock()
|
||||
{
|
||||
hasStoodUpAfterMatch = false;
|
||||
Debug.Log("Hook StartWalking block reset.");
|
||||
}
|
||||
|
||||
private void StopWalking()
|
||||
{
|
||||
isMoving = false;
|
||||
|
||||
if (agent != null && agent.enabled)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
agent.ResetPath();
|
||||
}
|
||||
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetBool(walkBoolName, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void DisableHookColliders()
|
||||
{
|
||||
if (hookColliders == null || hookColliders.Length == 0)
|
||||
{
|
||||
@@ -278,7 +376,7 @@ void DisableHookColliders()
|
||||
}
|
||||
}
|
||||
|
||||
void EnableHookColliders()
|
||||
private void EnableHookColliders()
|
||||
{
|
||||
if (hookColliders == null || hookColliders.Length == 0)
|
||||
{
|
||||
@@ -293,20 +391,4 @@ void EnableHookColliders()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StopWalking()
|
||||
{
|
||||
isMoving = false;
|
||||
|
||||
if (agent != null && agent.enabled)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
agent.ResetPath();
|
||||
}
|
||||
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetBool(walkBoolName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user