• Unity
  • Dynamic Timeline Binding

  • Изменено
Related Discussions
...

I have figured out how to dynamically bind a SkeletonAnimation to the SpineAnimationStateTrack in a specific timeline, but I've hit a wall in trying to set the AnimationReference on the SpineAnimationStateClip.

I thought I found a reference to the track using the TimelineAsset, but I'm unable to convert source type AnimationReferenceAsset to AnimationClip.

Guessing it's something simple that I'm missing, and would appreciate any guess as to how to accomplish this.

Have you tried the following?

int inputCount = playable.GetInputCount();
..
ScriptPlayable<SpineAnimationStateBehaviour> inputPlayable =
    (ScriptPlayable<SpineAnimationStateBehaviour>)playable.GetInput(i);
SpineAnimationStateBehaviour clipData = inputPlayable.GetBehaviour();
clipData.animationReference = animationReferenceAsset;

Or if you want to perform only editor scripting:

SpineAnimationStateClip clip;
clip.template.animationReference = animationReferenceAsset;

Works perfectly! Not sure I would have been able to figure out that out, so I genuinely appreciate your time and effort. Thanks for being awesome as always!

5 дней спустя

Glad it worked! Thanks for your kind words :nerd:


Posting additional code here for reference, in case anyone wants to access the clip instance at runtime:

PlayableDirector director = this.GetComponent<PlayableDirector>();
int rootCount = director.playableGraph.GetRootPlayableCount();
for (int i = 0; i < rootCount; ++i) {
   Playable rootPlayable = director.playableGraph.GetRootPlayable(0);
   int trackCount = rootPlayable.GetInputCount();
   for (int t = 0; t < trackCount; ++t) {
      var trackPlayable = rootPlayable.GetInput(t);
      if (trackPlayable.GetPlayableType() == typeof(SpineAnimationStateMixerBehaviour)) {
         //ScriptPlayable<SpineAnimationStateMixerBehaviour> behaviour = (ScriptPlayable<SpineAnimationStateMixerBehaviour>)mixerPlayable;
         int clipCount = trackPlayable.GetInputCount();
         for (int c = 0; c < clipCount; ++c) {
            var clipPlayable = trackPlayable.GetInput(c);
            if (clipPlayable.GetPlayableType() == typeof(SpineAnimationStateBehaviour)) {
               ScriptPlayable<SpineAnimationStateBehaviour> stateClip = (ScriptPlayable<SpineAnimationStateBehaviour>)clipPlayable;
               SpineAnimationStateBehaviour animationStateClip = stateClip.GetBehaviour();
               Debug.Log(string.Format("track {0}, clip {1}: {2}", t, c, animationStateClip.animationReference.name));
            }
         }
      }
   }
}