1
This commit is contained in:
59
Packages/Common~/Extensions/AI/EntityAi.cs
Normal file
59
Packages/Common~/Extensions/AI/EntityAi.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user