Add red/green highlights to debug BT node decorator result

This commit is contained in:
2026-09-24 22:57:06 +02:00
parent d56fdcce57
commit 0d4ea64caa
6 changed files with 39 additions and 2 deletions
+2
View File
@@ -299,6 +299,7 @@ namespace FlaxEditor.Options
TextBoxBackgroundSelected = Color.FromBgra(0xFF3F3F46),
CollectionBackgroundColor = Color.FromBgra(0x14CCCCCC),
ProgressNormal = Color.FromBgra(0xFF0ad328),
ProgressError = new Color(0.79f, 0.146f, 0.0f, 1.0f),
Selection = Color.Orange * 0.4f,
SelectionBorder = Color.Orange,
@@ -362,6 +363,7 @@ namespace FlaxEditor.Options
TextBoxBackgroundSelected = new Color(0.73f, 0.73f, 0.80f, 1f),
CollectionBackgroundColor = new Color(0.85f, 0.85f, 0.88f, 1f),
ProgressNormal = new Color(0.03f, 0.65f, 0.12f, 1f),
ProgressError = new Color(0.79f, 0.146f, 0.0f, 1.0f),
Selection = Color.Orange * 0.4f,
SelectionBorder = Color.Orange,
@@ -30,6 +30,7 @@ namespace FlaxEditor.Surface.Archetypes
protected const float DecoratorsMarginY = 2.0f;
protected bool _debugRelevant;
protected int _debugDecoratorResult = -1;
protected string _debugInfo;
protected Float2 _debugInfoSize;
protected ScriptType _type;
@@ -90,6 +91,7 @@ namespace FlaxEditor.Surface.Archetypes
protected virtual void UpdateDebugInfo(BehaviorTreeNode instance = null, Behavior behavior = null)
{
_debugRelevant = false;
_debugDecoratorResult = -1;
_debugInfo = null;
_debugInfoSize = Float2.Zero;
if (!instance)
@@ -98,6 +100,8 @@ namespace FlaxEditor.Surface.Archetypes
{
// Get debug description for the node based on the current settings
_debugRelevant = Behavior.GetNodeDebugRelevancy(instance, behavior);
if (instance is BehaviorTreeDecorator decorator && behavior && behavior.IsDuringPlay && behavior.Result == BehaviorUpdateResult.Running)
_debugDecoratorResult = Behavior.GetDecoratorDebugResult(decorator, behavior);
_debugInfo = Behavior.GetNodeDebugInfo(instance, behavior);
if (!string.IsNullOrEmpty(_debugInfo))
_debugInfoSize = Style.Current.FontSmall.MeasureText(_debugInfo);
@@ -808,7 +812,12 @@ namespace FlaxEditor.Surface.Archetypes
// Debug Info
if (!string.IsNullOrEmpty(_debugInfo))
{
Render2D.DrawText(style.FontSmall, _debugInfo, new Rectangle(4, _headerRect.Bottom, _debugInfoSize), style.Foreground, TextAlignment.Near, TextAlignment.Center, TextWrapping.NoWrap, 1, 0.8f);
var color = style.Foreground;
if (_debugDecoratorResult == 0)
color = style.ProgressError;
else if (_debugDecoratorResult == 1)
color = style.ProgressNormal;
Render2D.DrawText(style.FontSmall, _debugInfo, new Rectangle(4, _headerRect.Bottom, _debugInfoSize), color, TextAlignment.Near, TextAlignment.Center, TextWrapping.NoWrap, 1, 0.8f);
}
// Outline
+18 -1
View File
@@ -209,7 +209,25 @@ String Behavior::GetNodeDebugInfo(const BehaviorTreeNode* node, Behavior* behavi
if (!node)
return String::Empty;
BehaviorUpdateContext context;
InitNodeDebugContext(node, behavior, context);
return node->GetDebugInfo(context);
}
int32 Behavior::GetDecoratorDebugResult(BehaviorTreeDecorator* node, Behavior* behavior)
{
if (!node)
return -1;
BehaviorUpdateContext context;
InitNodeDebugContext(node, behavior, context);
return node->CanUpdate(context) ? 1 : 0;
}
void Behavior::InitNodeDebugContext(const BehaviorTreeNode* node, Behavior* behavior, BehaviorUpdateContext& context)
{
// Zero out context
Platform::MemoryClear(&context, sizeof(context));
// Check if the node is relevant (active in tree with state created)
if (GetNodeDebugRelevancy(node, behavior))
{
// Pass behavior and knowledge data only for relevant nodes to properly access it
@@ -219,7 +237,6 @@ String Behavior::GetNodeDebugInfo(const BehaviorTreeNode* node, Behavior* behavi
context.RelevantNodes = &behavior->_knowledge.RelevantNodes;
context.Time = behavior->_totalTime;
}
return node->GetDebugInfo(context);
}
#endif
+2
View File
@@ -110,5 +110,7 @@ private:
// Editor-only utilities to debug nodes state.
API_FUNCTION(Internal) static bool GetNodeDebugRelevancy(const BehaviorTreeNode* node, const Behavior* behavior);
API_FUNCTION(Internal) static String GetNodeDebugInfo(const BehaviorTreeNode* node, Behavior* behavior);
API_FUNCTION(Internal) static int32 GetDecoratorDebugResult(class BehaviorTreeDecorator* node, Behavior* behavior);
static void InitNodeDebugContext(const BehaviorTreeNode* node, Behavior* behavior, BehaviorUpdateContext& context);
#endif
};
+1
View File
@@ -300,6 +300,7 @@ namespace FlaxEngine
TextBoxBackgroundSelected = Color.FromBgra(0xFF3F3F46),
CollectionBackgroundColor = Color.FromBgra(0x14CCCCCC),
ProgressNormal = Color.FromBgra(0xFF0ad328),
ProgressError = new Color(0.79f, 0.146f, 0.0f, 1.0f),
Statusbar = new Style.StatusbarStyle
{
PlayMode = Color.FromBgra(0xFF2F9135),
+6
View File
@@ -170,6 +170,12 @@ namespace FlaxEngine.GUI
[EditorOrder(200)]
public Color ProgressNormal;
/// <summary>
/// The progress error color.
/// </summary>
[EditorOrder(201)]
public Color ProgressError;
/// <summary>
/// The selection and drag drop highlights colors.
/// </summary>