This commit is contained in:
badlogic 2018-11-19 13:27:56 +01:00
commit 8945d209c5
3 changed files with 94 additions and 90 deletions

View File

@ -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));
}
}
}
}

View File

@ -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);
/// <summary>OnRebuild is raised after the Skeleton is successfully initialized.</summary>
public event SkeletonRendererDelegate OnRebuild;
/// <summary> Occurs after the vertex data is populated every frame, before the vertices are pushed into the mesh.</summary>
public event Spine.Unity.MeshGeneratorDelegate OnPostProcessVertices;
public SkeletonDataAsset skeletonDataAsset;
public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } } // ISkeletonComponent
[SerializeField] public SkeletonDataAsset skeletonDataAsset;
#region Initialization settings
/// <summary>Skin name to use when the Skeleton is initialized.</summary>
[SpineSkin(defaultAsEmptyString:true)] public string initialSkinName;
[SerializeField] [SpineSkin(defaultAsEmptyString:true)] public string initialSkinName;
/// <summary>Flip X and Y to use when the Skeleton is initialized.</summary>
public bool initialFlipX, initialFlipY;
[SerializeField] public bool initialFlipX, initialFlipY;
#endregion
#region Advanced Render Settings
@ -121,6 +109,9 @@ namespace Spine.Unity {
}
}
}
/// <summary> Occurs after the vertex data is populated every frame, before the vertices are pushed into the mesh.</summary>
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);
/// <summary>OnRebuild is raised after the Skeleton is successfully initialized.</summary>
public event SkeletonRendererDelegate OnRebuild;
public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } } // ISkeletonComponent
#region Runtime Instantiation
public static T NewSpineGameObject<T> (SkeletonDataAsset skeletonDataAsset) where T : SkeletonRenderer {
return SkeletonRenderer.AddSpineComponent<T>(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;

View File

@ -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 {
/// <summary>
/// Smart popup menu for Spine Bones
/// </summary>
/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
/// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
/// <param name = "fallbackToTextField">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.</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 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 {
/// <summary>
/// Smart popup menu for Spine Animations
/// </summary>
/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
/// <param name = "fallbackToTextField">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.</param>
/// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty 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 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 {
/// <summary>
/// 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.
/// </param>
/// <param name="fallbackToTextField">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.</param>
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 {
/// <summary>
/// Smart popup menu for Spine Events (Spine.PathConstraint)
/// </summary>
/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
/// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty 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 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 {
/// <summary>
/// Smart popup menu for Spine Transform Constraints (Spine.TransformConstraint)
@ -142,6 +173,24 @@ namespace Spine.Unity {
}
}
public class SpinePathConstraint : SpineAttributeBase {
/// <summary>
/// Smart popup menu for Spine Events (Spine.PathConstraint)
/// </summary>
/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
/// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty 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 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 {
/// <summary>
/// Smart popup menu for Spine Skins
@ -166,25 +215,6 @@ namespace Spine.Unity {
}
}
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 = "fallbackToTextField">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.</param>
/// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty 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 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 {
/// <summary>
/// Smart popup menu for Spine Bones
/// </summary>
/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
/// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
/// <param name = "fallbackToTextField">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.</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 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;