112 lines
4.4 KiB
C#
112 lines
4.4 KiB
C#
![]() |
using System;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.AI;
|
||
|
using UnityEngine.Animations;
|
||
|
|
||
|
// ReSharper disable once CheckNamespace
|
||
|
namespace BlueWaterProject
|
||
|
{
|
||
|
public class HumanAi : BaseAi
|
||
|
{
|
||
|
#region Properties and variables
|
||
|
|
||
|
// 모델링 관련 변수
|
||
|
protected Transform backpackContainer;
|
||
|
protected Transform leftWeaponContainer;
|
||
|
protected Transform leftShieldContainer;
|
||
|
protected Transform headContainer;
|
||
|
protected Transform rightWeaponContainer;
|
||
|
protected Transform bodyContainer;
|
||
|
protected Transform flagContainer;
|
||
|
|
||
|
// 컴포넌트 관련 변수
|
||
|
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 Unity built-in methods
|
||
|
|
||
|
protected virtual void Awake()
|
||
|
{
|
||
|
InitComponent();
|
||
|
FlagLookAtFlag();
|
||
|
}
|
||
|
|
||
|
protected void Start()
|
||
|
{
|
||
|
InitStart();
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region Custom methods
|
||
|
|
||
|
protected virtual void InitComponent()
|
||
|
{
|
||
|
backpackContainer = Utils.GetComponentAndAssert<Transform>(transform.
|
||
|
Find("Bip001/Bip001 Pelvis/Bip001 Spine/Backpack_container"));
|
||
|
leftWeaponContainer = Utils.GetComponentAndAssert<Transform>(transform.
|
||
|
Find("Bip001/Bip001 Pelvis/Bip001 Spine/Bip001 L Clavicle/Bip001 L UpperArm/Bip001 L Forearm/Bip001 L Hand/L_hand_container"));
|
||
|
leftShieldContainer = Utils.GetComponentAndAssert<Transform>(transform.
|
||
|
Find("Bip001/Bip001 Pelvis/Bip001 Spine/Bip001 L Clavicle/Bip001 L UpperArm/Bip001 L Forearm/Bip001 L Hand/L_shield_container"));
|
||
|
headContainer = Utils.GetComponentAndAssert<Transform>(transform.
|
||
|
Find("Bip001/Bip001 Pelvis/Bip001 Spine/Bip001 Neck/Bip001 Head/Head_container"));
|
||
|
rightWeaponContainer = Utils.GetComponentAndAssert<Transform>(transform.
|
||
|
Find("Bip001/Bip001 Pelvis/Bip001 Spine/Bip001 R Clavicle/Bip001 R UpperArm/Bip001 R Forearm/Bip001 R Hand/R_hand_container"));
|
||
|
bodyContainer = Utils.GetComponentAndAssert<Transform>(transform.
|
||
|
Find("Body_container"));
|
||
|
flagContainer = Utils.GetComponentAndAssert<Transform>(transform.
|
||
|
Find("Flag_container"));
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
protected virtual void InitStart()
|
||
|
{
|
||
|
// var getAiViewData = GetAiViewData(false);
|
||
|
//
|
||
|
// InitViewModel(false);
|
||
|
// FindMaterial();
|
||
|
// SetLayer();
|
||
|
// SetCloseWeapon(getAiViewData);
|
||
|
// SetCurrentHp(AiStat.MaxHp);
|
||
|
// SetMoveSpeed(AiStat.MoveSpd);
|
||
|
//
|
||
|
// DefensePos = transform.position;
|
||
|
}
|
||
|
|
||
|
private void FlagLookAtFlag()
|
||
|
{
|
||
|
if (Camera.main != null)
|
||
|
{
|
||
|
var source = new ConstraintSource
|
||
|
{
|
||
|
sourceTransform = Camera.main.transform,
|
||
|
weight = 1f
|
||
|
};
|
||
|
lookAtConstraint.AddSource(source);
|
||
|
}
|
||
|
|
||
|
lookAtConstraint.constraintActive = true;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|