diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimation.cs b/spine-unity/Assets/spine-unity/SkeletonAnimation.cs
index 00e37f4a0..b8479b016 100644
--- a/spine-unity/Assets/spine-unity/SkeletonAnimation.cs
+++ b/spine-unity/Assets/spine-unity/SkeletonAnimation.cs
@@ -104,39 +104,25 @@ public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation {
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.
+ /// 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 AutoReset
- /**
- [Tooltip("Setting this to true makes the SkeletonAnimation behave similar to Spine editor. New animations will not inherit the pose from a previous animation. If you need to intermittently and programmatically pose your skeleton, leave this false.")]
- [SerializeField]
- protected bool autoReset = false;
-
- ///
- /// Setting this to true makes the SkeletonAnimation behave similar to Spine editor.
- /// New animations will not inherit the pose from a previous animation.
- /// If you need to intermittently and programmatically pose your skeleton, leave this false.
- public bool AutoReset {
- get { return this.autoReset; }
- set {
- if (!autoReset && value) {
- state.Start -= HandleNewAnimationAutoreset; // make sure there isn't a double-subscription.
- state.Start += HandleNewAnimationAutoreset;
- }
- autoReset = value;
- }
+ #region Runtime Instantiation
+ /// Adds and prepares a SkeletonAnimation component to a GameObject at runtime.
+ /// The newly instantiated SkeletonAnimation
+ public static SkeletonAnimation AddToGameObject (GameObject gameObject, SkeletonDataAsset skeletonDataAsset) {
+ return SkeletonRenderer.AddSpineComponent(gameObject, skeletonDataAsset);
}
- protected virtual void HandleNewAnimationAutoreset (Spine.AnimationState state, int trackIndex) {
- if (!autoReset) return;
- if (skeleton != null) skeleton.SetToSetupPose();
+ /// Instantiates a new UnityEngine.GameObject and adds a prepared SkeletonAnimation component to it.
+ /// The newly instantiated SkeletonAnimation component.
+ public static SkeletonAnimation NewSkeletonAnimationGameObject (SkeletonDataAsset skeletonDataAsset) {
+ return SkeletonRenderer.NewSpineGameObject(skeletonDataAsset);
}
- */
#endregion
public override void Reset () {
@@ -146,12 +132,6 @@ public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation {
state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
- /*
- if (autoReset) {
- state.Start += HandleNewAnimationAutoreset;
- }
- */
-
if (_animationName != null && _animationName.Length > 0) {
state.SetAnimation(0, _animationName, loop);
Update(0);
@@ -185,4 +165,5 @@ public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation {
_UpdateComplete(this);
}
}
+
}
diff --git a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs
index aad0dcaf8..5a2109e4e 100644
--- a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs
+++ b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs
@@ -76,6 +76,25 @@ public class SkeletonRenderer : MonoBehaviour {
private readonly ExposedList submeshes = new ExposedList();
private SkeletonUtilitySubmeshRenderer[] submeshRenderers;
+ #region Runtime Instantiation
+ /// Add and prepare a Spine component that derives from SkeletonRenderer to a GameObject at runtime.
+ /// T should be SkeletonRenderer or any of its derived classes.
+ public static T AddSpineComponent (GameObject gameObject, SkeletonDataAsset skeletonDataAsset) where T : SkeletonRenderer {
+ var c = gameObject.AddComponent();
+
+ if (skeletonDataAsset != null) {
+ c.skeletonDataAsset = skeletonDataAsset;
+ c.Reset(); // Method signature will change.
+ }
+
+ return c;
+ }
+
+ public static T NewSpineGameObject (SkeletonDataAsset skeletonDataAsset) where T : SkeletonRenderer {
+ return SkeletonRenderer.AddSpineComponent(new GameObject("New Spine GameObject"), skeletonDataAsset);
+ }
+ #endregion
+
public virtual void Awake () {
Reset();
}