Add Force Finish node to BT
This commit is contained in:
@@ -26,12 +26,12 @@ void Behavior::StartLogic()
|
|||||||
_knowledge.InitMemory(tree);
|
_knowledge.InitMemory(tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Behavior::StopLogic()
|
void Behavior::StopLogic(BehaviorUpdateResult result)
|
||||||
{
|
{
|
||||||
if (_result != BehaviorUpdateResult::Running)
|
if (_result != BehaviorUpdateResult::Running || result == BehaviorUpdateResult::Running)
|
||||||
return;
|
return;
|
||||||
_accumulatedTime = 0.0f;
|
_accumulatedTime = 0.0f;
|
||||||
_result = BehaviorUpdateResult::Success;
|
_result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Behavior::ResetLogic()
|
void Behavior::ResetLogic()
|
||||||
@@ -83,8 +83,9 @@ void Behavior::OnLateUpdate()
|
|||||||
context.DeltaTime = updateDeltaTime;
|
context.DeltaTime = updateDeltaTime;
|
||||||
const BehaviorUpdateResult result = tree->Graph.Root->InvokeUpdate(context);
|
const BehaviorUpdateResult result = tree->Graph.Root->InvokeUpdate(context);
|
||||||
if (result != BehaviorUpdateResult::Running)
|
if (result != BehaviorUpdateResult::Running)
|
||||||
{
|
|
||||||
_result = result;
|
_result = result;
|
||||||
|
if (_result != BehaviorUpdateResult::Running)
|
||||||
|
{
|
||||||
Finished();
|
Finished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stops the logic.
|
/// Stops the logic.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
API_FUNCTION() void StopLogic();
|
/// <param name="result">The logic result.</param>
|
||||||
|
API_FUNCTION() void StopLogic(BehaviorUpdateResult result = BehaviorUpdateResult::Success);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resets the behavior logic by clearing knowledge (clears blackboard and removes goals) and resetting execution state (goes back to root).
|
/// Resets the behavior logic by clearing knowledge (clears blackboard and removes goals) and resetting execution state (goes back to root).
|
||||||
|
|||||||
@@ -246,3 +246,9 @@ BehaviorUpdateResult BehaviorTreeSubTreeNode::Update(BehaviorUpdateContext conte
|
|||||||
// Run nested tree
|
// Run nested tree
|
||||||
return tree->Graph.Root->InvokeUpdate(context);
|
return tree->Graph.Root->InvokeUpdate(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BehaviorUpdateResult BehaviorTreeForceFinishNode::Update(BehaviorUpdateContext context)
|
||||||
|
{
|
||||||
|
context.Behavior->StopLogic(Result);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -141,3 +141,19 @@ public:
|
|||||||
BitArray<> RelevantNodes;
|
BitArray<> RelevantNodes;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Forces behavior execution end with a specific result (eg. force fail).
|
||||||
|
/// </summary>
|
||||||
|
API_CLASS(Sealed) class FLAXENGINE_API BehaviorTreeForceFinishNode : public BehaviorTreeNode
|
||||||
|
{
|
||||||
|
DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(BehaviorTreeForceFinishNode, BehaviorTreeNode);
|
||||||
|
API_AUTO_SERIALIZATION();
|
||||||
|
|
||||||
|
// Execution result.
|
||||||
|
API_FIELD() BehaviorUpdateResult Result = BehaviorUpdateResult::Success;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [BehaviorTreeNode]
|
||||||
|
BehaviorUpdateResult Update(BehaviorUpdateContext context) override;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user