diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs index 4e71bf522..651d1c0b9 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs @@ -323,7 +323,7 @@ namespace Spine.Unity.Editor { } foreach (var a in animations) { - var animationName = a.Name; + string animationName = a.Name; eventNames.Add(animationName); menuItems.Add(new GUIContent(animationName, SpineEditorUtilities.Icons.userEvent)); } @@ -336,9 +336,14 @@ namespace Spine.Unity.Editor { menu.AddItem(new GUIContent(NoneString), !property.hasMultipleDifferentValues && string.IsNullOrEmpty(property.stringValue), HandleSelect, new SpineDrawerValuePair(string.Empty, property)); 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), !property.hasMultipleDifferentValues && name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property)); + var eventObject = events.Items[i]; + string name = eventObject.Name; + if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal)) { + if (!TargetAttribute.audioOnly || !string.IsNullOrEmpty(eventObject.AudioPath)) { + menu.AddItem(new GUIContent(name), !property.hasMultipleDifferentValues && name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property)); + } + } + } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs index 641b42047..df8d8a8a3 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs @@ -39,26 +39,14 @@ namespace Spine.Unity { [ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer)), DisallowMultipleComponent] [HelpURL("http://esotericsoftware.com/spine-unity-rendering")] public class SkeletonRenderer : MonoBehaviour, ISkeletonComponent, IHasSkeletonDataAsset { - - public bool logErrors = false; - - public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer); - - /// OnRebuild is raised after the Skeleton is successfully initialized. - public event SkeletonRendererDelegate OnRebuild; - - /// Occurs after the vertex data is populated every frame, before the vertices are pushed into the mesh. - public event Spine.Unity.MeshGeneratorDelegate OnPostProcessVertices; - - public SkeletonDataAsset skeletonDataAsset; - public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } } // ISkeletonComponent + [SerializeField] public SkeletonDataAsset skeletonDataAsset; #region Initialization settings /// Skin name to use when the Skeleton is initialized. - [SpineSkin(defaultAsEmptyString:true)] public string initialSkinName; + [SerializeField] [SpineSkin(defaultAsEmptyString:true)] public string initialSkinName; /// Flip X and Y to use when the Skeleton is initialized. - public bool initialFlipX, initialFlipY; + [SerializeField] public bool initialFlipX, initialFlipY; #endregion #region Advanced Render Settings @@ -121,6 +109,9 @@ namespace Spine.Unity { } } } + + /// Occurs after the vertex data is populated every frame, before the vertices are pushed into the mesh. + public event Spine.Unity.MeshGeneratorDelegate OnPostProcessVertices; #endif #if SPINE_OPTIONAL_MATERIALOVERRIDE @@ -156,6 +147,13 @@ namespace Spine.Unity { } #endregion + public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer); + + /// OnRebuild is raised after the Skeleton is successfully initialized. + public event SkeletonRendererDelegate OnRebuild; + + public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } } // ISkeletonComponent + #region Runtime Instantiation public static T NewSpineGameObject (SkeletonDataAsset skeletonDataAsset) where T : SkeletonRenderer { return SkeletonRenderer.AddSpineComponent(new GameObject("New Spine GameObject"), skeletonDataAsset); @@ -185,6 +183,7 @@ namespace Spine.Unity { } #endregion + public virtual void Awake () { Initialize(false); } @@ -237,10 +236,8 @@ namespace Spine.Unity { valid = false; } - if (skeletonDataAsset == null) { - if (logErrors) Debug.LogError("Missing SkeletonData asset.", this); + if (skeletonDataAsset == null) return; - } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); if (skeletonData == null) return; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/SpineAttributes.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/SpineAttributes.cs index acb5b5ec0..97e0efe87 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/SpineAttributes.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/SpineAttributes.cs @@ -28,8 +28,6 @@ * POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -// Contributed by: Mitch Thompson - using UnityEngine; using System; using System.Collections; @@ -44,6 +42,34 @@ namespace Spine.Unity { public bool fallbackToTextField = false; } + public class SpineBone : SpineAttributeBase { + /// + /// Smart popup menu for Spine Bones + /// + /// Filters popup results to elements that begin with supplied string. + /// If true, the dropdown list will include a "none" option which stored as an empty string. + /// If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error. + /// 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() will be called as a fallback. + /// + public SpineBone (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) { + this.startsWith = startsWith; + this.dataField = dataField; + this.includeNone = includeNone; + this.fallbackToTextField = fallbackToTextField; + } + + public static Spine.Bone GetBone (string boneName, SkeletonRenderer renderer) { + return renderer.skeleton == null ? null : renderer.skeleton.FindBone(boneName); + } + + public static Spine.BoneData GetBoneData (string boneName, SkeletonDataAsset skeletonDataAsset) { + var data = skeletonDataAsset.GetSkeletonData(true); + return data.FindBone(boneName); + } + } + public class SpineSlot : SpineAttributeBase { public bool containsBoundingBoxes = false; @@ -67,6 +93,25 @@ namespace Spine.Unity { } } + public class SpineAnimation : SpineAttributeBase { + /// + /// Smart popup menu for Spine Animations + /// + /// Filters popup results to elements that begin with supplied string. + /// If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error. + /// If true, the dropdown list will include a "none" option which stored as an empty string. + /// 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() will be called as a fallback. + /// + public SpineAnimation (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) { + this.startsWith = startsWith; + this.dataField = dataField; + this.includeNone = includeNone; + this.fallbackToTextField = fallbackToTextField; + } + } + public class SpineEvent : SpineAttributeBase { /// /// Smart popup menu for Spine Events (Spine.EventData) @@ -78,11 +123,15 @@ namespace Spine.Unity { /// If left empty and the script the attribute is applied to is derived from Component, GetComponent(SkeletonRenderer)() will be called as a fallback. /// /// If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error. - public SpineEvent (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) { + + public bool audioOnly = false; + + public SpineEvent (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false, bool audioOnly = false) { this.startsWith = startsWith; this.dataField = dataField; this.includeNone = includeNone; this.fallbackToTextField = fallbackToTextField; + this.audioOnly = audioOnly; } } @@ -105,24 +154,6 @@ namespace Spine.Unity { } } - public class SpinePathConstraint : SpineAttributeBase { - /// - /// Smart popup menu for Spine Events (Spine.PathConstraint) - /// - /// Filters popup results to elements that begin with supplied string. - /// If true, the dropdown list will include a "none" option which stored as an empty string. - /// 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. - /// - public SpinePathConstraint (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) { - this.startsWith = startsWith; - this.dataField = dataField; - this.includeNone = includeNone; - this.fallbackToTextField = fallbackToTextField; - } - } - public class SpineTransformConstraint : SpineAttributeBase { /// /// Smart popup menu for Spine Transform Constraints (Spine.TransformConstraint) @@ -142,6 +173,24 @@ namespace Spine.Unity { } } + public class SpinePathConstraint : SpineAttributeBase { + /// + /// Smart popup menu for Spine Events (Spine.PathConstraint) + /// + /// Filters popup results to elements that begin with supplied string. + /// If true, the dropdown list will include a "none" option which stored as an empty string. + /// 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. + /// + public SpinePathConstraint (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) { + this.startsWith = startsWith; + this.dataField = dataField; + this.includeNone = includeNone; + this.fallbackToTextField = fallbackToTextField; + } + } + public class SpineSkin : SpineAttributeBase { /// /// Smart popup menu for Spine Skins @@ -166,25 +215,6 @@ namespace Spine.Unity { } } - public class SpineAnimation : SpineAttributeBase { - /// - /// Smart popup menu for Spine Animations - /// - /// Filters popup results to elements that begin with supplied string. - /// If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error. - /// If true, the dropdown list will include a "none" option which stored as an empty string. - /// 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() will be called as a fallback. - /// - public SpineAnimation (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) { - this.startsWith = startsWith; - this.dataField = dataField; - this.includeNone = includeNone; - this.fallbackToTextField = fallbackToTextField; - } - } - public class SpineAttachment : SpineAttributeBase { public bool returnAttachmentPath = false; public bool currentSkinOnly = false; @@ -258,34 +288,6 @@ namespace Spine.Unity { } } - public class SpineBone : SpineAttributeBase { - /// - /// Smart popup menu for Spine Bones - /// - /// Filters popup results to elements that begin with supplied string. - /// If true, the dropdown list will include a "none" option which stored as an empty string. - /// If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error. - /// 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() will be called as a fallback. - /// - public SpineBone (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) { - this.startsWith = startsWith; - this.dataField = dataField; - this.includeNone = includeNone; - this.fallbackToTextField = fallbackToTextField; - } - - public static Spine.Bone GetBone(string boneName, SkeletonRenderer renderer) { - return renderer.skeleton == null ? null : renderer.skeleton.FindBone(boneName); - } - - public static Spine.BoneData GetBoneData(string boneName, SkeletonDataAsset skeletonDataAsset) { - var data = skeletonDataAsset.GetSkeletonData(true); - return data.FindBone(boneName); - } - } - public class SpineAtlasRegion : PropertyAttribute { public string atlasAssetField;