mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[unity] Unified interfaces for Skeleton instance components. Used by SpineAttributeDrawers.
This commit is contained in:
parent
a7661270c0
commit
e23bec8ddb
@ -38,10 +38,10 @@ namespace Spine.Unity.Editor {
|
|||||||
if (dataProperty != null) {
|
if (dataProperty != null) {
|
||||||
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
||||||
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
||||||
} else if (dataProperty.objectReferenceValue is SkeletonRenderer) {
|
} else if (dataProperty.objectReferenceValue is ISkeletonComponent) {
|
||||||
var renderer = (SkeletonRenderer)dataProperty.objectReferenceValue;
|
var skeletonComponent = (ISkeletonComponent)dataProperty.objectReferenceValue;
|
||||||
if (renderer != null)
|
if (skeletonComponent != null)
|
||||||
skeletonDataAsset = renderer.skeletonDataAsset;
|
skeletonDataAsset = skeletonComponent.SkeletonDataAsset;
|
||||||
} else {
|
} else {
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
||||||
return;
|
return;
|
||||||
@ -49,10 +49,9 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
} else if (property.serializedObject.targetObject is Component) {
|
} else if (property.serializedObject.targetObject is Component) {
|
||||||
var component = (Component)property.serializedObject.targetObject;
|
var component = (Component)property.serializedObject.targetObject;
|
||||||
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
ISkeletonComponent skeletonComponent = component.GetComponentInChildren(typeof(ISkeletonComponent)) as ISkeletonComponent;
|
||||||
var skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
if (skeletonComponent != null)
|
||||||
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
skeletonDataAsset = skeletonComponent.SkeletonDataAsset;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skeletonDataAsset == null) {
|
if (skeletonDataAsset == null) {
|
||||||
|
|||||||
@ -31,7 +31,9 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Spine.Unity {
|
namespace Spine.Unity {
|
||||||
public delegate void UpdateBonesDelegate (ISkeletonAnimation skeletonRenderer);
|
public delegate void UpdateBonesDelegate (ISkeletonAnimation animatedSkeletonComponent);
|
||||||
|
|
||||||
|
/// <summary>A Spine-Unity Component that animates a Skeleton but not necessarily with a Spine.AnimationState.</summary>
|
||||||
public interface ISkeletonAnimation {
|
public interface ISkeletonAnimation {
|
||||||
event UpdateBonesDelegate UpdateLocal;
|
event UpdateBonesDelegate UpdateLocal;
|
||||||
event UpdateBonesDelegate UpdateWorld;
|
event UpdateBonesDelegate UpdateWorld;
|
||||||
@ -40,4 +42,19 @@ namespace Spine.Unity {
|
|||||||
void LateUpdate ();
|
void LateUpdate ();
|
||||||
Skeleton Skeleton { get; }
|
Skeleton Skeleton { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>A Spine-Unity Component that manages a Spine.Skeleton instance, instantiated from a SkeletonDataAsset.</summary>
|
||||||
|
public interface ISkeletonComponent {
|
||||||
|
/// <summary>Gets the SkeletonDataAsset of the Spine Component.</summary>
|
||||||
|
SkeletonDataAsset SkeletonDataAsset { get; }
|
||||||
|
|
||||||
|
/// <summary>Gets the Spine.Skeleton instance of the Spine Component. This is equivalent to SkeletonRenderer's .skeleton.</summary>
|
||||||
|
Skeleton Skeleton { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>A Spine-Unity Component that uses a Spine.AnimationState to animate its skeleton.</summary>
|
||||||
|
public interface IAnimationStateComponent {
|
||||||
|
/// <summary>Gets the Spine.AnimationState of the animated Spine Component. This is equivalent to SkeletonAnimation.state.</summary>
|
||||||
|
AnimationState AnimationState { get; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,10 +39,11 @@ using Spine;
|
|||||||
namespace Spine.Unity {
|
namespace Spine.Unity {
|
||||||
[ExecuteInEditMode, RequireComponent(typeof(CanvasRenderer), typeof(RectTransform)), DisallowMultipleComponent]
|
[ExecuteInEditMode, RequireComponent(typeof(CanvasRenderer), typeof(RectTransform)), DisallowMultipleComponent]
|
||||||
[AddComponentMenu("Spine/SkeletonGraphic (Unity UI Canvas)")]
|
[AddComponentMenu("Spine/SkeletonGraphic (Unity UI Canvas)")]
|
||||||
public class SkeletonGraphic : MaskableGraphic {
|
public class SkeletonGraphic : MaskableGraphic, ISkeletonComponent, IAnimationStateComponent {
|
||||||
|
|
||||||
#region Inspector
|
#region Inspector
|
||||||
public SkeletonDataAsset skeletonDataAsset;
|
public SkeletonDataAsset skeletonDataAsset;
|
||||||
|
public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } }
|
||||||
|
|
||||||
[SpineSkin(dataField:"skeletonDataAsset")]
|
[SpineSkin(dataField:"skeletonDataAsset")]
|
||||||
public string initialSkinName = "default";
|
public string initialSkinName = "default";
|
||||||
|
|||||||
@ -37,12 +37,13 @@ namespace Spine.Unity {
|
|||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
[AddComponentMenu("Spine/SkeletonAnimation")]
|
[AddComponentMenu("Spine/SkeletonAnimation")]
|
||||||
[HelpURL("http://esotericsoftware.com/spine-unity-documentation#Controlling-Animation")]
|
[HelpURL("http://esotericsoftware.com/spine-unity-documentation#Controlling-Animation")]
|
||||||
public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation {
|
public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation, Spine.Unity.IAnimationStateComponent {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the Spine.AnimationState object of this SkeletonAnimation. You can control animations through it.
|
/// 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</summary>
|
/// Note that this object, like .skeleton, is not guaranteed to exist in Awake. Do all accesses and caching to it in Start</summary>
|
||||||
public Spine.AnimationState state;
|
public Spine.AnimationState state;
|
||||||
|
public Spine.AnimationState AnimationState { get { return this.state; } }
|
||||||
|
|
||||||
public event UpdateBonesDelegate UpdateLocal {
|
public event UpdateBonesDelegate UpdateLocal {
|
||||||
add { _UpdateLocal += value; }
|
add { _UpdateLocal += value; }
|
||||||
@ -63,18 +64,9 @@ namespace Spine.Unity {
|
|||||||
protected event UpdateBonesDelegate _UpdateWorld;
|
protected event UpdateBonesDelegate _UpdateWorld;
|
||||||
protected event UpdateBonesDelegate _UpdateComplete;
|
protected event UpdateBonesDelegate _UpdateComplete;
|
||||||
|
|
||||||
/// <summary>Gets the skeleton.</summary>
|
|
||||||
public Skeleton Skeleton {
|
|
||||||
get {
|
|
||||||
this.Initialize(false);
|
|
||||||
return this.skeleton;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[SpineAnimation]
|
[SpineAnimation]
|
||||||
private String _animationName;
|
private String _animationName;
|
||||||
|
|
||||||
public String AnimationName {
|
public String AnimationName {
|
||||||
get {
|
get {
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
@ -95,7 +87,7 @@ namespace Spine.Unity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == null || value.Length == 0)
|
if (string.IsNullOrEmpty(value))
|
||||||
state.ClearTrack(0);
|
state.ClearTrack(0);
|
||||||
else
|
else
|
||||||
state.SetAnimation(0, value, loop);
|
state.SetAnimation(0, value, loop);
|
||||||
@ -103,17 +95,13 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>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.</summary>
|
/// <summary>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.</summary>
|
||||||
#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.")]
|
[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;
|
public bool loop;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The rate at which animations progress over time. 1 means 100%. 0.5 means 50%.</summary>
|
/// The rate at which animations progress over time. 1 means 100%. 0.5 means 50%.</summary>
|
||||||
/// <remarks>AnimationState and TrackEntry also have their own timeScale. These are combined multiplicatively.</remarks>
|
/// <remarks>AnimationState and TrackEntry also have their own timeScale. These are combined multiplicatively.</remarks>
|
||||||
#if UNITY_5
|
|
||||||
[Tooltip("The rate at which animations progress over time. 1 means 100%. 0.5 means 50%.")]
|
[Tooltip("The rate at which animations progress over time. 1 means 100%. 0.5 means 50%.")]
|
||||||
#endif
|
|
||||||
public float timeScale = 1;
|
public float timeScale = 1;
|
||||||
|
|
||||||
#region Runtime Instantiation
|
#region Runtime Instantiation
|
||||||
@ -155,8 +143,8 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!string.IsNullOrEmpty(_animationName)) {
|
if (!string.IsNullOrEmpty(_animationName)) {
|
||||||
state.SetAnimation(0, _animationName, loop);
|
state.SetAnimation(0, _animationName, loop);
|
||||||
Update(0);
|
Update(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,8 +33,6 @@ namespace Spine.Unity {
|
|||||||
protected event UpdateBonesDelegate _UpdateWorld;
|
protected event UpdateBonesDelegate _UpdateWorld;
|
||||||
protected event UpdateBonesDelegate _UpdateComplete;
|
protected event UpdateBonesDelegate _UpdateComplete;
|
||||||
|
|
||||||
public Skeleton Skeleton { get { return this.skeleton; } }
|
|
||||||
|
|
||||||
readonly Dictionary<int, Spine.Animation> animationTable = new Dictionary<int, Spine.Animation>();
|
readonly Dictionary<int, Spine.Animation> animationTable = new Dictionary<int, Spine.Animation>();
|
||||||
readonly Dictionary<AnimationClip, int> clipNameHashCodeTable = new Dictionary<AnimationClip, int>();
|
readonly Dictionary<AnimationClip, int> clipNameHashCodeTable = new Dictionary<AnimationClip, int>();
|
||||||
Animator animator;
|
Animator animator;
|
||||||
|
|||||||
@ -46,12 +46,13 @@ namespace Spine.Unity {
|
|||||||
/// <summary>Renders a skeleton.</summary>
|
/// <summary>Renders a skeleton.</summary>
|
||||||
[ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer)), DisallowMultipleComponent]
|
[ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer)), DisallowMultipleComponent]
|
||||||
[HelpURL("http://esotericsoftware.com/spine-unity-documentation#Rendering")]
|
[HelpURL("http://esotericsoftware.com/spine-unity-documentation#Rendering")]
|
||||||
public class SkeletonRenderer : MonoBehaviour {
|
public class SkeletonRenderer : MonoBehaviour, ISkeletonComponent {
|
||||||
|
|
||||||
public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer);
|
public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer);
|
||||||
public SkeletonRendererDelegate OnRebuild;
|
public SkeletonRendererDelegate OnRebuild;
|
||||||
|
|
||||||
public SkeletonDataAsset skeletonDataAsset;
|
public SkeletonDataAsset skeletonDataAsset;
|
||||||
|
public SkeletonDataAsset SkeletonDataAsset { get { return skeletonDataAsset; } }
|
||||||
public String initialSkinName;
|
public String initialSkinName;
|
||||||
|
|
||||||
#region Advanced
|
#region Advanced
|
||||||
@ -119,6 +120,12 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
[System.NonSerialized] public bool valid;
|
[System.NonSerialized] public bool valid;
|
||||||
[System.NonSerialized] public Skeleton skeleton;
|
[System.NonSerialized] public Skeleton skeleton;
|
||||||
|
public Skeleton Skeleton {
|
||||||
|
get {
|
||||||
|
Initialize(false);
|
||||||
|
return skeleton;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Spine.Unity.DoubleBuffered<SkeletonRenderer.SmartMesh> doubleBufferedMesh;
|
Spine.Unity.DoubleBuffered<SkeletonRenderer.SmartMesh> doubleBufferedMesh;
|
||||||
readonly SmartMesh.Instruction currentInstructions = new SmartMesh.Instruction();
|
readonly SmartMesh.Instruction currentInstructions = new SmartMesh.Instruction();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user