2024-02-12 20:50:24 +00:00
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
namespace BlueWaterProject
|
|
|
|
{
|
2024-03-05 03:47:17 +00:00
|
|
|
public class Patrol : MonoBehaviour
|
2024-02-12 20:50:24 +00:00
|
|
|
{
|
|
|
|
/***********************************************************************
|
|
|
|
* Variables
|
|
|
|
***********************************************************************/
|
|
|
|
#region Variables
|
|
|
|
|
|
|
|
// 패트롤 옵션
|
|
|
|
[Title("패트롤 옵션")]
|
|
|
|
[SerializeField] private bool showWayPointGizmo = true;
|
2024-03-05 03:47:17 +00:00
|
|
|
[field: SerializeField] public WayPointInfo[] WayPoints { get; set; }
|
2024-02-12 20:50:24 +00:00
|
|
|
[field: SerializeField] public Vector3 OriginalPoint { get; set; }
|
|
|
|
[field: SerializeField] public int CurrentIndex { get; set; }
|
|
|
|
[field: SerializeField] public int PreviousIndex { get; set; }
|
|
|
|
|
|
|
|
// 기즈모 잠금 기능
|
|
|
|
[Title("기즈모 잠금 기능")]
|
|
|
|
[field: SerializeField] public bool LockHandlesOnXAxis { get; set; }
|
|
|
|
[field: SerializeField] public bool LockHandlesOnYAxis { get; set; }
|
|
|
|
[field: SerializeField] public bool LockHandlesOnZAxis { get; set; }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Unity Events
|
|
|
|
***************************************************************m********/
|
|
|
|
#region Unity Events
|
|
|
|
|
|
|
|
private void OnDrawGizmosSelected()
|
|
|
|
{
|
|
|
|
if (WayPoints == null || WayPoints.Length <= 0 || !showWayPointGizmo) return;
|
|
|
|
|
|
|
|
if (!Application.isPlaying)
|
|
|
|
{
|
2024-03-05 03:47:17 +00:00
|
|
|
OriginalPoint = transform.position;
|
2024-02-12 20:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < WayPoints.Length; i++)
|
|
|
|
{
|
|
|
|
var currentColor = i == CurrentIndex ? Color.blue : Color.yellow;
|
|
|
|
|
|
|
|
if ((i + 1) < WayPoints.Length)
|
|
|
|
{
|
|
|
|
Gizmos.color = currentColor;
|
|
|
|
Gizmos.DrawLine(OriginalPoint + WayPoints[i].Point, OriginalPoint + WayPoints[i + 1].Point);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == WayPoints.Length - 1)
|
|
|
|
{
|
|
|
|
Gizmos.color = currentColor;
|
|
|
|
Gizmos.DrawLine(OriginalPoint + WayPoints[i].Point, OriginalPoint + WayPoints[0].Point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Application.isPlaying) return;
|
|
|
|
|
|
|
|
DrawGizmoPoint(OriginalPoint + WayPoints[CurrentIndex].Point,2f, Color.blue);
|
|
|
|
DrawGizmoPoint(OriginalPoint + WayPoints[PreviousIndex].Point, 2f, Color.red);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void DrawGizmoPoint(Vector3 pos, float size, Color color)
|
|
|
|
{
|
|
|
|
Gizmos.color = color;
|
|
|
|
Gizmos.DrawWireSphere(pos, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
OriginalPoint = transform.position;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Methods
|
|
|
|
***********************************************************************/
|
|
|
|
#region Methods
|
|
|
|
|
2024-03-05 03:47:17 +00:00
|
|
|
public WayPointInfo GetCurrentWayPointInfo() => WayPoints[CurrentIndex];
|
|
|
|
public Vector3 GetCurrentWayPoint() => OriginalPoint + WayPoints[CurrentIndex].Point;
|
2024-02-12 20:50:24 +00:00
|
|
|
|
|
|
|
public int GetNextIndex()
|
|
|
|
{
|
|
|
|
if (WayPoints == null) return -1;
|
|
|
|
|
|
|
|
var maxSize = WayPoints.Length;
|
|
|
|
var nextIndex = CurrentIndex + 1;
|
|
|
|
|
|
|
|
if (nextIndex >= maxSize)
|
|
|
|
{
|
|
|
|
nextIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool HasReachedDestination()
|
|
|
|
{
|
2024-03-05 03:47:17 +00:00
|
|
|
var myPosition = transform.position;
|
2024-02-12 20:50:24 +00:00
|
|
|
var movePoint = OriginalPoint + WayPoints[CurrentIndex].Point;
|
|
|
|
var distance = Vector3.Distance(myPosition, movePoint);
|
|
|
|
|
|
|
|
if (distance > 3f) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetMovePoint()
|
|
|
|
{
|
2024-03-05 03:47:17 +00:00
|
|
|
if (WayPoints == null || WayPoints.Length <= CurrentIndex) return;
|
2024-02-12 20:50:24 +00:00
|
|
|
|
|
|
|
PreviousIndex = CurrentIndex;
|
|
|
|
CurrentIndex = GetNextIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|