From e9cf188c2d597a586fc85268da3600b6e4ec6816 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 19 Sep 2023 21:24:00 +0200 Subject: [PATCH] Add outline for relevant BT nodes when debugging tree --- Source/Editor/Surface/Archetypes/BehaviorTree.cs | 13 +++++++++++++ Source/Engine/AI/Behavior.cpp | 7 ++++++- Source/Engine/AI/Behavior.h | 5 +++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/BehaviorTree.cs b/Source/Editor/Surface/Archetypes/BehaviorTree.cs index 15f154617..9bb82fe7c 100644 --- a/Source/Editor/Surface/Archetypes/BehaviorTree.cs +++ b/Source/Editor/Surface/Archetypes/BehaviorTree.cs @@ -29,6 +29,7 @@ namespace FlaxEditor.Surface.Archetypes protected const float DecoratorsMarginX = 5.0f; protected const float DecoratorsMarginY = 2.0f; + protected bool _debugRelevant; protected string _debugInfo; protected Float2 _debugInfoSize; protected ScriptType _type; @@ -88,6 +89,7 @@ namespace FlaxEditor.Surface.Archetypes protected virtual void UpdateDebugInfo(BehaviorTreeNode instance = null, Behavior behavior = null) { + _debugRelevant = false; _debugInfo = null; _debugInfoSize = Float2.Zero; if (!instance) @@ -95,6 +97,7 @@ namespace FlaxEditor.Surface.Archetypes if (instance) { // Get debug description for the node based on the current settings + _debugRelevant = Behavior.GetNodeDebugRelevancy(instance, behavior); _debugInfo = Behavior.GetNodeDebugInfo(instance, behavior); if (!string.IsNullOrEmpty(_debugInfo)) _debugInfoSize = Style.Current.FontSmall.MeasureText(_debugInfo); @@ -183,6 +186,15 @@ namespace FlaxEditor.Surface.Archetypes var style = Style.Current; Render2D.DrawText(style.FontSmall, _debugInfo, new Rectangle(4, _headerRect.Bottom + 4, _debugInfoSize), style.Foreground); } + + // Debug relevancy outline + if (_debugRelevant) + { + var colorTop = Color.LightYellow; + var colorBottom = Color.Yellow; + var backgroundRect = new Rectangle(Float2.One, Size - new Float2(2.0f)); + Render2D.DrawRectangle(backgroundRect, colorTop, colorTop, colorBottom, colorBottom); + } } public override void OnDestroy() @@ -685,6 +697,7 @@ namespace FlaxEditor.Surface.Archetypes // Add drag button to reorder decorator _dragIcon = new DragImage { + AnchorPreset = AnchorPresets.TopRight, Color = Style.Current.ForegroundGrey, Parent = this, Margin = new Margin(1), diff --git a/Source/Engine/AI/Behavior.cpp b/Source/Engine/AI/Behavior.cpp index 74d48ddb0..8234125f4 100644 --- a/Source/Engine/AI/Behavior.cpp +++ b/Source/Engine/AI/Behavior.cpp @@ -169,7 +169,12 @@ void Behavior::OnDisable() #if USE_EDITOR -String Behavior::GetNodeDebugInfo(BehaviorTreeNode* node, Behavior* behavior) +bool Behavior::GetNodeDebugRelevancy(const BehaviorTreeNode* node, const Behavior* behavior) +{ + return node && behavior && behavior->_knowledge.RelevantNodes.Get(node->_executionIndex); +} + +String Behavior::GetNodeDebugInfo(const BehaviorTreeNode* node, Behavior* behavior) { if (!node) return String::Empty; diff --git a/Source/Engine/AI/Behavior.h b/Source/Engine/AI/Behavior.h index c061fcb5a..0bf69354d 100644 --- a/Source/Engine/AI/Behavior.h +++ b/Source/Engine/AI/Behavior.h @@ -93,7 +93,8 @@ public: private: #if USE_EDITOR - // Editor-only utility to debug nodes state. - API_FUNCTION(Internal) static String GetNodeDebugInfo(BehaviorTreeNode* node, Behavior* behavior); + // 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); #endif };