Add displaying playback position of animation in Anim Graph window
This commit is contained in:
@@ -113,6 +113,25 @@ namespace FlaxEditor.Surface
|
||||
ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin;
|
||||
}
|
||||
|
||||
internal AnimGraphTraceEvent[] LastTraceEvents;
|
||||
|
||||
internal bool TryGetTraceEvent(SurfaceNode node, out AnimGraphTraceEvent traceEvent)
|
||||
{
|
||||
if (LastTraceEvents != null)
|
||||
{
|
||||
foreach (var e in LastTraceEvents)
|
||||
{
|
||||
if (e.NodeId == node.ID)
|
||||
{
|
||||
traceEvent = e;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
traceEvent = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static SurfaceStyle CreateStyle()
|
||||
{
|
||||
var editor = Editor.Instance;
|
||||
@@ -383,6 +402,7 @@ namespace FlaxEditor.Surface
|
||||
}
|
||||
ScriptsBuilder.ScriptsReloadBegin -= OnScriptsReloadBegin;
|
||||
_nodesCache.Wait();
|
||||
LastTraceEvents = null;
|
||||
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
{
|
||||
private AssetSelect _assetSelect;
|
||||
private Box _assetBox;
|
||||
private ProgressBar _playbackPos;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Sample(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
|
||||
@@ -93,6 +94,36 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
_assetSelect.Visible = !box.HasAnyConnection;
|
||||
UpdateTitle();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
// Debug current playback position
|
||||
if (((AnimGraphSurface)Surface).TryGetTraceEvent(this, out var traceEvent) && traceEvent.Asset is FlaxEngine.Animation anim)
|
||||
{
|
||||
if (_playbackPos == null)
|
||||
{
|
||||
_playbackPos = new ProgressBar
|
||||
{
|
||||
SmoothingScale = 0.0f,
|
||||
Offsets = Margin.Zero,
|
||||
AnchorPreset = AnchorPresets.HorizontalStretchBottom,
|
||||
Parent = this,
|
||||
Height = 12.0f,
|
||||
};
|
||||
_playbackPos.Y -= 16.0f;
|
||||
}
|
||||
_playbackPos.Visible = true;
|
||||
_playbackPos.Maximum = anim.Duration;
|
||||
_playbackPos.Value = traceEvent.Value; // AnimGraph reports position in animation frames, not time
|
||||
}
|
||||
else if (_playbackPos != null)
|
||||
{
|
||||
_playbackPos.Visible = false;
|
||||
}
|
||||
|
||||
base.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -396,6 +396,16 @@ namespace FlaxEditor.Windows.Assets
|
||||
/// <inheritdoc />
|
||||
public override void OnUpdate()
|
||||
{
|
||||
// Extract animations playback state from the events tracing
|
||||
var debugActor = _debugPicker.Value as AnimatedModel;
|
||||
if (debugActor == null)
|
||||
debugActor = _preview.PreviewActor;
|
||||
if (debugActor != null)
|
||||
{
|
||||
debugActor.EnableTracing = true;
|
||||
Surface.LastTraceEvents = debugActor.TraceEvents;
|
||||
}
|
||||
|
||||
base.OnUpdate();
|
||||
|
||||
// Update graph execution flow debugging visualization
|
||||
@@ -416,6 +426,8 @@ namespace FlaxEditor.Windows.Assets
|
||||
/// <inheritdoc />
|
||||
public override void OnDestroy()
|
||||
{
|
||||
if (IsDisposing)
|
||||
return;
|
||||
Animations.DebugFlow -= OnDebugFlow;
|
||||
|
||||
_properties = null;
|
||||
|
||||
Reference in New Issue
Block a user