Skip to content

Display animation clip names and progress directly on nodes #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Editor/Graph/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public virtual string GetContentTypeShortName()
return GetContentTypeName().Split('.').Last();
}

public virtual string GetLabel()
{
return null;
}

public virtual bool TryGetProgress(out float progress)
{
progress = 0f;
return false;
}

public override string ToString()
{
return "Node content: " + GetContentTypeName();
Expand Down
8 changes: 7 additions & 1 deletion Editor/Graph/Renderer/DefaultGraphRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,15 @@ private void DrawNode(Rect nodeRect, Node node, bool selected)
{
string nodeType = node.GetContentTypeName();
NodeTypeLegend nodeTypeLegend = m_LegendForType[nodeType];
string formattedLabel = Regex.Replace(nodeTypeLegend.label, "((?<![A-Z])\\B[A-Z])", "\n$1"); // Split into multi-lines
string formattedLabel = node.GetLabel() ?? Regex.Replace(nodeTypeLegend.label, "((?<![A-Z])\\B[A-Z])", "\n$1"); // Split into multi-lines

DrawRect(nodeRect, nodeTypeLegend.color, formattedLabel, node.active, selected);

if (node.TryGetProgress(out float progress))
{
float height = 10f;
EditorGUI.DrawRect(new Rect(nodeRect.xMin, nodeRect.yMax - height, nodeRect.width * progress, height), Color.white);
}
}

// Compute the tangents for the graphLayout edges. Assumes that graphLayout is drawn from left to right
Expand Down
33 changes: 33 additions & 0 deletions Editor/PlayableNodes/AnimationClipPlayableNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;

Expand All @@ -11,6 +12,38 @@ public AnimationClipPlayableNode(Playable content, float weight = 1.0f)
{
}

public override string GetLabel()
{
var p = (Playable)content;
if (p.IsValid())
{
var acp = (AnimationClipPlayable)p;
var clip = acp.GetAnimationClip();
return clip ? clip.name : "(none)";
}
return "(invalid)";
}

public override bool TryGetProgress(out float progress)
{
var p = (Playable)content;
if (p.IsValid())
{
var acp = (AnimationClipPlayable)p;
var clip = acp.GetAnimationClip();
if (clip != null)
{
if (clip.isLooping)
progress = (float)((acp.GetTime() % clip.length) / clip.length);
else
progress = Mathf.Clamp01((float)(acp.GetTime() / clip.length));
return true;
}
}
progress = 0f;
return false;
}

public override string ToString()
{
var sb = new StringBuilder();
Expand Down