Payne_Lee

Here I'm making a custom window:
ft0.png


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:
ft1.png


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


The problem is: How to get serializable Animation Name in EditorWindow? :wonder: :wonder: :wonder:
You do not have the required permissions to view the files attached to this post.
Payne_Lee
  • Posts: 25

Harald

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;
User avatar
Harald

Harri
  • Posts: 4343

Payne_Lee

Harald wrote: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:
ft3.png


so that I can choose animations in my custom window as a select menu:
ft4.png
You do not have the required permissions to view the files attached to this post.
Payne_Lee
  • Posts: 25

Harald

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"));
User avatar
Harald

Harri
  • Posts: 4343

Payne_Lee

Harald wrote: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
ft01.png



and copied this section into my Class:
ft02.png



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.:
ft03.jpg


Did i need other necessary property or something like that?
You do not have the required permissions to view the files attached to this post.
Payne_Lee
  • Posts: 25

Harald

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"));
}
...
}
User avatar
Harald

Harri
  • Posts: 4343

Payne_Lee

: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:
ft0.png

ft1.png

ft2.png


❤Thanks a lot for all the patience!
You do not have the required permissions to view the files attached to this post.
Payne_Lee
  • Posts: 25

Harald

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

Harri
  • Posts: 4343


Return to Unity