BITKit/Src/UnityPluginsSupport/NodeCanvas/EntityBehaviourTree.cs

55 lines
1.1 KiB
C#
Raw Normal View History

2023-06-29 14:57:11 +08:00
using System.Collections;
using System.Collections.Generic;
using BITKit.Entities;
using NodeCanvas.BehaviourTrees;
using NodeCanvas.Framework;
using UnityEngine;
namespace BITKit
{
2023-11-06 01:17:23 +08:00
public class EntityBehaviourTree :EntityBehavior
2023-06-29 14:57:11 +08:00
{
2023-08-11 23:57:37 +08:00
public BehaviourTreeOwner behaviourTree;
2023-06-29 14:57:11 +08:00
[SerializeField] private Blackboard blackboard;
private readonly ValidHandle _allow=new();
2023-10-24 23:38:22 +08:00
[Inject] private IHealth _health;
[Inject(true)] private IEntityOverride _override;
2023-06-29 14:57:11 +08:00
public override void OnAwake()
{
_allow.AddListener(OnAllow);
2023-10-24 23:38:22 +08:00
_health.OnSetAlive += OnSetAlive;
_health.OnSetHealthPoint += OnSetHP;
_override.OnOverride += OnEntryOverride;
2023-06-29 14:57:11 +08:00
}
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();
}
}
}
}