mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Spine.Unity and Spine.Unity.Editor namespace
This commit is contained in:
parent
80d8e9e276
commit
9254e18801
@ -38,10 +38,10 @@ using UnityEditor;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Spine;
|
using Spine;
|
||||||
|
|
||||||
namespace Spine.Unity {
|
namespace Spine.Unity.Editor {
|
||||||
|
|
||||||
[CustomEditor(typeof(AtlasAsset))]
|
[CustomEditor(typeof(AtlasAsset))]
|
||||||
public class AtlasAssetInspector : Editor {
|
public class AtlasAssetInspector : UnityEditor.Editor {
|
||||||
private SerializedProperty atlasFile, materials;
|
private SerializedProperty atlasFile, materials;
|
||||||
private AtlasAsset atlasAsset;
|
private AtlasAsset atlasAsset;
|
||||||
private List<bool> baked;
|
private List<bool> baked;
|
||||||
|
|||||||
@ -14,9 +14,9 @@ using UnityEditor.AnimatedValues;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Spine;
|
using Spine;
|
||||||
|
|
||||||
namespace Spine.Unity {
|
namespace Spine.Unity.Editor {
|
||||||
[CustomEditor(typeof(SkeletonDataAsset))]
|
[CustomEditor(typeof(SkeletonDataAsset))]
|
||||||
public class SkeletonDataAssetInspector : Editor {
|
public class SkeletonDataAssetInspector : UnityEditor.Editor {
|
||||||
static bool showAnimationStateData = true;
|
static bool showAnimationStateData = true;
|
||||||
static bool showAnimationList = true;
|
static bool showAnimationList = true;
|
||||||
static bool showSlotList = false;
|
static bool showSlotList = false;
|
||||||
@ -50,6 +50,7 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
atlasAssets = serializedObject.FindProperty("atlasAssets");
|
atlasAssets = serializedObject.FindProperty("atlasAssets");
|
||||||
|
atlasAssets.isExpanded = true;
|
||||||
skeletonJSON = serializedObject.FindProperty("skeletonJSON");
|
skeletonJSON = serializedObject.FindProperty("skeletonJSON");
|
||||||
scale = serializedObject.FindProperty("scale");
|
scale = serializedObject.FindProperty("scale");
|
||||||
fromAnimation = serializedObject.FindProperty("fromAnimation");
|
fromAnimation = serializedObject.FindProperty("fromAnimation");
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Spine {
|
namespace Spine.Unity.Editor {
|
||||||
public static class AssetDatabaseAvailabilityDetector {
|
public static class AssetDatabaseAvailabilityDetector {
|
||||||
const string MARKER_RESOURCE_NAME = "SpineAssetDatabaseMarker";
|
const string MARKER_RESOURCE_NAME = "SpineAssetDatabaseMarker";
|
||||||
private static bool _isMarkerLoaded;
|
private static bool _isMarkerLoaded;
|
||||||
|
|||||||
@ -33,60 +33,65 @@ using System;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[CustomEditor(typeof(BoneFollower))]
|
|
||||||
public class BoneFollowerInspector : Editor {
|
|
||||||
SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation;
|
|
||||||
BoneFollower component;
|
|
||||||
bool needsReset;
|
|
||||||
|
|
||||||
void OnEnable () {
|
namespace Spine.Unity.Editor {
|
||||||
skeletonRenderer = serializedObject.FindProperty("skeletonRenderer");
|
|
||||||
boneName = serializedObject.FindProperty("boneName");
|
[CustomEditor(typeof(BoneFollower))]
|
||||||
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
public class BoneFollowerInspector : UnityEditor.Editor {
|
||||||
followZPosition = serializedObject.FindProperty("followZPosition");
|
SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation;
|
||||||
component = (BoneFollower)target;
|
BoneFollower component;
|
||||||
component.skeletonRenderer.Initialize(false);
|
bool needsReset;
|
||||||
}
|
|
||||||
|
void OnEnable () {
|
||||||
override public void OnInspectorGUI () {
|
skeletonRenderer = serializedObject.FindProperty("skeletonRenderer");
|
||||||
if (needsReset) {
|
boneName = serializedObject.FindProperty("boneName");
|
||||||
component.Reset();
|
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
|
||||||
component.DoUpdate();
|
followZPosition = serializedObject.FindProperty("followZPosition");
|
||||||
needsReset = false;
|
component = (BoneFollower)target;
|
||||||
SceneView.RepaintAll();
|
component.skeletonRenderer.Initialize(false);
|
||||||
}
|
}
|
||||||
serializedObject.Update();
|
|
||||||
|
|
||||||
// FindRenderer()
|
override public void OnInspectorGUI () {
|
||||||
if (skeletonRenderer.objectReferenceValue == null) {
|
if (needsReset) {
|
||||||
SkeletonRenderer parentRenderer = SkeletonUtility.GetInParent<SkeletonRenderer>(component.transform);
|
component.Reset();
|
||||||
|
component.DoUpdate();
|
||||||
|
needsReset = false;
|
||||||
|
SceneView.RepaintAll();
|
||||||
|
}
|
||||||
|
serializedObject.Update();
|
||||||
|
|
||||||
if (parentRenderer != null) {
|
// FindRenderer()
|
||||||
skeletonRenderer.objectReferenceValue = (UnityEngine.Object)parentRenderer;
|
if (skeletonRenderer.objectReferenceValue == null) {
|
||||||
|
SkeletonRenderer parentRenderer = SkeletonUtility.GetInParent<SkeletonRenderer>(component.transform);
|
||||||
|
|
||||||
|
if (parentRenderer != null) {
|
||||||
|
skeletonRenderer.objectReferenceValue = (UnityEngine.Object)parentRenderer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUILayout.PropertyField(skeletonRenderer);
|
||||||
|
|
||||||
|
if (component.valid) {
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
EditorGUILayout.PropertyField(boneName);
|
||||||
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
needsReset = true;
|
||||||
|
serializedObject.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUILayout.PropertyField(followBoneRotation);
|
||||||
|
EditorGUILayout.PropertyField(followZPosition);
|
||||||
|
} else {
|
||||||
|
GUILayout.Label("INVALID");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serializedObject.ApplyModifiedProperties() ||
|
||||||
|
(UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed")
|
||||||
|
) {
|
||||||
|
component.Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(skeletonRenderer);
|
|
||||||
|
|
||||||
if (component.valid) {
|
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
EditorGUILayout.PropertyField(boneName);
|
|
||||||
if (EditorGUI.EndChangeCheck()) {
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
|
||||||
needsReset = true;
|
|
||||||
serializedObject.Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(followBoneRotation);
|
|
||||||
EditorGUILayout.PropertyField(followZPosition);
|
|
||||||
} else {
|
|
||||||
GUILayout.Label("INVALID");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (serializedObject.ApplyModifiedProperties() ||
|
|
||||||
(Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
|
|
||||||
) {
|
|
||||||
component.Reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@ using System.IO;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Spine.Unity {
|
namespace Spine.Unity.Editor {
|
||||||
public static class Menus {
|
public static class Menus {
|
||||||
[MenuItem("Assets/Create/Spine Atlas")]
|
[MenuItem("Assets/Create/Spine Atlas")]
|
||||||
static public void CreateAtlas () {
|
static public void CreateAtlas () {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ using UnityEditor;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Spine;
|
using Spine;
|
||||||
|
|
||||||
namespace Spine.Unity {
|
namespace Spine.Unity.Editor {
|
||||||
|
|
||||||
[CustomEditor(typeof(SkeletonAnimation))]
|
[CustomEditor(typeof(SkeletonAnimation))]
|
||||||
public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
||||||
|
|||||||
@ -6,7 +6,7 @@ using System;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Spine.Unity {
|
namespace Spine.Unity.Editor {
|
||||||
[CustomEditor(typeof(SkeletonAnimator))]
|
[CustomEditor(typeof(SkeletonAnimator))]
|
||||||
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
|
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
|
||||||
protected SerializedProperty layerMixModes;
|
protected SerializedProperty layerMixModes;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -33,10 +33,10 @@ using System;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Spine.Unity {
|
namespace Spine.Unity.Editor {
|
||||||
|
|
||||||
[CustomEditor(typeof(SkeletonRenderer))]
|
[CustomEditor(typeof(SkeletonRenderer))]
|
||||||
public class SkeletonRendererInspector : Editor {
|
public class SkeletonRendererInspector : UnityEditor.Editor {
|
||||||
protected static bool advancedFoldout;
|
protected static bool advancedFoldout;
|
||||||
|
|
||||||
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, separatorSlotNames, front, zSpacing;
|
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, separatorSlotNames, front, zSpacing;
|
||||||
|
|||||||
@ -6,351 +6,351 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Spine;
|
using Spine;
|
||||||
|
|
||||||
|
namespace Spine.Unity.Editor {
|
||||||
|
public struct SpineDrawerValuePair {
|
||||||
|
public string str;
|
||||||
|
public SerializedProperty property;
|
||||||
|
|
||||||
|
public SpineDrawerValuePair (string val, SerializedProperty property) {
|
||||||
public struct SpineDrawerValuePair {
|
this.str = val;
|
||||||
public string str;
|
this.property = property;
|
||||||
public SerializedProperty property;
|
|
||||||
|
|
||||||
public SpineDrawerValuePair (string val, SerializedProperty property) {
|
|
||||||
this.str = val;
|
|
||||||
this.property = property;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class SpineTreeItemDrawerBase<T> : PropertyDrawer where T:SpineAttributeBase {
|
|
||||||
protected SkeletonDataAsset skeletonDataAsset;
|
|
||||||
internal const string NoneLabel = "<None>";
|
|
||||||
|
|
||||||
protected T TargetAttribute { get { return (T)attribute; } }
|
|
||||||
|
|
||||||
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
|
|
||||||
if (property.propertyType != SerializedPropertyType.String) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
var dataProperty = property.serializedObject.FindProperty(TargetAttribute.dataField);
|
|
||||||
|
public abstract class SpineTreeItemDrawerBase<T> : PropertyDrawer where T:SpineAttributeBase {
|
||||||
if (dataProperty != null) {
|
protected SkeletonDataAsset skeletonDataAsset;
|
||||||
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
internal const string NoneLabel = "<None>";
|
||||||
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
|
||||||
} else if (dataProperty.objectReferenceValue is SkeletonRenderer) {
|
protected T TargetAttribute { get { return (T)attribute; } }
|
||||||
var renderer = (SkeletonRenderer)dataProperty.objectReferenceValue;
|
|
||||||
if (renderer != null)
|
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
|
||||||
skeletonDataAsset = renderer.skeletonDataAsset;
|
if (property.propertyType != SerializedPropertyType.String) {
|
||||||
} else {
|
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (property.serializedObject.targetObject is Component) {
|
|
||||||
var component = (Component)property.serializedObject.targetObject;
|
|
||||||
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
|
||||||
var skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
|
||||||
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skeletonDataAsset == null) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Must have reference to a SkeletonDataAsset");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
|
||||||
|
|
||||||
var propertyStringValue = property.stringValue;
|
var dataProperty = property.serializedObject.FindProperty(TargetAttribute.dataField);
|
||||||
if (GUI.Button(position, string.IsNullOrEmpty(propertyStringValue) ? NoneLabel : propertyStringValue, EditorStyles.popup)) {
|
|
||||||
Selector(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Selector (SerializedProperty property) {
|
if (dataProperty != null) {
|
||||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
||||||
if (data == null)
|
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
||||||
return;
|
} else if (dataProperty.objectReferenceValue is SkeletonRenderer) {
|
||||||
|
var renderer = (SkeletonRenderer)dataProperty.objectReferenceValue;
|
||||||
GenericMenu menu = new GenericMenu();
|
if (renderer != null)
|
||||||
PopulateMenu(menu, property, this.TargetAttribute, data);
|
skeletonDataAsset = renderer.skeletonDataAsset;
|
||||||
menu.ShowAsContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void PopulateMenu (GenericMenu menu, SerializedProperty property, T targetAttribute, SkeletonData data);
|
|
||||||
|
|
||||||
protected virtual void HandleSelect (object val) {
|
|
||||||
var pair = (SpineDrawerValuePair)val;
|
|
||||||
pair.property.stringValue = pair.str;
|
|
||||||
pair.property.serializedObject.ApplyModifiedProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override float GetPropertyHeight (SerializedProperty property, GUIContent label) {
|
|
||||||
return 18;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineSlot))]
|
|
||||||
public class SpineSlotDrawer : SpineTreeItemDrawerBase<SpineSlot> {
|
|
||||||
|
|
||||||
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSlot targetAttribute, SkeletonData data) {
|
|
||||||
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;
|
|
||||||
|
|
||||||
List<Attachment> attachments = new List<Attachment>();
|
|
||||||
foreach (var skin in data.Skins) {
|
|
||||||
skin.FindAttachmentsForSlot(slotIndex, attachments);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasBoundingBox = false;
|
|
||||||
foreach (var attachment in attachments) {
|
|
||||||
if (attachment is BoundingBoxAttachment) {
|
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
|
||||||
hasBoundingBox = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasBoundingBox)
|
|
||||||
menu.AddDisabledItem(new GUIContent(name));
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (property.serializedObject.targetObject is Component) {
|
||||||
|
var component = (Component)property.serializedObject.targetObject;
|
||||||
|
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
||||||
|
var skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
||||||
|
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (skeletonDataAsset == null) {
|
||||||
|
EditorGUI.LabelField(position, "ERROR:", "Must have reference to a SkeletonDataAsset");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
position = EditorGUI.PrefixLabel(position, label);
|
||||||
|
|
||||||
|
var propertyStringValue = property.stringValue;
|
||||||
|
if (GUI.Button(position, string.IsNullOrEmpty(propertyStringValue) ? NoneLabel : propertyStringValue, EditorStyles.popup)) {
|
||||||
|
Selector(property);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void Selector (SerializedProperty property) {
|
||||||
|
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
||||||
|
if (data == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GenericMenu menu = new GenericMenu();
|
||||||
|
PopulateMenu(menu, property, this.TargetAttribute, data);
|
||||||
|
menu.ShowAsContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void PopulateMenu (GenericMenu menu, SerializedProperty property, T targetAttribute, SkeletonData data);
|
||||||
|
|
||||||
|
protected virtual void HandleSelect (object val) {
|
||||||
|
var pair = (SpineDrawerValuePair)val;
|
||||||
|
pair.property.stringValue = pair.str;
|
||||||
|
pair.property.serializedObject.ApplyModifiedProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override float GetPropertyHeight (SerializedProperty property, GUIContent label) {
|
||||||
|
return 18;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
[CustomPropertyDrawer(typeof(SpineSlot))]
|
||||||
|
public class SpineSlotDrawer : SpineTreeItemDrawerBase<SpineSlot> {
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineSkin))]
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSlot targetAttribute, SkeletonData data) {
|
||||||
public class SpineSkinDrawer : SpineTreeItemDrawerBase<SpineSkin> {
|
|
||||||
|
|
||||||
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSkin targetAttribute, SkeletonData data) {
|
|
||||||
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
|
||||||
menu.AddSeparator("");
|
|
||||||
|
|
||||||
for (int i = 0; i < data.Skins.Count; i++) {
|
|
||||||
string name = data.Skins.Items[i].Name;
|
|
||||||
if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
|
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[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), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineEvent))]
|
|
||||||
public class SpineEventNameDrawer : SpineTreeItemDrawerBase<SpineEvent> {
|
|
||||||
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineEvent targetAttribute, SkeletonData data) {
|
|
||||||
var events = skeletonDataAsset.GetSkeletonData(false).Events;
|
|
||||||
for (int i = 0; i < events.Count; i++) {
|
|
||||||
string name = events.Items[i].Name;
|
|
||||||
if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
|
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineAttachment))]
|
|
||||||
public class SpineAttachmentDrawer : SpineTreeItemDrawerBase<SpineAttachment> {
|
|
||||||
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineAttachment targetAttribute, SkeletonData data) {
|
|
||||||
List<Skin> validSkins = new List<Skin>();
|
|
||||||
SkeletonRenderer skeletonRenderer = null;
|
|
||||||
|
|
||||||
var component = property.serializedObject.targetObject as Component;
|
|
||||||
if (component != null) {
|
|
||||||
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
|
||||||
skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
|
||||||
//if (skeletonDataAsset != skeletonRenderer.skeletonDataAsset) Debug.LogWarning("DataField SkeletonDataAsset and SkeletonRenderer/SkeletonAnimation's SkeletonDataAsset do not match. Remove the explicit dataField parameter of your [SpineAttachment] field.");
|
|
||||||
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skeletonRenderer != null && targetAttribute.currentSkinOnly) {
|
|
||||||
if (skeletonRenderer.skeleton.Skin != null) {
|
|
||||||
validSkins.Add(skeletonRenderer.skeleton.Skin);
|
|
||||||
} else {
|
|
||||||
validSkins.Add(data.Skins.Items[0]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach (Skin skin in data.Skins) {
|
|
||||||
if (skin != null)
|
|
||||||
validSkins.Add(skin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<string> attachmentNames = new List<string>();
|
|
||||||
List<string> placeholderNames = new List<string>();
|
|
||||||
|
|
||||||
string prefix = "";
|
|
||||||
|
|
||||||
if (skeletonRenderer != null && targetAttribute.currentSkinOnly)
|
|
||||||
menu.AddDisabledItem(new GUIContent(skeletonRenderer.gameObject.name + " (SkeletonRenderer)"));
|
|
||||||
else
|
|
||||||
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
|
||||||
|
|
||||||
menu.AddSeparator("");
|
|
||||||
|
|
||||||
menu.AddItem(new GUIContent("Null"), property.stringValue == "", HandleSelect, new SpineDrawerValuePair("", property));
|
|
||||||
|
|
||||||
menu.AddSeparator("");
|
|
||||||
|
|
||||||
Skin defaultSkin = data.Skins.Items[0];
|
|
||||||
|
|
||||||
SerializedProperty slotProperty = property.serializedObject.FindProperty(targetAttribute.slotField);
|
|
||||||
string slotMatch = "";
|
|
||||||
if (slotProperty != null) {
|
|
||||||
if (slotProperty.propertyType == SerializedPropertyType.String) {
|
|
||||||
slotMatch = slotProperty.stringValue.ToLower();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Skin skin in validSkins) {
|
|
||||||
string skinPrefix = skin.Name + "/";
|
|
||||||
|
|
||||||
if (validSkins.Count > 1)
|
|
||||||
prefix = skinPrefix;
|
|
||||||
|
|
||||||
for (int i = 0; i < data.Slots.Count; i++) {
|
for (int i = 0; i < data.Slots.Count; i++) {
|
||||||
if (slotMatch.Length > 0 && data.Slots.Items[i].Name.ToLower().Contains(slotMatch) == false)
|
string name = data.Slots.Items[i].Name;
|
||||||
continue;
|
if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal)) {
|
||||||
|
if (targetAttribute.containsBoundingBoxes) {
|
||||||
attachmentNames.Clear();
|
|
||||||
placeholderNames.Clear();
|
int slotIndex = i;
|
||||||
|
|
||||||
skin.FindNamesForSlot(i, attachmentNames);
|
List<Attachment> attachments = new List<Attachment>();
|
||||||
if (skin != defaultSkin) {
|
foreach (var skin in data.Skins) {
|
||||||
defaultSkin.FindNamesForSlot(i, attachmentNames);
|
skin.FindAttachmentsForSlot(slotIndex, attachments);
|
||||||
skin.FindNamesForSlot(i, placeholderNames);
|
}
|
||||||
}
|
|
||||||
|
bool hasBoundingBox = false;
|
||||||
|
foreach (var attachment in attachments) {
|
||||||
for (int a = 0; a < attachmentNames.Count; a++) {
|
if (attachment is BoundingBoxAttachment) {
|
||||||
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
string attachmentPath = attachmentNames[a];
|
hasBoundingBox = true;
|
||||||
string menuPath = prefix + data.Slots.Items[i].Name + "/" + attachmentPath;
|
break;
|
||||||
string name = attachmentNames[a];
|
}
|
||||||
|
}
|
||||||
if (targetAttribute.returnAttachmentPath)
|
|
||||||
name = skin.Name + "/" + data.Slots.Items[i].Name + "/" + attachmentPath;
|
if (!hasBoundingBox)
|
||||||
|
menu.AddDisabledItem(new GUIContent(name));
|
||||||
if (targetAttribute.placeholdersOnly && placeholderNames.Contains(attachmentPath) == false) {
|
|
||||||
menu.AddDisabledItem(new GUIContent(menuPath));
|
|
||||||
} else {
|
} else {
|
||||||
menu.AddItem(new GUIContent(menuPath), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomPropertyDrawer(typeof(SpineSkin))]
|
||||||
|
public class SpineSkinDrawer : SpineTreeItemDrawerBase<SpineSkin> {
|
||||||
|
|
||||||
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSkin targetAttribute, SkeletonData data) {
|
||||||
|
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
||||||
|
menu.AddSeparator("");
|
||||||
|
|
||||||
|
for (int i = 0; i < data.Skins.Count; i++) {
|
||||||
|
string name = data.Skins.Items[i].Name;
|
||||||
|
if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
|
||||||
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[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), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomPropertyDrawer(typeof(SpineEvent))]
|
||||||
|
public class SpineEventNameDrawer : SpineTreeItemDrawerBase<SpineEvent> {
|
||||||
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineEvent targetAttribute, SkeletonData data) {
|
||||||
|
var events = skeletonDataAsset.GetSkeletonData(false).Events;
|
||||||
|
for (int i = 0; i < events.Count; i++) {
|
||||||
|
string name = events.Items[i].Name;
|
||||||
|
if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
|
||||||
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomPropertyDrawer(typeof(SpineAttachment))]
|
||||||
|
public class SpineAttachmentDrawer : SpineTreeItemDrawerBase<SpineAttachment> {
|
||||||
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineAttachment targetAttribute, SkeletonData data) {
|
||||||
|
List<Skin> validSkins = new List<Skin>();
|
||||||
|
SkeletonRenderer skeletonRenderer = null;
|
||||||
|
|
||||||
|
var component = property.serializedObject.targetObject as Component;
|
||||||
|
if (component != null) {
|
||||||
|
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
||||||
|
skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
||||||
|
//if (skeletonDataAsset != skeletonRenderer.skeletonDataAsset) Debug.LogWarning("DataField SkeletonDataAsset and SkeletonRenderer/SkeletonAnimation's SkeletonDataAsset do not match. Remove the explicit dataField parameter of your [SpineAttachment] field.");
|
||||||
|
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skeletonRenderer != null && targetAttribute.currentSkinOnly) {
|
||||||
|
if (skeletonRenderer.skeleton.Skin != null) {
|
||||||
|
validSkins.Add(skeletonRenderer.skeleton.Skin);
|
||||||
|
} else {
|
||||||
|
validSkins.Add(data.Skins.Items[0]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach (Skin skin in data.Skins) {
|
||||||
|
if (skin != null)
|
||||||
|
validSkins.Add(skin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> attachmentNames = new List<string>();
|
||||||
|
List<string> placeholderNames = new List<string>();
|
||||||
|
|
||||||
|
string prefix = "";
|
||||||
|
|
||||||
|
if (skeletonRenderer != null && targetAttribute.currentSkinOnly)
|
||||||
|
menu.AddDisabledItem(new GUIContent(skeletonRenderer.gameObject.name + " (SkeletonRenderer)"));
|
||||||
|
else
|
||||||
|
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
||||||
|
|
||||||
|
menu.AddSeparator("");
|
||||||
|
|
||||||
|
menu.AddItem(new GUIContent("Null"), property.stringValue == "", HandleSelect, new SpineDrawerValuePair("", property));
|
||||||
|
|
||||||
|
menu.AddSeparator("");
|
||||||
|
|
||||||
|
Skin defaultSkin = data.Skins.Items[0];
|
||||||
|
|
||||||
|
SerializedProperty slotProperty = property.serializedObject.FindProperty(targetAttribute.slotField);
|
||||||
|
string slotMatch = "";
|
||||||
|
if (slotProperty != null) {
|
||||||
|
if (slotProperty.propertyType == SerializedPropertyType.String) {
|
||||||
|
slotMatch = slotProperty.stringValue.ToLower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Skin skin in validSkins) {
|
||||||
|
string skinPrefix = skin.Name + "/";
|
||||||
|
|
||||||
|
if (validSkins.Count > 1)
|
||||||
|
prefix = skinPrefix;
|
||||||
|
|
||||||
|
for (int i = 0; i < data.Slots.Count; i++) {
|
||||||
|
if (slotMatch.Length > 0 && data.Slots.Items[i].Name.ToLower().Contains(slotMatch) == false)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
attachmentNames.Clear();
|
||||||
|
placeholderNames.Clear();
|
||||||
|
|
||||||
|
skin.FindNamesForSlot(i, attachmentNames);
|
||||||
|
if (skin != defaultSkin) {
|
||||||
|
defaultSkin.FindNamesForSlot(i, attachmentNames);
|
||||||
|
skin.FindNamesForSlot(i, placeholderNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int a = 0; a < attachmentNames.Count; a++) {
|
||||||
|
|
||||||
|
string attachmentPath = attachmentNames[a];
|
||||||
|
string menuPath = prefix + data.Slots.Items[i].Name + "/" + attachmentPath;
|
||||||
|
string name = attachmentNames[a];
|
||||||
|
|
||||||
|
if (targetAttribute.returnAttachmentPath)
|
||||||
|
name = skin.Name + "/" + data.Slots.Items[i].Name + "/" + attachmentPath;
|
||||||
|
|
||||||
|
if (targetAttribute.placeholdersOnly && placeholderNames.Contains(attachmentPath) == false) {
|
||||||
|
menu.AddDisabledItem(new GUIContent(menuPath));
|
||||||
|
} else {
|
||||||
|
menu.AddItem(new GUIContent(menuPath), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
[CustomPropertyDrawer(typeof(SpineBone))]
|
||||||
|
public class SpineBoneDrawer : SpineTreeItemDrawerBase<SpineBone> {
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineBone))]
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineBone targetAttribute, SkeletonData data) {
|
||||||
public class SpineBoneDrawer : SpineTreeItemDrawerBase<SpineBone> {
|
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
||||||
|
menu.AddSeparator("");
|
||||||
|
|
||||||
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineBone targetAttribute, SkeletonData data) {
|
for (int i = 0; i < data.Bones.Count; i++) {
|
||||||
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
string name = data.Bones.Items[i].Name;
|
||||||
menu.AddSeparator("");
|
if (name.StartsWith(targetAttribute.startsWith))
|
||||||
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
for (int i = 0; i < data.Bones.Count; i++) {
|
}
|
||||||
string name = data.Bones.Items[i].Name;
|
}
|
||||||
if (name.StartsWith(targetAttribute.startsWith))
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomPropertyDrawer(typeof(SpineAtlasRegion))]
|
||||||
|
public class SpineAtlasRegionDrawer : PropertyDrawer {
|
||||||
|
Component component;
|
||||||
|
SerializedProperty atlasProp;
|
||||||
|
|
||||||
|
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
|
||||||
|
if (property.propertyType != SerializedPropertyType.String) {
|
||||||
|
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
component = (Component)property.serializedObject.targetObject;
|
||||||
|
|
||||||
|
if (component != null)
|
||||||
|
atlasProp = property.serializedObject.FindProperty("atlasAsset");
|
||||||
|
else
|
||||||
|
atlasProp = null;
|
||||||
|
|
||||||
|
|
||||||
|
if (atlasProp == null) {
|
||||||
|
EditorGUI.LabelField(position, "ERROR:", "Must have AtlasAsset variable!");
|
||||||
|
return;
|
||||||
|
} else if (atlasProp.objectReferenceValue == null) {
|
||||||
|
EditorGUI.LabelField(position, "ERROR:", "Atlas variable must not be null!");
|
||||||
|
return;
|
||||||
|
} else if (atlasProp.objectReferenceValue.GetType() != typeof(AtlasAsset)) {
|
||||||
|
EditorGUI.LabelField(position, "ERROR:", "Atlas variable must be of type AtlasAsset!");
|
||||||
|
}
|
||||||
|
|
||||||
|
position = EditorGUI.PrefixLabel(position, label);
|
||||||
|
|
||||||
|
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
||||||
|
Selector(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Selector (SerializedProperty property) {
|
||||||
|
GenericMenu menu = new GenericMenu();
|
||||||
|
AtlasAsset atlasAsset = (AtlasAsset)atlasProp.objectReferenceValue;
|
||||||
|
Atlas atlas = atlasAsset.GetAtlas();
|
||||||
|
FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic);
|
||||||
|
List<AtlasRegion> regions = (List<AtlasRegion>)field.GetValue(atlas);
|
||||||
|
|
||||||
|
for (int i = 0; i < regions.Count; i++) {
|
||||||
|
string name = regions[i].name;
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
menu.ShowAsContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void HandleSelect (object val) {
|
||||||
|
var pair = (SpineDrawerValuePair)val;
|
||||||
|
pair.property.stringValue = pair.str;
|
||||||
|
pair.property.serializedObject.ApplyModifiedProperties();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineAtlasRegion))]
|
|
||||||
public class SpineAtlasRegionDrawer : PropertyDrawer {
|
|
||||||
Component component;
|
|
||||||
SerializedProperty atlasProp;
|
|
||||||
|
|
||||||
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
|
|
||||||
if (property.propertyType != SerializedPropertyType.String) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
component = (Component)property.serializedObject.targetObject;
|
|
||||||
|
|
||||||
if (component != null)
|
|
||||||
atlasProp = property.serializedObject.FindProperty("atlasAsset");
|
|
||||||
else
|
|
||||||
atlasProp = null;
|
|
||||||
|
|
||||||
|
|
||||||
if (atlasProp == null) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Must have AtlasAsset variable!");
|
|
||||||
return;
|
|
||||||
} else if (atlasProp.objectReferenceValue == null) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Atlas variable must not be null!");
|
|
||||||
return;
|
|
||||||
} else if (atlasProp.objectReferenceValue.GetType() != typeof(AtlasAsset)) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Atlas variable must be of type AtlasAsset!");
|
|
||||||
}
|
|
||||||
|
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
|
||||||
|
|
||||||
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
|
||||||
Selector(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Selector (SerializedProperty property) {
|
|
||||||
GenericMenu menu = new GenericMenu();
|
|
||||||
AtlasAsset atlasAsset = (AtlasAsset)atlasProp.objectReferenceValue;
|
|
||||||
Atlas atlas = atlasAsset.GetAtlas();
|
|
||||||
FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic);
|
|
||||||
List<AtlasRegion> regions = (List<AtlasRegion>)field.GetValue(atlas);
|
|
||||||
|
|
||||||
for (int i = 0; i < regions.Count; i++) {
|
|
||||||
string name = regions[i].name;
|
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
menu.ShowAsContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void HandleSelect (object val) {
|
|
||||||
var pair = (SpineDrawerValuePair)val;
|
|
||||||
pair.property.stringValue = pair.str;
|
|
||||||
pair.property.serializedObject.ApplyModifiedProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -35,7 +35,7 @@ using UnityEditor;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Spine.Unity {
|
namespace Spine.Unity.Editor {
|
||||||
public static class SpineInspectorUtility {
|
public static class SpineInspectorUtility {
|
||||||
|
|
||||||
public static string Pluralize (int n, string singular, string plural) {
|
public static string Pluralize (int n, string singular, string plural) {
|
||||||
@ -100,5 +100,4 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,52 +33,56 @@ using UnityEngine;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
[CustomEditor(typeof(BoundingBoxFollower))]
|
namespace Spine.Unity.Editor {
|
||||||
public class BoundingBoxFollowerInspector : Editor {
|
|
||||||
SerializedProperty skeletonRenderer, slotName;
|
[CustomEditor(typeof(BoundingBoxFollower))]
|
||||||
BoundingBoxFollower follower;
|
public class BoundingBoxFollowerInspector : UnityEditor.Editor {
|
||||||
bool needToReset = false;
|
SerializedProperty skeletonRenderer, slotName;
|
||||||
|
BoundingBoxFollower follower;
|
||||||
|
bool needToReset = false;
|
||||||
|
|
||||||
void OnEnable () {
|
void OnEnable () {
|
||||||
skeletonRenderer = serializedObject.FindProperty("skeletonRenderer");
|
skeletonRenderer = serializedObject.FindProperty("skeletonRenderer");
|
||||||
slotName = serializedObject.FindProperty("slotName");
|
slotName = serializedObject.FindProperty("slotName");
|
||||||
follower = (BoundingBoxFollower)target;
|
follower = (BoundingBoxFollower)target;
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnInspectorGUI () {
|
|
||||||
if (needToReset) {
|
|
||||||
follower.HandleReset(null);
|
|
||||||
needToReset = false;
|
|
||||||
}
|
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
EditorGUILayout.PropertyField(skeletonRenderer);
|
|
||||||
EditorGUILayout.PropertyField(slotName, new GUIContent("Slot"));
|
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck()){
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
|
||||||
needToReset = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasBone = follower.GetComponent<BoneFollower>() != null;
|
public override void OnInspectorGUI () {
|
||||||
|
if (needToReset) {
|
||||||
|
follower.HandleReset(null);
|
||||||
|
needToReset = false;
|
||||||
|
}
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
EditorGUILayout.PropertyField(skeletonRenderer);
|
||||||
|
EditorGUILayout.PropertyField(slotName, new GUIContent("Slot"));
|
||||||
|
|
||||||
EditorGUI.BeginDisabledGroup(hasBone || follower.Slot == null);
|
if (EditorGUI.EndChangeCheck()){
|
||||||
{
|
serializedObject.ApplyModifiedProperties();
|
||||||
if (GUILayout.Button(new GUIContent("Add Bone Follower", SpineEditorUtilities.Icons.bone))) {
|
needToReset = true;
|
||||||
var boneFollower = follower.gameObject.AddComponent<BoneFollower>();
|
}
|
||||||
boneFollower.boneName = follower.Slot.Data.BoneData.Name;
|
|
||||||
|
bool hasBone = follower.GetComponent<BoneFollower>() != null;
|
||||||
|
|
||||||
|
EditorGUI.BeginDisabledGroup(hasBone || follower.Slot == null);
|
||||||
|
{
|
||||||
|
if (GUILayout.Button(new GUIContent("Add Bone Follower", SpineEditorUtilities.Icons.bone))) {
|
||||||
|
var boneFollower = follower.gameObject.AddComponent<BoneFollower>();
|
||||||
|
boneFollower.boneName = follower.Slot.Data.BoneData.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EditorGUI.EndDisabledGroup();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//GUILayout.Space(20);
|
||||||
|
GUILayout.Label("Attachment Names", EditorStyles.boldLabel);
|
||||||
|
foreach (var kp in follower.attachmentNameTable) {
|
||||||
|
string name = kp.Value;
|
||||||
|
var collider = follower.colliderTable[kp.Key];
|
||||||
|
bool isPlaceholder = name != kp.Key.Name;
|
||||||
|
collider.enabled = EditorGUILayout.ToggleLeft(new GUIContent(!isPlaceholder ? name : name + " [" + kp.Key.Name + "]", isPlaceholder ? SpineEditorUtilities.Icons.skinPlaceholder : SpineEditorUtilities.Icons.boundingBox), collider.enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EditorGUI.EndDisabledGroup();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//GUILayout.Space(20);
|
|
||||||
GUILayout.Label("Attachment Names", EditorStyles.boldLabel);
|
|
||||||
foreach (var kp in follower.attachmentNameTable) {
|
|
||||||
string name = kp.Value;
|
|
||||||
var collider = follower.colliderTable[kp.Key];
|
|
||||||
bool isPlaceholder = name != kp.Key.Name;
|
|
||||||
collider.enabled = EditorGUILayout.ToggleLeft(new GUIContent(!isPlaceholder ? name : name + " [" + kp.Key.Name + "]", isPlaceholder ? SpineEditorUtilities.Icons.skinPlaceholder : SpineEditorUtilities.Icons.boundingBox), collider.enabled);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ using UnityEngine;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using Spine;
|
using Spine;
|
||||||
|
|
||||||
namespace Spine {
|
namespace Spine.Unity {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
|
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
|
||||||
/// The routine will pause until the AnimationState.TrackEntry fires its Complete event.</summary>
|
/// The routine will pause until the AnimationState.TrackEntry fires its Complete event.</summary>
|
||||||
|
|||||||
@ -37,7 +37,7 @@ using UnityEngine;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using Spine;
|
using Spine;
|
||||||
|
|
||||||
namespace Spine {
|
namespace Spine.Unity {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
|
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
|
||||||
/// The routine will pause until the AnimationState fires an event matching the given event name or EventData reference.</summary>
|
/// The routine will pause until the AnimationState fires an event matching the given event name or EventData reference.</summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user