59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using NodeCanvas.Framework;
|
|
using Mirror;
|
|
namespace BITKit.Entities
|
|
{
|
|
public enum AIState
|
|
{
|
|
None,
|
|
Idle,
|
|
Movement,
|
|
Alert,
|
|
HitStop,
|
|
Attack,
|
|
Escape,
|
|
Seek,
|
|
}
|
|
public class EntityAi : EntityComponent
|
|
{
|
|
[Header(Constant.Header.Data)]
|
|
public AIState currentState;
|
|
[Header(Constant.Header.Components)]
|
|
public GraphOwner graph;
|
|
[Header(Constant.Header.Reference)]
|
|
[SerializeReference, SubclassSelector] public References _onGetDamage;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
entity.AddListener<bool>(nameof(OnSetAlive), OnSetAlive);
|
|
entity.AddListener<DamageMessage>(OnDamage);
|
|
}
|
|
public override void OnStopServer()
|
|
{
|
|
graph.StopBehaviour();
|
|
}
|
|
void OnSetAlive(bool alive)
|
|
{
|
|
if (isServer)
|
|
{
|
|
if (alive)
|
|
{
|
|
graph.StartBehaviour();
|
|
}
|
|
else
|
|
{
|
|
graph.StopBehaviour();
|
|
}
|
|
}
|
|
}
|
|
void OnDamage(DamageMessage damageMessage)
|
|
{
|
|
if (damageMessage.target == entity)
|
|
{
|
|
graph.SendEvent<DamageMessage>(_onGetDamage, damageMessage, this);
|
|
}
|
|
}
|
|
}
|
|
} |