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