OldBlueWater/BlueWater/Assets/02.Scripts/Ai/Human/Combat/CombatAi.cs

93 lines
3.1 KiB
C#
Raw Normal View History

2023-09-13 03:23:27 +00:00
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
// 일반 변수
2023-09-13 07:05:21 +00:00
protected bool isDrawGizmosInFieldOfView = true;
2023-09-13 03:23:27 +00:00
protected LayerMask targetLayer;
protected Vector3 defensePos;
2023-09-13 07:05:21 +00:00
protected IslandInfo attackingIslandInfo;
2023-09-13 03:23:27 +00:00
// 컴포넌트 관련 변수
2023-09-13 07:05:21 +00:00
protected Animator combatAnimator;
2023-09-13 03:23:27 +00:00
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()
{
2023-09-13 07:05:21 +00:00
base.Awake();
2023-09-13 03:23:27 +00:00
FlagLookAtCamera();
SetLayer();
}
#endregion
#region Custom methods
protected override void InitComponent()
{
base.InitComponent();
2023-09-13 07:05:21 +00:00
combatAnimator = Utils.GetComponentAndAssert<Animator>(transform);
2023-09-13 03:23:27 +00:00
humanAgent = Utils.GetComponentAndAssert<NavMeshAgent>(transform);
myCollider = Utils.GetComponentAndAssert<CapsuleCollider>(transform);
hitBoxCollider = Utils.GetComponentAndAssert<CapsuleCollider>(transform.Find("HitBox"));
lookAtConstraint = Utils.GetComponentAndAssert<LookAtConstraint>(flagContainer);
}
2023-09-13 07:05:21 +00:00
protected void FlagLookAtCamera()
2023-09-13 03:23:27 +00:00
{
if (Camera.main != null)
{
var source = new ConstraintSource
{
sourceTransform = Camera.main.transform,
weight = 1f
};
lookAtConstraint.AddSource(source);
}
lookAtConstraint.constraintActive = true;
}
2023-09-13 07:05:21 +00:00
protected void SetAnimatorController(string controllerName) => combatAnimator.runtimeAnimatorController =
UnitManager.Inst.AIAnimatorControllerList.Find(obj => obj.name == controllerName);
2023-09-13 03:23:27 +00:00
protected void SetMoveSpeed(float value) => humanAgent.speed = value;
2023-09-13 07:05:21 +00:00
public void SetIslandInfo(IslandInfo info) => attackingIslandInfo = info;
2023-09-13 03:23:27 +00:00
#endregion
}
}