Pharan a écritLooks like it wasn't Mitch stuff after all:
https://docs.unity3d.com/ScriptReference/GenericMenu.html
Note the sample code:
menu.AddItem(new GUIContent("SubMenu/MenuItem3"), false, Callback, "item 3");
... is automatically parsed as a submenu.
What you could do is replace whatever character you want into "/" and use that modified string in new GUIContent.
Like in the code you cited above, you can change it to:
menu.AddItem(new GUIContent(name.Replace('_', '/'), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
its pretty magicall adding strings to dropdowns to me 🙂
But would that not Save the string Movement_Walk as Movement\Walk. And thus would not be able to used to play animations? (as the name is incorrect)
03 Aug 2016, 16:42
huh, I guess not. Thanks, this works. Maybe it would be nice to allow you to replace the separator?
03 Aug 2016, 16:45
Something like:
public class SpineAnimation : SpineAttributeBase {
/// <summary>
/// Smart popup menu for Spine Animations
/// </summary>
/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
/// </param>
///
public char m_Separator = '/';
public SpineAnimation(string startsWith = "", string dataField = "") {
this.startsWith = startsWith;
this.dataField = dataField;
}
public SpineAnimation(string startsWith = "", string dataField = "", char Separator = '/')
{
this.startsWith = startsWith;
this.dataField = dataField;
m_Separator = Separator;
}
}
[CustomPropertyDrawer(typeof(SpineAnimation))]
public class SpineAnimationDrawer : SpineTreeItemDrawerBase<SpineAnimation> {
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineAnimation targetAttribute, SkeletonData data) {
var animations = skeletonDataAsset.GetAnimationStateData().SkeletonData.Animations;
// <None> item
menu.AddItem(new GUIContent(NoneLabel), string.IsNullOrEmpty(property.stringValue), HandleSelect, new SpineDrawerValuePair("", property));
for (int i = 0; i < animations.Count; i++) {
string name = animations.Items[i].Name;
if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
menu.AddItem(new GUIContent(name.Replace(targetAttribute.m_Separator, '/')), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
}
}
}