OldBlueWater/BlueWater/Assets/02.Scripts/Ai/AiMover.cs

67 lines
1.7 KiB
C#
Raw Normal View History

2023-08-08 07:53:35 +00:00
using System;
using UnityEngine;
using UnityEngine.AI;
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
public class AiMover : MonoBehaviour
{
private enum MoveType
{
NONE, // 미설정
FIXED, // 자리를 지키는 AI
MOVE // 자리를 움직이는 AI
}
#region Property and variable
[SerializeField] private MoveType moveType;
private bool isCommanded;
private Vector3 movePos;
private AiController aiController;
#endregion
#region Unity built-in function
private void Awake()
{
aiController = Utils.GetComponentAndAssert<AiController>(transform);
}
private void LateUpdate()
{
aiController.GetAnimator().SetFloat(AiController.SpeedHash, aiController.GetNavMeshAgent().velocity.normalized.magnitude);
if (isCommanded || aiController.GetIsAttacking())
{
}
else
{
if (!GetTargetInfo().transform || moveType is MoveType.NONE or MoveType.FIXED) return;
2023-08-08 07:53:35 +00:00
GetNavMeshAgent().SetDestination(GetTargetInfo().transform.position);
2023-08-08 07:53:35 +00:00
}
}
#endregion
#region Custom function
public void MoveTarget(Vector3 targetPos)
{
isCommanded = true;
GetNavMeshAgent().SetDestination(targetPos);
}
2023-08-08 07:53:35 +00:00
public bool GetIsCommanded() => isCommanded;
private TargetInfo GetTargetInfo() => aiController.TargetInfo;
2023-08-08 07:53:35 +00:00
private NavMeshAgent GetNavMeshAgent() => aiController.GetNavMeshAgent();
#endregion
}
}