Spineboy.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /******************************************************************************
  2. * Spine Runtimes Software License
  3. * Version 2.3
  4. *
  5. * Copyright (c) 2013-2015, Esoteric Software
  6. * All rights reserved.
  7. *
  8. * You are granted a perpetual, non-exclusive, non-sublicensable and
  9. * non-transferable license to use, install, execute and perform the Spine
  10. * Runtimes Software (the "Software") and derivative works solely for personal
  11. * or internal use. Without the written permission of Esoteric Software (see
  12. * Section 2 of the Spine Software License Agreement), you may not (a) modify,
  13. * translate, adapt or otherwise create derivative works, improvements of the
  14. * Software or develop new applications using the Software or (b) remove,
  15. * delete, alter or obscure any trademarks or any copyright, trademark, patent
  16. * or other intellectual property or proprietary rights notices on or in the
  17. * Software, including any copy thereof. Redistributions in binary or source
  18. * form must include this license and terms.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  21. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  23. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  26. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  28. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  29. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *****************************************************************************/
  31. using UnityEngine;
  32. using System.Collections;
  33. using Spine;
  34. using System;
  35. using Spine.Unity;
  36. public class Spineboy : MonoBehaviour {
  37. SkeletonAnimation skeletonAnimation;
  38. public void Start () {
  39. // Get the SkeletonAnimation component for the GameObject this script is attached to.
  40. skeletonAnimation = GetComponent<SkeletonAnimation>();
  41. // Call our method any time an animation fires an event.
  42. skeletonAnimation.state.Event += Event;
  43. // A lambda can be used for the callback instead of a method.
  44. skeletonAnimation.state.End += (state, trackIndex) => {
  45. Debug.Log("start: " + state.GetCurrent(trackIndex));
  46. };
  47. // Queue jump to be played on track 0 two seconds after the starting animation.
  48. skeletonAnimation.state.AddAnimation(0, "jump", false, 2);
  49. // Queue walk to be looped on track 0 after the jump animation.
  50. skeletonAnimation.state.AddAnimation(0, "run", true, 0);
  51. }
  52. public void Event (Spine.AnimationState state, int trackIndex, Spine.Event e) {
  53. Debug.Log(trackIndex + " " + state.GetCurrent(trackIndex) + ": event " + e + ", " + e.Int);
  54. }
  55. public void OnMouseDown () {
  56. // Set jump to be played on track 0 immediately.
  57. skeletonAnimation.state.SetAnimation(0, "jump", false);
  58. // Queue walk to be looped on track 0 after the jump animation.
  59. skeletonAnimation.state.AddAnimation(0, "run", true, 0);
  60. }
  61. }