Finally , I did it in another way.
I make a detailed description of my requirement :
1、I want to develop a custom editor to edit the data of spine animations , for example , the animation 'A' can be play after 'B' or 'C' , I want select the preAnimations from dropDownList , finally , the Bean class to json .
2、I submitted after finishing the sample code here ( but the code didn't work to show dropDownList of spineAnimations):
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
public class MyAnimationDataInspector : MonoBehaviour
{
// skeletonDataAsset is on this gameObject
public SkeletonDataAsset mySkeletonDataAsset;
[HideInInspector]
[SerializeField]
private MyBeanData myBean;
public MyBeanData MyBean
{
get
{
return myBean;
}
set
{
myBean = value;
}
}
}
[CustomEditor(typeof(MyAnimationDataInspector))]
public class MyAnimationDataInspectorEditor : Editor
{
public override void OnInspectorGUI()
{
MyAnimationDataInspector target = (MyAnimationDataInspector)this.target;
EditorGUILayout.BeginVertical();
// if List has two items , there should be two dropDownList at right , but it didn't work
foreach (PreAnimationInfo item in target.MyBean.preAnimationList)
{
item.mySkeletonDataAsset = target.mySkeletonDataAsset;
SerializedObject obj = new SerializedObject(item);
SerializedProperty preAnimationProperty = obj.FindProperty("preAnimation");
EditorGUILayout.PropertyField(preAnimationProperty);
obj.ApplyModifiedProperties();
}
EditorGUILayout.EndVertical();
}
}
[System.Serializable]
public class MyBeanData
{
public List<PreAnimationInfo> preAnimationList = new List<PreAnimationInfo>();
}
public class PreAnimationInfo : ScriptableObject
{
public SkeletonDataAsset mySkeletonDataAsset;
[SpineAnimation(dataField: "mySkeletonDataAsset")]
public string preAnimation;
}
the code not work to show DropDownList but a textField... 😢
3、Of course I know the 'SpineTreeItemDrawerBase' is the core of dropDownList animations , but my first step don't want to make it complex about the core , I made an easy way did it , that is define a just container of string in the 'target' as a view , still use the bean but without scriptable to make serializedProperty , then it worked. After that ,I'll try to find a more easy way to use a property as a dropDownList through the core method in 'SpineTreeItemDrawerBase'.