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

87 lines
2.7 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
// 일반 변수
protected LayerMask targetLayer;
protected Vector3 defensePos;
// 컴포넌트 관련 변수
protected Animator humanAnimator;
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.InitComponent();
FlagLookAtCamera();
SetLayer();
}
#endregion
#region Custom methods
protected override void InitComponent()
{
base.InitComponent();
humanAnimator = 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);
}
private void FlagLookAtCamera()
{
if (Camera.main != null)
{
var source = new ConstraintSource
{
sourceTransform = Camera.main.transform,
weight = 1f
};
lookAtConstraint.AddSource(source);
}
lookAtConstraint.constraintActive = true;
}
protected void SetMoveSpeed(float value) => humanAgent.speed = value;
#endregion
}
}