Add AutoAttachDebugPreviewActor option to editor for quick debugging anim graphs on dynamically spawned player

This commit is contained in:
Wojtek Figat
2025-04-08 22:44:31 +02:00
parent c75b33eb7d
commit eb86002fbd
3 changed files with 27 additions and 4 deletions

View File

@@ -350,14 +350,14 @@ namespace FlaxEditor.CustomEditors.Editors
}
else
{
if (PresenterContext is PropertiesWindow)
if (PresenterContext is PropertiesWindow || PresenterContext == null)
_linkedTreeNode = Editor.Instance.Scene.GetActorNode(actor).TreeNode;
else if (PresenterContext is PrefabWindow prefabWindow)
_linkedTreeNode = prefabWindow.Graph.Root.Find(actor).TreeNode;
if (_linkedTreeNode != null)
{
_linkedTreeNode.ExpandAllParents();
if (PresenterContext is PropertiesWindow)
if (PresenterContext is PropertiesWindow || PresenterContext == null)
Editor.Instance.Windows.SceneWin.SceneTreePanel.ScrollViewTo(_linkedTreeNode, true);
else if (PresenterContext is PrefabWindow prefabWindow)
(prefabWindow.Tree.Parent as Panel).ScrollViewTo(_linkedTreeNode, true);
@@ -427,7 +427,7 @@ namespace FlaxEditor.CustomEditors.Editors
private void Select(Actor actor)
{
if (PresenterContext is PropertiesWindow)
if (PresenterContext is PropertiesWindow || PresenterContext == null)
Editor.Instance.SceneEditing.Select(actor);
else if (PresenterContext is PrefabWindow prefabWindow)
prefabWindow.Select(prefabWindow.Graph.Root.Find(actor));

View File

@@ -162,6 +162,13 @@ namespace FlaxEditor.Options
[EditorDisplay("Content"), EditorOrder(550)]
public bool UseAssetImportPathRelative { get; set; } = true;
/// <summary>
/// If checked, editor windows will try to automatically attach to the first found valid actor for preview. For example, Animation Graph window will pick the first matching instance to preview.
/// </summary>
[DefaultValue(false)]
[EditorDisplay("Content"), EditorOrder(550)]
public bool AutoAttachDebugPreviewActor { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether perform automatic CSG rebuild on brush change.
/// </summary>

View File

@@ -415,8 +415,24 @@ namespace FlaxEditor.Windows.Assets
/// <inheritdoc />
public override unsafe void OnUpdate()
{
// Extract animations playback state from the events tracing
// Auto-attach preview
var debugActor = _debugPicker.Value as AnimatedModel;
if (!debugActor && Editor.IsPlayMode && Editor.Options.Options.General.AutoAttachDebugPreviewActor)
{
var animationGraph = OriginalAsset;
var animatedModels = Level.GetActors<AnimatedModel>();
foreach (var animatedModel in animatedModels)
{
if (animatedModel.AnimationGraph == animationGraph &&
animatedModel.IsActiveInHierarchy)
{
_debugPicker.Value = animatedModel;
break;
}
}
}
// Extract animations playback state from the events tracing
if (debugActor == null)
debugActor = _preview.PreviewActor;
if (debugActor != null)