SpineBeginnerTwo.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using UnityEngine;
  2. using System.Collections;
  3. using Spine.Unity;
  4. public class SpineBeginnerTwo : MonoBehaviour {
  5. #region Inspector
  6. // [SpineAnimation] attribute allows an Inspector dropdown of Spine animation names coming form SkeletonAnimation.
  7. [SpineAnimation]
  8. public string runAnimationName;
  9. [SpineAnimation]
  10. public string idleAnimationName;
  11. [SpineAnimation]
  12. public string walkAnimationName;
  13. [SpineAnimation]
  14. public string shootAnimationName;
  15. #endregion
  16. SkeletonAnimation skeletonAnimation;
  17. // Spine.AnimationState and Spine.Skeleton are not Unity-serialized objects. You will not see them as fields in the inspector.
  18. public Spine.AnimationState spineAnimationState;
  19. public Spine.Skeleton skeleton;
  20. void Start () {
  21. // Make sure you get these AnimationState and Skeleton references in Start or Later. Getting and using them in Awake is not guaranteed by default execution order.
  22. skeletonAnimation = GetComponent<SkeletonAnimation>();
  23. spineAnimationState = skeletonAnimation.state;
  24. skeleton = skeletonAnimation.skeleton;
  25. StartCoroutine(DoDemoRoutine());
  26. }
  27. /// <summary>This is an infinitely repeating Unity Coroutine. Read the Unity documentation on Coroutines to learn more.</summary>
  28. IEnumerator DoDemoRoutine () {
  29. while (true) {
  30. // SetAnimation is the basic way to set an animation.
  31. // SetAnimation sets the animation and starts playing it from the beginning.
  32. // Common Mistake: If you keep calling it in Update, it will keep showing the first pose of the animation, do don't do that.
  33. spineAnimationState.SetAnimation(0, walkAnimationName, true);
  34. yield return new WaitForSeconds(1.5f);
  35. // skeletonAnimation.AnimationName = runAnimationName; // this line also works for quick testing/simple uses.
  36. spineAnimationState.SetAnimation(0, runAnimationName, true);
  37. yield return new WaitForSeconds(1.5f);
  38. spineAnimationState.SetAnimation(0, idleAnimationName, true);
  39. yield return new WaitForSeconds(1f);
  40. skeleton.FlipX = true; // skeleton allows you to flip the skeleton.
  41. yield return new WaitForSeconds(0.5f);
  42. skeleton.FlipX = false;
  43. yield return new WaitForSeconds(0.5f);
  44. }
  45. }
  46. }