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(transform); humanAgent = Utils.GetComponentAndAssert(transform); myCollider = Utils.GetComponentAndAssert(transform); hitBoxCollider = Utils.GetComponentAndAssert(transform.Find("HitBox")); lookAtConstraint = Utils.GetComponentAndAssert(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 } }