From 8050d0d19efa153fc93e3f831e97d73c11cd7c22 Mon Sep 17 00:00:00 2001 From: Jeonghyeon Ha Date: Thu, 28 Aug 2025 11:24:44 +0900 Subject: [PATCH] =?UTF-8?q?AIMoveTo=20=EB=94=94=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=EC=9A=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/Actions/MoveToInteractionTarget.cs | 78 ++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/AI/Common/Actions/MoveToInteractionTarget.cs b/Assets/_DDD/_Scripts/Restaurant/Character/AI/Common/Actions/MoveToInteractionTarget.cs index 9bf125e0f..602f24ab2 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/AI/Common/Actions/MoveToInteractionTarget.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/AI/Common/Actions/MoveToInteractionTarget.cs @@ -1,5 +1,6 @@ using Opsive.BehaviorDesigner.Runtime.Tasks; using Opsive.BehaviorDesigner.Runtime.Tasks.Actions; +using Unity.VisualScripting; using UnityEngine; namespace DDD.Restaurant @@ -19,6 +20,14 @@ public class MoveToInteractionTarget : Action [Tooltip("목적지 재계산 주기(초), 0 이하면 비활성화")] [SerializeField] private float repathInterval = 0.5f; + [Header("Debug Settings")] + [Tooltip("디버그 드로우 활성화")] + [SerializeField] private bool enableDebugDraw = true; + [Tooltip("디버그 선 색상")] + [SerializeField] private Color debugLineColor = Color.red; + [Tooltip("타겟 위치 기즈모 색상")] + [SerializeField] private Color targetGizmoColor = Color.yellow; + private IAiMovement _movement; private float _repathTimer; private Vector3 _currentDestination; @@ -49,7 +58,7 @@ public override TaskStatus OnUpdate() _currentDestination = CalculateDestination(_target); StartOrUpdateMovement(); } - + return CheckMovementCompletion(); } @@ -57,6 +66,73 @@ public override void OnEnd() { StopMovement(); } + + protected override void OnDrawGizmos() + { + if (!enableDebugDraw || _target == null) return; + + // 타겟 이름을 자신의 게임오브젝트 위에 표시 +#if UNITY_EDITOR + UnityEditor.Handles.Label(transform.position + Vector3.up * 2f, + $"Target: {_target.name}"); +#endif + + // 타겟 위치에 기즈모 그리기 + Gizmos.color = targetGizmoColor; + if (_isMoving && _currentDestination != Vector3.zero) + { + Gizmos.DrawWireSphere(_currentDestination, 0.5f); + } + else if (_target != null) + { + Gizmos.DrawWireSphere(_target.transform.position, 0.5f); + } + + // 현재 위치에서 타겟까지 직선 그리기 + Gizmos.color = debugLineColor; + Vector3 targetPos = _isMoving && _currentDestination != Vector3.zero + ? _currentDestination + : (_target != null ? _target.transform.position : Vector3.zero); + + if (targetPos != Vector3.zero) + { + Gizmos.DrawLine(transform.position, targetPos); + } + + // 현재 오브젝트 위치에 작은 기즈모 그리기 + Gizmos.color = Color.blue; + Gizmos.DrawWireCube(transform.position, Vector3.one * 0.3f); + } + + protected override void OnDrawGizmosSelected() + { + if (!enableDebugDraw || _target == null) return; + + // 선택되었을 때 추가 정보 표시 +#if UNITY_EDITOR + Vector3 targetPos = _isMoving && _currentDestination != Vector3.zero + ? _currentDestination + : _target.transform.position; + + float distance = Vector3.Distance(transform.position, targetPos); + UnityEditor.Handles.Label(targetPos + Vector3.up * 1f, + $"Distance: {distance:F2}m\nStopping: {stoppingDistance:F2}m"); + + // InteractionPoints가 있다면 모두 표시 + if (useInteractionPoints && _target.TryGetComponent(out var ric)) + { + var points = ric.GetInteractionPoints(); + if (points != null && points.Length > 0) + { + Gizmos.color = Color.cyan; + foreach (var point in points) + { + Gizmos.DrawWireSphere(point, 0.2f); + } + } + } +#endif + } private bool ShouldUpdateDestination() {