CapersProject/Assets/02.Scripts/Character/AiMovement.cs
Nam Tae Gun 51798c3346 #16 SandMole(모래 두더지) 보스 추가 중
+ AiMovement 클래스 재생성 및 초기화 방식 변경
+ AnimationController 클래스 초기화 방식 변경
+ MapManager, MapController 로직 수정
+ BaseBoss 프리팹 수정
+ SandMole 보스에 맞게 맵 추가
+ 임시 SandMole, GhostBarrel 이미지 추가
+ 기존 GroundGreen, GroundRed 스프라이트 정사각형으로 변경, 수정에 따라 BaseMapController Ground, Wall 수정
+ 코뿔소 맵 투명화 Props 추가

Closes #12
2024-06-14 01:46:37 +09:00

101 lines
2.2 KiB
C#

using Pathfinding;
using UnityEngine;
namespace BlueWater.Enemies
{
public class AiMovement : MonoBehaviour
{
// Variables
#region Variables
private IAstarAI _iAstarAi;
#endregion
// Unity events
#region Unity events
private void Awake()
{
InitializeComponents();
}
#endregion
// Initialize methods
#region Initialize methods
private void InitializeComponents()
{
_iAstarAi = GetComponent<IAstarAI>();
}
#endregion
// Methods
#region Methods
public void EnableMove()
{
if (_iAstarAi == null) return;
_iAstarAi.isStopped = false;
_iAstarAi.canMove = true;
}
public void StopMove()
{
if (_iAstarAi == null) return;
_iAstarAi.isStopped = true;
_iAstarAi.canMove = false;
_iAstarAi.SetPath(null);
}
public void Move(Vector3 position)
{
if (_iAstarAi == null) return;
_iAstarAi.destination = position;
EnableMove();
}
public void MoveTarget(Collider target)
{
if (!target)
{
StopMove();
return;
}
Move(target.transform.position);
}
public void Teleport(Vector3 position)
{
_iAstarAi?.Teleport(position);
}
public bool HasReachedDestination()
{
return _iAstarAi is { pathPending: false, reachedEndOfPath: true };
}
public void SetMoveSpeed(float speed)
{
if (_iAstarAi == null) return;
_iAstarAi.maxSpeed = speed;
}
public bool IsPositionMovable(Vector3 startPosition, Vector3 endPosition)
{
var startNode = AstarPath.active.GetNearest(startPosition).node;
var endNode = AstarPath.active.GetNearest(endPosition).node;
return PathUtilities.IsPathPossible(startNode, endNode);
}
#endregion
}
}