diff --git a/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs b/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs index a4db8a87d..2211953a2 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs @@ -38,10 +38,10 @@ namespace Spine.Unity.Editor { if (dataProperty != null) { if (dataProperty.objectReferenceValue is SkeletonDataAsset) { skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue; - } else if (dataProperty.objectReferenceValue is SkeletonRenderer) { - var renderer = (SkeletonRenderer)dataProperty.objectReferenceValue; - if (renderer != null) - skeletonDataAsset = renderer.skeletonDataAsset; + } else if (dataProperty.objectReferenceValue is ISkeletonComponent) { + var skeletonComponent = (ISkeletonComponent)dataProperty.objectReferenceValue; + if (skeletonComponent != null) + skeletonDataAsset = skeletonComponent.SkeletonDataAsset; } else { EditorGUI.LabelField(position, "ERROR:", "Invalid reference type"); return; @@ -49,10 +49,9 @@ namespace Spine.Unity.Editor { } else if (property.serializedObject.targetObject is Component) { var component = (Component)property.serializedObject.targetObject; - if (component.GetComponentInChildren() != null) { - var skeletonRenderer = component.GetComponentInChildren(); - skeletonDataAsset = skeletonRenderer.skeletonDataAsset; - } + ISkeletonComponent skeletonComponent = component.GetComponentInChildren(typeof(ISkeletonComponent)) as ISkeletonComponent; + if (skeletonComponent != null) + skeletonDataAsset = skeletonComponent.SkeletonDataAsset; } if (skeletonDataAsset == null) { diff --git a/spine-unity/Assets/spine-unity/ISkeletonAnimation.cs b/spine-unity/Assets/spine-unity/ISkeletonAnimation.cs index fddac4897..44d664708 100644 --- a/spine-unity/Assets/spine-unity/ISkeletonAnimation.cs +++ b/spine-unity/Assets/spine-unity/ISkeletonAnimation.cs @@ -31,7 +31,9 @@ using UnityEngine; namespace Spine.Unity { - public delegate void UpdateBonesDelegate (ISkeletonAnimation skeletonRenderer); + public delegate void UpdateBonesDelegate (ISkeletonAnimation animatedSkeletonComponent); + + /// A Spine-Unity Component that animates a Skeleton but not necessarily with a Spine.AnimationState. public interface ISkeletonAnimation { event UpdateBonesDelegate UpdateLocal; event UpdateBonesDelegate UpdateWorld; @@ -39,5 +41,20 @@ namespace Spine.Unity { void LateUpdate (); Skeleton Skeleton { get; } - } + } + + /// A Spine-Unity Component that manages a Spine.Skeleton instance, instantiated from a SkeletonDataAsset. + public interface ISkeletonComponent { + /// Gets the SkeletonDataAsset of the Spine Component. + SkeletonDataAsset SkeletonDataAsset { get; } + + /// Gets the Spine.Skeleton instance of the Spine Component. This is equivalent to SkeletonRenderer's .skeleton. + Skeleton Skeleton { get; } + } + + /// A Spine-Unity Component that uses a Spine.AnimationState to animate its skeleton. + public interface IAnimationStateComponent { + /// Gets the Spine.AnimationState of the animated Spine Component. This is equivalent to SkeletonAnimation.state. + AnimationState AnimationState { get; } + } } diff --git a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs index 7e7c1b7f0..fa3d577b6 100644 --- a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs +++ b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs @@ -39,10 +39,11 @@ using Spine; namespace Spine.Unity { [ExecuteInEditMode, RequireComponent(typeof(CanvasRenderer), typeof(RectTransform)), DisallowMultipleComponent] [AddComponentMenu("Spine/SkeletonGraphic (Unity UI Canvas)")] - public class SkeletonGraphic : MaskableGraphic { + public class SkeletonGraphic : MaskableGraphic, ISkeletonComponent, IAnimationStateComponent { #region Inspector public SkeletonDataAsset skeletonDataAsset; + public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } } [SpineSkin(dataField:"skeletonDataAsset")] public string initialSkinName = "default"; diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimation.cs b/spine-unity/Assets/spine-unity/SkeletonAnimation.cs index 5608ec762..7fdf243b2 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimation.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimation.cs @@ -37,12 +37,13 @@ namespace Spine.Unity { [ExecuteInEditMode] [AddComponentMenu("Spine/SkeletonAnimation")] [HelpURL("http://esotericsoftware.com/spine-unity-documentation#Controlling-Animation")] - public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation { + public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation, Spine.Unity.IAnimationStateComponent { /// /// This is the Spine.AnimationState object of this SkeletonAnimation. You can control animations through it. /// Note that this object, like .skeleton, is not guaranteed to exist in Awake. Do all accesses and caching to it in Start public Spine.AnimationState state; + public Spine.AnimationState AnimationState { get { return this.state; } } public event UpdateBonesDelegate UpdateLocal { add { _UpdateLocal += value; } @@ -63,18 +64,9 @@ namespace Spine.Unity { protected event UpdateBonesDelegate _UpdateWorld; protected event UpdateBonesDelegate _UpdateComplete; - /// Gets the skeleton. - public Skeleton Skeleton { - get { - this.Initialize(false); - return this.skeleton; - } - } - [SerializeField] [SpineAnimation] private String _animationName; - public String AnimationName { get { if (!valid) { @@ -95,7 +87,7 @@ namespace Spine.Unity { return; } - if (value == null || value.Length == 0) + if (string.IsNullOrEmpty(value)) state.ClearTrack(0); else state.SetAnimation(0, value, loop); @@ -103,17 +95,13 @@ namespace Spine.Unity { } /// Whether or not an animation should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected. - #if UNITY_5 [Tooltip("Whether or not an animation should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected.")] - #endif public bool loop; /// /// The rate at which animations progress over time. 1 means 100%. 0.5 means 50%. /// AnimationState and TrackEntry also have their own timeScale. These are combined multiplicatively. - #if UNITY_5 [Tooltip("The rate at which animations progress over time. 1 means 100%. 0.5 means 50%.")] - #endif public float timeScale = 1; #region Runtime Instantiation @@ -155,8 +143,8 @@ namespace Spine.Unity { } #else if (!string.IsNullOrEmpty(_animationName)) { - state.SetAnimation(0, _animationName, loop); - Update(0); + state.SetAnimation(0, _animationName, loop); + Update(0); } #endif } diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs index d2ccd63e7..d84482081 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimator.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimator.cs @@ -33,8 +33,6 @@ namespace Spine.Unity { protected event UpdateBonesDelegate _UpdateWorld; protected event UpdateBonesDelegate _UpdateComplete; - public Skeleton Skeleton { get { return this.skeleton; } } - readonly Dictionary animationTable = new Dictionary(); readonly Dictionary clipNameHashCodeTable = new Dictionary(); Animator animator; diff --git a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs index a3bb70300..77526ac35 100644 --- a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs +++ b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs @@ -46,12 +46,13 @@ namespace Spine.Unity { /// Renders a skeleton. [ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer)), DisallowMultipleComponent] [HelpURL("http://esotericsoftware.com/spine-unity-documentation#Rendering")] - public class SkeletonRenderer : MonoBehaviour { + public class SkeletonRenderer : MonoBehaviour, ISkeletonComponent { public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer); public SkeletonRendererDelegate OnRebuild; public SkeletonDataAsset skeletonDataAsset; + public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } } public String initialSkinName; #region Advanced @@ -119,6 +120,12 @@ namespace Spine.Unity { [System.NonSerialized] public bool valid; [System.NonSerialized] public Skeleton skeleton; + public Skeleton Skeleton { + get { + Initialize(false); + return skeleton; + } + } Spine.Unity.DoubleBuffered doubleBufferedMesh; readonly SmartMesh.Instruction currentInstructions = new SmartMesh.Instruction();