Skip to content

Commit 5d33df7

Browse files
committed
changed animation end time setup > now get end time via pointer
1 parent 8f529e5 commit 5d33df7

4 files changed

Lines changed: 52 additions & 12 deletions

File tree

Editor/Scripts/Interactivity/VisualScriptingExport/UnitExporters/Animations/AnimationPlayNode.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@ public bool InitializeInteractivityNodes(UnitExporter unitExporter)
7575
node.ValueInConnection[Animation_StartNode.IdValueSpeed].Value = 1f;
7676
node.ValueInConnection[Animation_StartNode.IdValueStartTime].Value = 0.0f;
7777

78-
node.ValueInConnection[Animation_StartNode.IdValueEndtime].Value =
79-
(clip != null && !clip.isLooping) ? clip.length : float.PositiveInfinity;
78+
if (clip != null && !clip.isLooping)
79+
{
80+
var animationLength = AnimationHelper.GetAnimationLength(unitExporter, animationId);
81+
node.ValueIn(Animation_StartNode.IdValueEndtime).ConnectToSource(animationLength);
82+
83+
}
84+
else
85+
node.ValueIn(Animation_StartNode.IdValueEndtime).SetValue(float.PositiveInfinity);
8086

8187
unitExporter.MapInputPortToSocketName(unit.enter, Animation_StartNode.IdFlowIn, node);
8288
// There should only be one output flow from the Animator.Play node

Editor/Scripts/Interactivity/VisualScriptingExport/UnitExporters/Animations/AnimatorPlayNode.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,37 @@ public bool InitializeInteractivityNodes(UnitExporter unitExporter)
6464
AnimationClip clip = animationState.motion as AnimationClip;
6565
bool isReversed = animationState.speed < 0 && !unitExporter.Context.exporter.BakeAnimationSpeed;
6666

67-
float clipLength = clip.length;
68-
69-
float startTime = 0;
70-
float endTime = clipLength;
67+
7168
if (clip != null && clip.isLooping)
7269
{
73-
startTime = isReversed ? clipLength : 0;
74-
endTime = isReversed ? float.NegativeInfinity : float.PositiveInfinity;
70+
if (isReversed)
71+
{
72+
var clipLengthRef = AnimationHelper.GetAnimationLength(unitExporter, animationId);
73+
node.ValueIn(Animation_StartNode.IdValueStartTime).ConnectToSource(clipLengthRef);
74+
node.ValueIn(Animation_StartNode.IdValueEndtime).SetValue(float.NegativeInfinity);
75+
76+
}
77+
else
78+
{
79+
node.ValueIn(Animation_StartNode.IdValueStartTime).SetValue(0f);
80+
node.ValueIn(Animation_StartNode.IdValueEndtime).SetValue(float.PositiveInfinity);
81+
82+
}
7583
}
7684
else if (isReversed)
7785
{
78-
startTime = clipLength;
79-
endTime = 0;
86+
var clipLengthRef = AnimationHelper.GetAnimationLength(unitExporter, animationId);
87+
node.ValueIn(Animation_StartNode.IdValueStartTime).ConnectToSource(clipLengthRef);
88+
node.ValueIn(Animation_StartNode.IdValueEndtime).SetValue(0f);
89+
}
90+
else
91+
{
92+
var clipLengthRef = AnimationHelper.GetAnimationLength(unitExporter, animationId);
93+
node.ValueIn(Animation_StartNode.IdValueStartTime).SetValue(0f);
94+
node.ValueIn(Animation_StartNode.IdValueEndtime).ConnectToSource(clipLengthRef);
95+
8096
}
8197

82-
node.ValueInConnection[Animation_StartNode.IdValueStartTime].Value = startTime;
8398

8499
var otherAnimationStates = AnimatorHelper.GetAllAnimationStates(target);
85100
var stopSequence = unitExporter.CreateNode<Flow_SequenceNode>();
@@ -109,7 +124,6 @@ public bool InitializeInteractivityNodes(UnitExporter unitExporter)
109124
var lastSequenceFlow = stopSequence.FlowOut("zzz");
110125
lastSequenceFlow.ConnectToFlowDestination(node.FlowIn(Animation_StartNode.IdFlowIn));
111126

112-
node.ValueInConnection[Animation_StartNode.IdValueEndtime].Value = endTime;
113127

114128
// There should only be one output flow from the Animator.Play node
115129
unitExporter.MapOutFlowConnectionWhenValid(unit.exit, Animation_StartNode.IdFlowOut, node);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using UnityGLTF.Interactivity.Export;
2+
using UnityGLTF.Interactivity.Schema;
3+
4+
namespace UnityGLTF.Interactivity.VisualScripting.Export
5+
{
6+
public static class AnimationHelper
7+
{
8+
public static ValueOutRef GetAnimationLength(UnitExporter unitExporter, int animationId)
9+
{
10+
var pointerLength = unitExporter.CreateNode<Pointer_GetNode>();
11+
PointersHelper.SetupPointerTemplateAndTargetInput(pointerLength, "index", "/animations/{index}/extensions/KHR_interactivity/maxTime", GltfTypes.Float);
12+
pointerLength.ValueIn("index").SetValue(animationId);
13+
return pointerLength.FirstValueOut();
14+
}
15+
16+
}
17+
}

Editor/Scripts/Interactivity/VisualScriptingExport/UnitExporters/Helpers/AnimationHelper.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)