OldBlueWater/BlueWater/Assets/02.Scripts/Ai/Human/Combat/CombatAi.cs
2023-09-13 16:05:21 +09:00

93 lines
3.1 KiB
C#

using System;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Animations;
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
public abstract class CombatAi : HumanAi
{
#region Properties and variables
// 일반 변수
protected bool isDrawGizmosInFieldOfView = true;
protected LayerMask targetLayer;
protected Vector3 defensePos;
protected IslandInfo attackingIslandInfo;
// 컴포넌트 관련 변수
protected Animator combatAnimator;
protected NavMeshAgent humanAgent;
protected CapsuleCollider myCollider;
protected CapsuleCollider hitBoxCollider;
protected LookAtConstraint lookAtConstraint;
// 애니메이션 관련 변수
protected static readonly int SpeedHash = Animator.StringToHash("Speed");
protected static readonly int AttackHash = Animator.StringToHash("Attack");
protected static readonly int DamageHash = Animator.StringToHash("TakeDamage");
protected static readonly int DeathTypeHash = Animator.StringToHash("DeathType");
protected static readonly int DeathHash = Animator.StringToHash("Death");
protected static readonly int ShieldHash = Animator.StringToHash("Shield");
protected static readonly int OutlineColorHash = Shader.PropertyToID("_OutlineColor");
#endregion
#region Abstract methods
protected abstract void SetLayer();
protected abstract void SetCurrentHp(float value);
#endregion
#region Unity built-in methods
protected override void Awake()
{
base.Awake();
FlagLookAtCamera();
SetLayer();
}
#endregion
#region Custom methods
protected override void InitComponent()
{
base.InitComponent();
combatAnimator = Utils.GetComponentAndAssert<Animator>(transform);
humanAgent = Utils.GetComponentAndAssert<NavMeshAgent>(transform);
myCollider = Utils.GetComponentAndAssert<CapsuleCollider>(transform);
hitBoxCollider = Utils.GetComponentAndAssert<CapsuleCollider>(transform.Find("HitBox"));
lookAtConstraint = Utils.GetComponentAndAssert<LookAtConstraint>(flagContainer);
}
protected void FlagLookAtCamera()
{
if (Camera.main != null)
{
var source = new ConstraintSource
{
sourceTransform = Camera.main.transform,
weight = 1f
};
lookAtConstraint.AddSource(source);
}
lookAtConstraint.constraintActive = true;
}
protected void SetAnimatorController(string controllerName) => combatAnimator.runtimeAnimatorController =
UnitManager.Inst.AIAnimatorControllerList.Find(obj => obj.name == controllerName);
protected void SetMoveSpeed(float value) => humanAgent.speed = value;
public void SetIslandInfo(IslandInfo info) => attackingIslandInfo = info;
#endregion
}
}