Add BehaviorTreeKnowledgeBooleanDecorator

This commit is contained in:
Wojtek Figat
2024-03-05 12:45:40 +01:00
parent b506295b7b
commit d5f4254a73
2 changed files with 29 additions and 0 deletions

View File

@@ -706,6 +706,14 @@ bool BehaviorTreeKnowledgeValuesConditionalDecorator::CanUpdate(const BehaviorUp
return BehaviorKnowledge::CompareValues((float)ValueA.Get(context.Knowledge), (float)ValueB.Get(context.Knowledge), Comparison);
}
bool BehaviorTreeKnowledgeBooleanDecorator::CanUpdate(const BehaviorUpdateContext& context)
{
Variant value = Value.Get(context.Knowledge);
bool result = (bool)value;
result ^= Invert;
return result;
}
bool BehaviorTreeHasTagDecorator::CanUpdate(const BehaviorUpdateContext& context)
{
bool result = false;

View File

@@ -445,6 +445,27 @@ public:
bool CanUpdate(const BehaviorUpdateContext& context) override;
};
/// <summary>
/// Checks certain knowledge value to conditionally enter the node if the value is set (eg. not-null object reference or boolean value).
/// </summary>
API_CLASS(Sealed) class FLAXENGINE_API BehaviorTreeKnowledgeBooleanDecorator : public BehaviorTreeDecorator
{
DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(BehaviorTreeKnowledgeBooleanDecorator, BehaviorTreeDecorator);
API_AUTO_SERIALIZATION();
// The value from behavior's knowledge (blackboard, goal or sensor) to check if it's set (eg. not-null object reference or boolean value).
API_FIELD(Attributes="EditorOrder(0)")
BehaviorKnowledgeSelectorAny Value;
// If checked, the condition will be inverted.
API_FIELD(Attributes="EditorOrder(10)")
bool Invert = false;
public:
// [BehaviorTreeNode]
bool CanUpdate(const BehaviorUpdateContext& context) override;
};
/// <summary>
/// Checks if certain actor (from knowledge) has a given tag assigned.
/// </summary>