• Unity
  • How to get serializable Animation Name in EditorWindow?

Here I'm making a custom window:

And the function I‘m expecting is to get every Animation Name in a prefab including a SpineAnimation by appointing that prefab for Spine animation Prefab:

This is what the goal looks like ↓↓↓, but now only in the inspector...

The problem is: How to get serializable Animation Name in EditorWindow? :wonder: :wonder: :wonder:

Related Discussions
...

You can use Spine's attribute drawers in EditorWindows as in normal component classes.

You can check out the SkeletonDebugWindow EditorWindow class as an example:
http://esotericsoftware.com/git/spine-runtimes/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDebugWindow.cs#L85-L86

The most important parts are these:

public class SkeletonDebugWindow : EditorWindow {
      ...
      public SkeletonRenderer skeletonRenderer;
      ...
      [SpineBone(dataField:"skeletonRenderer")]
      public string boneName;
      ...

The same can be applied to a SpineAnimation:

[SpineAnimation(dataField: "skeletonRenderer")]
public string animationName;

Harald escribió

You can use Spine's attribute drawers in EditorWindows as in normal component classes.

You can check out the SkeletonDebugWindow EditorWindow class as an example:
http://esotericsoftware.com/git/spine-runtimes/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDebugWindow.cs#L85-L86

The most important parts are these:

public class SkeletonDebugWindow : EditorWindow {
      ...
      public SkeletonRenderer skeletonRenderer;
      ...
      [SpineBone(dataField:"skeletonRenderer")]
      public string boneName;
      ...

The same can be applied to a SpineAnimation:

[SpineAnimation(dataField: "skeletonRenderer")]
public string animationName;

:wonder:
Uh ... in fact what I want to konw is how to get the SerializedProperty value of a SpineAnimationName:

so that I can choose animations in my custom window as a select menu:

You can use it in the same way as in the class I mentioned above, see
http://esotericsoftware.com/git/spine-runtimes/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDebugWindow.cs#L261-L262

So in your case:

var animationProperty = new SerializedObject(this).FindProperty("animationName");
EditorGUILayout.PropertyField(animationProperty, new GUIContent("Animation Name"));
Harald escribió

You can use it in the same way as in the class I mentioned above, see
http://esotericsoftware.com/git/spine-runtimes/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDebugWindow.cs#L261-L262

So in your case:

var animationProperty = new SerializedObject(this).FindProperty("animationName");
EditorGUILayout.PropertyField(animationProperty, new GUIContent("Animation Name"));

As you taught I found the SkeletonDebugWindow.cs

and copied this section into my Class:

But after opened two windows and comparing the same selected object, it didn't work in my DialogCreator window, and the "SerializedProperty bpo" was Null.:

Did i need other necessary property or something like that?

In your case it is not "boneName", this was just an analogous reference in the SkeletonDebugWindow.cs file.
As I wrote above, in your case it is "animationName".

So the complete code for your class would be:

class YourClass {
    ...
    public SkeletonRenderer skeletonRenderer;
    ...
    [SpineAnimation(dataField: "skeletonRenderer")]
    public string animationName;

void YourMethod() {
    ...
    var animationProperty = new SerializedObject(this).FindProperty("animationName");
    EditorGUILayout.PropertyField(animationProperty, new GUIContent("Animation Name"));
}
...
}

:nerd: :nerd: :nerd:
Damn~ You've just pull me out of a hell!
Learned a lot by the discussion.

And finally I found that the trouble kept existing be cause the SkeletonRenderer skeletonRenderer wasn't public.
Here's the finished one:


❤Thanks a lot for all the patience!

Thanks for getting back to us, glad you got it working!