53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit.Entities;
|
|
using NodeCanvas.BehaviourTrees;
|
|
using NodeCanvas.Framework;
|
|
using UnityEngine;
|
|
|
|
namespace BITKit
|
|
{
|
|
public class EntityBehaviourTree :EntityComponent, IHealthCallback,IEntityOverrideCallback
|
|
{
|
|
public BehaviourTreeOwner behaviourTree;
|
|
[SerializeField] private Blackboard blackboard;
|
|
|
|
private readonly ValidHandle _allow=new();
|
|
|
|
public override void OnAwake()
|
|
{
|
|
entity.RegisterCallback<IHealthCallback>(this);
|
|
entity.RegisterCallback<IEntityOverrideCallback>(this);
|
|
|
|
_allow.AddListener(OnAllow);
|
|
}
|
|
|
|
public void OnSetAlive(bool alive)
|
|
{
|
|
_allow.SetElements(this,alive);
|
|
blackboard.SetVariableValue("IsAlive", alive);
|
|
}
|
|
public void OnSetHP(int hp)
|
|
{
|
|
blackboard.SetVariableValue("HP", hp);
|
|
}
|
|
|
|
public void OnEntryOverride(bool @override)
|
|
{
|
|
_allow.SetDisableElements(this,@override);
|
|
}
|
|
private void OnAllow(bool allow)
|
|
{
|
|
if (allow)
|
|
{
|
|
behaviourTree.StartBehaviour();
|
|
}
|
|
else
|
|
{
|
|
behaviourTree.StopBehaviour();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|