Skip to content

Commit

Permalink
[unity] SpineAttributeDrawers menu item methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
pharan committed Jun 7, 2017
1 parent 54cb4df commit ef40834
Showing 1 changed file with 68 additions and 6 deletions.
74 changes: 68 additions & 6 deletions spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs
Expand Up @@ -60,7 +60,7 @@ public abstract class SpineTreeItemDrawerBase<T> : PropertyDrawer where T:SpineA
noneLabel.image = image;
return noneLabel;
}

protected T TargetAttribute { get { return (T)attribute; } }
protected SerializedProperty SerializedProperty { get; private set; }

Expand Down Expand Up @@ -155,7 +155,7 @@ public class SpineSlotDrawer : SpineTreeItemDrawerBase<SpineSlot> {
for (int i = 0; i < data.Slots.Count; i++) {
string name = data.Slots.Items[i].Name;
if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal)) {

if (targetAttribute.containsBoundingBoxes) {
int slotIndex = i;
var attachments = new List<Attachment>();
Expand Down Expand Up @@ -192,6 +192,28 @@ public class SpineSkinDrawer : SpineTreeItemDrawerBase<SpineSkin> {

protected override Texture2D Icon { get { return SpineEditorUtilities.Icons.skin; } }

public static void GetSkinMenuItems (SkeletonData data, List<string> animationNames, List<GUIContent> menuItems, bool includeNone = true) {
if (data == null) return;

var skins = data.Skins;

animationNames.Clear();
menuItems.Clear();

var icon = SpineEditorUtilities.Icons.skin;

if (includeNone) {
animationNames.Add("");
menuItems.Add(new GUIContent(NoneString, icon));
}

foreach (var s in skins) {
var skinName = s.Name;
animationNames.Add(skinName);
menuItems.Add(new GUIContent(skinName, icon));
}
}

protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSkin targetAttribute, SkeletonData data) {
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
menu.AddSeparator("");
Expand All @@ -207,9 +229,29 @@ public class SpineSkinDrawer : SpineTreeItemDrawerBase<SpineSkin> {

[CustomPropertyDrawer(typeof(SpineAnimation))]
public class SpineAnimationDrawer : SpineTreeItemDrawerBase<SpineAnimation> {

protected override Texture2D Icon { get { return SpineEditorUtilities.Icons.animation; } }

public static void GetAnimationMenuItems (SkeletonData data, List<string> animationNames, List<GUIContent> menuItems, bool includeNone = true) {
if (data == null) return;

var animations = data.Animations;

animationNames.Clear();
menuItems.Clear();

if (includeNone) {
animationNames.Add("");
menuItems.Add(new GUIContent(NoneString, SpineEditorUtilities.Icons.animation));
}

foreach (var a in animations) {
var animationName = a.Name;
animationNames.Add(animationName);
menuItems.Add(new GUIContent(animationName, SpineEditorUtilities.Icons.animation));
}
}

protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineAnimation targetAttribute, SkeletonData data) {
var animations = skeletonDataAsset.GetAnimationStateData().SkeletonData.Animations;

Expand All @@ -230,6 +272,26 @@ public class SpineEventNameDrawer : SpineTreeItemDrawerBase<SpineEvent> {

protected override Texture2D Icon { get { return SpineEditorUtilities.Icons.userEvent; } }

public static void GetEventMenuItems (SkeletonData data, List<string> eventNames, List<GUIContent> menuItems, bool includeNone = true) {
if (data == null) return;

var animations = data.Events;

eventNames.Clear();
menuItems.Clear();

if (includeNone) {
eventNames.Add("");
menuItems.Add(new GUIContent(NoneString, SpineEditorUtilities.Icons.userEvent));
}

foreach (var a in animations) {
var animationName = a.Name;
eventNames.Add(animationName);
menuItems.Add(new GUIContent(animationName, SpineEditorUtilities.Icons.userEvent));
}
}

protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineEvent targetAttribute, SkeletonData data) {
var events = skeletonDataAsset.GetSkeletonData(false).Events;

Expand Down Expand Up @@ -325,7 +387,7 @@ public class SpineAttachmentDrawer : SpineTreeItemDrawerBase<SpineAttachment> {
validSkins.Add(currentSkin);
else
validSkins.Add(data.Skins.Items[0]);

} else {
foreach (Skin skin in data.Skins)
if (skin != null) validSkins.Add(skin);
Expand Down Expand Up @@ -398,7 +460,7 @@ public class SpineAttachmentDrawer : SpineTreeItemDrawerBase<SpineAttachment> {

[CustomPropertyDrawer(typeof(SpineBone))]
public class SpineBoneDrawer : SpineTreeItemDrawerBase<SpineBone> {

protected override Texture2D Icon { get { return SpineEditorUtilities.Icons.bone; } }

protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineBone targetAttribute, SkeletonData data) {
Expand Down Expand Up @@ -428,7 +490,7 @@ public class SpineAtlasRegionDrawer : PropertyDrawer {
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
return;
}

string atlasAssetFieldName = TargetAttribute.atlasAssetField;
if (string.IsNullOrEmpty(atlasAssetFieldName))
atlasAssetFieldName = "atlasAsset";
Expand Down

0 comments on commit ef40834

Please sign in to comment.