33 lines
944 B
C++
33 lines
944 B
C++
#include "behaviour_node.h"
|
|
#include "behaviour_nodes/behaviour_tree.h"
|
|
#include "core/config/engine.h"
|
|
#include "core/object/class_db.h"
|
|
#include "macros.h"
|
|
|
|
void BehaviourNode::_bind_methods() {
|
|
BIND_ENUM_CONSTANT(Fail);
|
|
BIND_ENUM_CONSTANT(Running);
|
|
BIND_ENUM_CONSTANT(Success);
|
|
ClassDB::bind_method(D_METHOD("get_behaviour_tree"), &self_type::get_behaviour_tree);
|
|
BIND_HPROPERTY(Variant::INT, status, PROPERTY_HINT_ENUM, Status_hint(), PROPERTY_USAGE_NO_EDITOR);
|
|
}
|
|
|
|
void BehaviourNode::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
default:
|
|
return;
|
|
case NOTIFICATION_ENTER_TREE:
|
|
Node *parent{ get_parent() };
|
|
this->parent = cast_to<BehaviourNode>(parent);
|
|
while (this->behaviour_tree == nullptr && parent != nullptr) {
|
|
if ((this->behaviour_tree = cast_to<BehaviourTree>(parent))) {
|
|
break;
|
|
}
|
|
parent = parent->get_parent();
|
|
}
|
|
return;
|
|
}
|
|
}
|