• Unity
  • [Unity / C#] List available animations on SkeletonAnimator?

  • Düzenlendi
Related Discussions
...

Hello,

I am using Spine's Unity runtime. I am trying to get a list or array of all animations available to a SkeletonAnimation - I know you can pass them in using SetAnimation as either a string or as a Spine.Animation - but how can you get the possible animations in the first place?


Seem to have figured it out:

SkeletonAnimation.skeleton.data.Animations.ToArray()

SkeletonData.Animations is a System.Collections.Generic.List<Spine.Animation>.
You don't really need to turn it into an array.

Pharan: Thanks for your response. When I try that I get the error

Cannot implicitly convert type `Spine.ExposedList<Spine.Animation>' to `System.Collections.Generic.List<Spine.Animation>'

So I think this may not be accurate - not sure what that type is but it seems to come with the Spine runtime.

Oh. I guess it's a Spine.ExposedList<Spine.Animation> now.
A Spine.ExposedList is the same as a System.Collections.Generic.List, except (1) the indexer was removed, and (2) element access is through the now-exposed internal array .Items.

I'm not sure why this was done for the animation list, but for most cases in the runtime, this was to reduce the indexer overhead when processing large numbers of skeleton parts.

I guess given that, ToArray is the simplest way to do it.

3 yıl sonra

Hello,

i'm exactly trying to do that, but it seems i can't achieve it!

I'm trying to create a dropDownlist of all animation to the attached gameObject. So when i drop a Spine Game Object in the inspector, i want to fill my drop down list.

Here's my code :


//monobehaviour cs
[SerializeField] public GameObject objectToActivate;//this is the object to animate when the EnergyBox is Activate
private SkeletonAnimation objectAnimation;
public string[] listOfAnimation;

void Start () {


    objectAnimation = objectToActivate.GetComponent<SkeletonAnimation>();
    listOfAnimation = new string[] { objectAnimation.skeleton.Data.Animations.ToString() };
}

//

---


//myEditorScript

[CustomEditor(typeof(useDisplay))]

public class NewBehaviourScript : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

    useDisplay script = (useDisplay)target;

    GUIContent listOfAnimation = new GUIContent("ListOfAnimation");
    script.arrayIdx = EditorGUILayout.Popup(listOfAnimation, script.arrayIdx, script.listOfAnimation);
}
}


please HELP ME!!

You have resurrected a very old thread which is by now obsolete.

You can use the SpineAnimation attribute now, so the much more elegant way is as follows:

using UnityEngine;
using Spine.Unity;

public class AnimNameInspector : MonoBehaviour {

   [SpineAnimation]
   public string listOfAllAnimations;

   public SkeletonAnimation otherSkeletonData;
   [SpineAnimation(dataField: "otherSkeletonData")]
   public string otherSkeletonsAnimations; // dropdown list will be populated with otherSkeletonData's animations.
}

Note that the SpineAnimation attribute has some more useful entries apart from the dataField:
spine-runtimes/SpineAttributes.cs at 3.7