From 6bbce812f880cd869f493da1f0b5e27e1676208b Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Mon, 6 May 2013 15:40:46 +0200 Subject: [PATCH] Refactored spine-unity, separated SkeletonComponent and SkeletonAnimation. Added animation: to SkeletonAnimation. See: http://www.esotericsoftware.com/forum/viewtopic.php?f=3&t=606 --- .../Assets/Plugins/Editor/Spine/Menus.cs | 37 ++++-- .../Spine/SkeletonAnimationInspector.cs | 116 ++++++++++++++++++ .../Spine/SkeletonAnimationInspector.cs.meta} | 2 +- .../Spine/SkeletonComponentInspector.cs | 39 +----- .../Assets/Plugins/Spine/SkeletonAnimation.cs | 65 ++++++++++ .../Plugins/Spine/SkeletonAnimation.cs.meta | 8 ++ .../Assets/Plugins/Spine/SkeletonComponent.cs | 52 +++----- .../examples/Unity 3.5/goblins/goblins.unity | Bin 16312 -> 16376 bytes .../spineboy/Spineboy.cs} | 21 ++-- .../Unity 3.5/spineboy/spineboy.unity | Bin 19260 -> 19460 bytes .../examples/Unity 4/goblins/goblins.unity | Bin 16024 -> 16072 bytes .../examples/Unity 4/spineboy/Spineboy.cs | 40 ++++++ .../Unity 4/spineboy/Spineboy.cs.meta | 8 ++ .../examples/Unity 4/spineboy/spineboy.unity | Bin 18096 -> 18144 bytes 14 files changed, 296 insertions(+), 92 deletions(-) create mode 100644 spine-unity/Assets/Plugins/Editor/Spine/SkeletonAnimationInspector.cs rename spine-unity/Assets/{examples/Unity 4/spineboy/SpineboyComponent.cs.meta => Plugins/Editor/Spine/SkeletonAnimationInspector.cs.meta} (78%) create mode 100644 spine-unity/Assets/Plugins/Spine/SkeletonAnimation.cs create mode 100644 spine-unity/Assets/Plugins/Spine/SkeletonAnimation.cs.meta rename spine-unity/Assets/examples/{Unity 4/spineboy/SpineboyComponent.cs => Unity 3.5/spineboy/Spineboy.cs} (76%) create mode 100644 spine-unity/Assets/examples/Unity 4/spineboy/Spineboy.cs create mode 100644 spine-unity/Assets/examples/Unity 4/spineboy/Spineboy.cs.meta diff --git a/spine-unity/Assets/Plugins/Editor/Spine/Menus.cs b/spine-unity/Assets/Plugins/Editor/Spine/Menus.cs index f776292c5..2ef28abbc 100644 --- a/spine-unity/Assets/Plugins/Editor/Spine/Menus.cs +++ b/spine-unity/Assets/Plugins/Editor/Spine/Menus.cs @@ -32,12 +32,12 @@ using Spine; public class SpineEditor { [MenuItem("Assets/Create/Spine Atlas")] static public void CreateAtlas () { - CreateAsset("New Spine Atlas"); + CreateAsset("New Atlas"); } - [MenuItem("Assets/Create/Spine Skeleton Data")] + [MenuItem("Assets/Create/Spine SkeletonData")] static public void CreateSkeletonData () { - CreateAsset("New Spine Skeleton Data"); + CreateAsset("New SkeletonData"); } static private void CreateAsset (String path) where T : ScriptableObject { @@ -53,20 +53,39 @@ public class SpineEditor { Selection.activeObject = asset; } - [MenuItem("GameObject/Create Other/Spine Skeleton")] - static public void CreateSkeletonGameObject () { - GameObject gameObject = new GameObject("New Spine Skeleton", typeof(SkeletonComponent)); + [MenuItem("GameObject/Create Other/Spine SkeletonComponent")] + static public void CreateSkeletonComponentGameObject () { + GameObject gameObject = new GameObject("New SkeletonComponent", typeof(SkeletonComponent)); + EditorUtility.FocusProjectWindow(); + Selection.activeObject = gameObject; + } + + [MenuItem("GameObject/Create Other/Spine SkeletonAnimation")] + static public void CreateSkeletonAnimationGameObject () { + GameObject gameObject = new GameObject("New SkeletonAnimation", typeof(SkeletonAnimation)); EditorUtility.FocusProjectWindow(); Selection.activeObject = gameObject; } - [MenuItem("Component/Spine Skeleton")] + [MenuItem("Component/Spine SkeletonComponent")] static public void CreateSkeletonComponent () { Selection.activeGameObject.AddComponent(typeof(SkeletonComponent)); } - [MenuItem("Component/Spine Skeleton", true)] + [MenuItem("Component/Spine SkeletonAnimation")] + static public void CreateSkeletonAnimation () { + Selection.activeGameObject.AddComponent(typeof(SkeletonAnimation)); + } + + [MenuItem("Component/Spine SkeletonComponent", true)] static public bool ValidateCreateSkeletonComponent () { - return Selection.activeGameObject != null && Selection.activeGameObject.GetComponent(typeof(SkeletonComponent)) == null; + return Selection.activeGameObject != null + && Selection.activeGameObject.GetComponent(typeof(SkeletonComponent)) == null + && Selection.activeGameObject.GetComponent(typeof(SkeletonAnimation)) == null; + } + + [MenuItem("Component/Spine SkeletonAnimation", true)] + static public bool ValidateCreateSkeletonAnimation () { + return ValidateCreateSkeletonComponent(); } } diff --git a/spine-unity/Assets/Plugins/Editor/Spine/SkeletonAnimationInspector.cs b/spine-unity/Assets/Plugins/Editor/Spine/SkeletonAnimationInspector.cs new file mode 100644 index 000000000..362ebbf68 --- /dev/null +++ b/spine-unity/Assets/Plugins/Editor/Spine/SkeletonAnimationInspector.cs @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2013, Esoteric Software + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +using System; +using UnityEditor; +using UnityEngine; + +[CustomEditor(typeof(SkeletonAnimation))] +public class SkeletonAnimationInspector : Editor { + private SerializedProperty skeletonDataAsset, animationName, loop, useAnimationName, initialSkinName, timeScale; + + void OnEnable () { + skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); + animationName = serializedObject.FindProperty("animationName"); + loop = serializedObject.FindProperty("loop"); + useAnimationName = serializedObject.FindProperty("useAnimationName"); + initialSkinName = serializedObject.FindProperty("initialSkinName"); + timeScale = serializedObject.FindProperty("timeScale"); + } + + override public void OnInspectorGUI () { + serializedObject.Update(); + SkeletonComponent component = (SkeletonComponent)target; + + EditorGUIUtility.LookLikeInspector(); + EditorGUILayout.PropertyField(skeletonDataAsset); + + if (component.skeleton != null) { + // Initial skin name. + String[] skins = new String[component.skeleton.Data.Skins.Count + 1]; + int skinIndex = 0; + for (int i = 0; i < skins.Length - 1; i++) { + String name = component.skeleton.Data.Skins[i].Name; + skins[i] = name; + if (name == initialSkinName.stringValue) skinIndex = i; + } + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField("Initial Skin"); + EditorGUIUtility.LookLikeControls(); + skinIndex = EditorGUILayout.Popup(skinIndex, skins); + EditorGUIUtility.LookLikeInspector(); + EditorGUILayout.EndHorizontal(); + + initialSkinName.stringValue = skinIndex == 0 ? null : skins[skinIndex]; + + // Animation name. + String[] animations = new String[component.skeleton.Data.Animations.Count + 2]; + animations[0] = ""; + animations[1] = ""; + int animationIndex = useAnimationName.boolValue ? 1 : 0; + for (int i = 0; i < animations.Length - 2; i++) { + String name = component.skeleton.Data.Animations[i].Name; + animations[i + 2] = name; + if (name == animationName.stringValue) animationIndex = i + 2; + } + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField("Animation"); + EditorGUIUtility.LookLikeControls(); + animationIndex = EditorGUILayout.Popup(animationIndex, animations); + EditorGUIUtility.LookLikeInspector(); + EditorGUILayout.EndHorizontal(); + + if (animationIndex == 0) { + animationName.stringValue = null; + useAnimationName.boolValue = false; + } else if (animationIndex == 1) { + animationName.stringValue = null; + useAnimationName.boolValue = true; + } else { + animationName.stringValue = animations[animationIndex]; + useAnimationName.boolValue = true; + } + } + + // Animation loop. + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField("Loop"); + loop.boolValue = EditorGUILayout.Toggle(loop.boolValue); + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.PropertyField(timeScale); + + if (serializedObject.ApplyModifiedProperties() || + (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") + ) { + if (!Application.isPlaying) { + component.Clear(); + component.Update(); + } + } + } +} diff --git a/spine-unity/Assets/examples/Unity 4/spineboy/SpineboyComponent.cs.meta b/spine-unity/Assets/Plugins/Editor/Spine/SkeletonAnimationInspector.cs.meta similarity index 78% rename from spine-unity/Assets/examples/Unity 4/spineboy/SpineboyComponent.cs.meta rename to spine-unity/Assets/Plugins/Editor/Spine/SkeletonAnimationInspector.cs.meta index cac343146..012f0375f 100644 --- a/spine-unity/Assets/examples/Unity 4/spineboy/SpineboyComponent.cs.meta +++ b/spine-unity/Assets/Plugins/Editor/Spine/SkeletonAnimationInspector.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5fe5e7b61b19ccf46b700c982173cb7e +guid: 39fbfef61034ca045b5aa80088e1e8a4 MonoImporter: serializedVersion: 2 defaultReferences: [] diff --git a/spine-unity/Assets/Plugins/Editor/Spine/SkeletonComponentInspector.cs b/spine-unity/Assets/Plugins/Editor/Spine/SkeletonComponentInspector.cs index ab089d0a6..e8746090d 100644 --- a/spine-unity/Assets/Plugins/Editor/Spine/SkeletonComponentInspector.cs +++ b/spine-unity/Assets/Plugins/Editor/Spine/SkeletonComponentInspector.cs @@ -29,13 +29,11 @@ using UnityEngine; [CustomEditor(typeof(SkeletonComponent))] public class SkeletonComponentInspector : Editor { - private SerializedProperty skeletonDataAsset, animationName, skinName, loop, timeScale; + private SerializedProperty skeletonDataAsset, initialSkinName, timeScale; void OnEnable () { skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); - skinName = serializedObject.FindProperty("skinName"); - animationName = serializedObject.FindProperty("animationName"); - loop = serializedObject.FindProperty("loop"); + initialSkinName = serializedObject.FindProperty("initialSkinName"); timeScale = serializedObject.FindProperty("timeScale"); } @@ -47,50 +45,25 @@ public class SkeletonComponentInspector : Editor { EditorGUILayout.PropertyField(skeletonDataAsset); if (component.skeleton != null) { - // Skin name. + // Initial skin name. String[] skins = new String[component.skeleton.Data.Skins.Count + 1]; int skinIndex = 0; for (int i = 0; i < skins.Length - 1; i++) { String name = component.skeleton.Data.Skins[i].Name; skins[i] = name; - if (name == skinName.stringValue) skinIndex = i; + if (name == initialSkinName.stringValue) skinIndex = i; } EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField("Skin"); + EditorGUILayout.LabelField("Initial Skin"); EditorGUIUtility.LookLikeControls(); skinIndex = EditorGUILayout.Popup(skinIndex, skins); EditorGUIUtility.LookLikeInspector(); EditorGUILayout.EndHorizontal(); - skinName.stringValue = skinIndex == 0 ? null : skins[skinIndex]; - - // Animation name. - String[] animations = new String[component.skeleton.Data.Animations.Count + 1]; - animations[0] = ""; - int animationIndex = 0; - for (int i = 0; i < animations.Length - 1; i++) { - String name = component.skeleton.Data.Animations[i].Name; - animations[i + 1] = name; - if (name == animationName.stringValue) animationIndex = i + 1; - } - - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField("Animation"); - EditorGUIUtility.LookLikeControls(); - animationIndex = EditorGUILayout.Popup(animationIndex, animations); - EditorGUIUtility.LookLikeInspector(); - EditorGUILayout.EndHorizontal(); - - animationName.stringValue = animationIndex == 0 ? null : animations[animationIndex]; + initialSkinName.stringValue = skinIndex == 0 ? null : skins[skinIndex]; } - // Animation loop. - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField("Loop"); - loop.boolValue = EditorGUILayout.Toggle(loop.boolValue); - EditorGUILayout.EndHorizontal(); - EditorGUILayout.PropertyField(timeScale); if (serializedObject.ApplyModifiedProperties() || diff --git a/spine-unity/Assets/Plugins/Spine/SkeletonAnimation.cs b/spine-unity/Assets/Plugins/Spine/SkeletonAnimation.cs new file mode 100644 index 000000000..eebc7c1d9 --- /dev/null +++ b/spine-unity/Assets/Plugins/Spine/SkeletonAnimation.cs @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013, Esoteric Software + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ +using System; +using System.IO; +using System.Collections.Generic; +using UnityEngine; +using Spine; + +/** Extends SkeletonComponent to apply an animation. */ +[ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] +public class SkeletonAnimation : SkeletonComponent { + public bool useAnimationName; + public String animationName; + public bool loop; + public Spine.AnimationState state; + + override public void Initialize () { + base.Initialize(); // Call overridden method to initialize the skeleton. + + state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData()); + } + + override public void UpdateSkeleton () { + if (useAnimationName) { + // Keep AnimationState in sync with animationName and loop fields. + if (animationName == null || animationName.Length == 0) { + if (state.Animation != null) state.ClearAnimation(); + } else if (state.Animation == null || animationName != state.Animation.Name) { + Spine.Animation animation = skeleton.Data.FindAnimation(animationName); + if (animation != null) + state.SetAnimation(animation, loop); + } + state.Loop = loop; + } + + // Apply the animation. + state.Update(Time.deltaTime * timeScale); + state.Apply(skeleton); + + // Call overridden method to call skeleton Update and UpdateWorldTransform. + base.UpdateSkeleton(); + } +} diff --git a/spine-unity/Assets/Plugins/Spine/SkeletonAnimation.cs.meta b/spine-unity/Assets/Plugins/Spine/SkeletonAnimation.cs.meta new file mode 100644 index 000000000..f497aa7e8 --- /dev/null +++ b/spine-unity/Assets/Plugins/Spine/SkeletonAnimation.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d247ba06193faa74d9335f5481b2b56c +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs b/spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs index 5da904689..244a7c104 100644 --- a/spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs +++ b/spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs @@ -28,15 +28,13 @@ using System.Collections.Generic; using UnityEngine; using Spine; +/** Renders a skeleton. Extend to apply animations, get bones and manipulate them, etc. */ [ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] public class SkeletonComponent : MonoBehaviour { public SkeletonDataAsset skeletonDataAsset; public Skeleton skeleton; - public String skinName; - public String animationName; - public bool loop; + public String initialSkinName; public float timeScale = 1; - public Spine.AnimationState state; private Mesh mesh; private Vector3[] vertices; private Color[] colors; @@ -45,7 +43,7 @@ public class SkeletonComponent : MonoBehaviour { private int quadCount; private float[] vertexPositions = new float[8]; - public void Clear () { + public virtual void Clear () { GetComponent().mesh = null; DestroyImmediate(mesh); mesh = null; @@ -53,25 +51,26 @@ public class SkeletonComponent : MonoBehaviour { skeleton = null; } - public void Initialize () { + public virtual void Initialize () { mesh = new Mesh(); GetComponent().mesh = mesh; mesh.name = "Skeleton Mesh"; mesh.hideFlags = HideFlags.HideAndDontSave; - state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData()); - skeleton = new Skeleton(skeletonDataAsset.GetSkeletonData(false)); + + if (initialSkinName != null && initialSkinName.Length > 0) { + skeleton.SetSkin(initialSkinName); + skeleton.SetSlotsToSetupPose(); + } } - public void UpdateAnimation () { + public virtual void UpdateSkeleton () { skeleton.Update(Time.deltaTime * timeScale); - state.Update(Time.deltaTime * timeScale); - state.Apply(skeleton); skeleton.UpdateWorldTransform(); } - public void Update () { + public virtual void Update () { // Clear fields if missing information to render. if (skeletonDataAsset == null || skeletonDataAsset.GetSkeletonData(false) == null) { Clear(); @@ -82,28 +81,7 @@ public class SkeletonComponent : MonoBehaviour { if (skeleton == null || skeleton.Data != skeletonDataAsset.GetSkeletonData(false)) Initialize(); - // Keep AnimationState in sync with animationName and loop fields. - if (animationName == null || animationName.Length == 0) { - if (state.Animation != null) state.ClearAnimation(); - } else if (state.Animation == null || animationName != state.Animation.Name) { - Spine.Animation animation = skeleton.Data.FindAnimation(animationName); - if (animation != null) - state.SetAnimation(animation, loop); - } - state.Loop = loop; - - // Keep Skeleton in sync with skinName. - if (skinName == null || skinName.Length == 0) { - if (skeleton.Skin != null) { - skeleton.SetSkin((Skin)null); - skeleton.SetSlotsToSetupPose(); - } - } else if (skeleton.Skin == null || skinName != skeleton.Skin.Name) { - skeleton.SetSkin(skinName); - skeleton.SetSlotsToSetupPose(); - } - - UpdateAnimation(); + UpdateSkeleton(); // Count quads. int quadCount = 0; @@ -176,16 +154,16 @@ public class SkeletonComponent : MonoBehaviour { renderer.sharedMaterial = skeletonDataAsset.atlasAsset.material; } - void OnEnable () { + public virtual void OnEnable () { Update(); } - void OnDisable () { + public virtual void OnDisable () { if (Application.isEditor) Clear(); } - void Reset () { + public virtual void Reset () { Update(); } } diff --git a/spine-unity/Assets/examples/Unity 3.5/goblins/goblins.unity b/spine-unity/Assets/examples/Unity 3.5/goblins/goblins.unity index fbcf75b3250176dbb5c96ad72a3116a357c0d310..76ca8138ff53216e1ec4b874d40d6daa22da9151 100644 GIT binary patch delta 312 zcmdl{|D#@jfx+6Bfx-R<0|NsmkXqD!US@7$NoIbYUt(@5 z10zs@3=o3=h|SlRpAU`N?%Gii`@A%~_TB6hTUW0HSnrKkE*Y zAh>~g$;Ax1C94xAeqQB1*Z8Zegm&~XkiwkIq@u*4O8w--7N%6{?mJMiBdVW$) dW**1|4fY_TLH;XG%*ke)ywF;Fvy9ywMgVzKRviEU delta 259 zcmexSzoTA&fx%jwfx&(U0|NsmkZmwgz@CwJv!U2!#>uDEG&XxP-DPAfo@~IEtOO?jYp5MTrmo*;sOAuT6Av4o){GdDFjIWZ@d zfdwe0FxgN;c=Ku2O(sFk`MCx8d8v6NddbBMT(N$6r|j>0%-Cc4U(Sus8)QySW>QgN zQKf!zVsb{Rexd;orI@Cgq?#orrx~ZESeRH?CMTI1r=_JDnwg{;B$-TBw6>qjXPq#~ rhHrD5^&%!oE}$vt`AIpMdFh!&ISgPIlqcq7GfqBeE4?|!ZVn>=fcQpB diff --git a/spine-unity/Assets/examples/Unity 4/spineboy/SpineboyComponent.cs b/spine-unity/Assets/examples/Unity 3.5/spineboy/Spineboy.cs similarity index 76% rename from spine-unity/Assets/examples/Unity 4/spineboy/SpineboyComponent.cs rename to spine-unity/Assets/examples/Unity 3.5/spineboy/Spineboy.cs index 74680081e..2cbc5a3bd 100644 --- a/spine-unity/Assets/examples/Unity 4/spineboy/SpineboyComponent.cs +++ b/spine-unity/Assets/examples/Unity 3.5/spineboy/Spineboy.cs @@ -26,18 +26,15 @@ using UnityEngine; using System.Collections; -public class SpineboyComponent : MonoBehaviour { - public void OnMouseDown () { - SkeletonComponent skeletonComponent = GetComponent(); - skeletonComponent.animationName = "jump"; - skeletonComponent.loop = false; +public class Spineboy : MonoBehaviour { + public void Start () { + SkeletonAnimation skeletonAnimation = GetComponent(); + skeletonAnimation.state.SetAnimation("walk", true); } - - public void Update () { - SkeletonComponent skeletonComponent = GetComponent(); - if (!skeletonComponent.loop && skeletonComponent.state.Time >= skeletonComponent.state.Animation.Duration - 0.25) { - skeletonComponent.animationName = "walk"; - skeletonComponent.loop = true; - } + + public void OnMouseDown () { + SkeletonAnimation skeletonAnimation = GetComponent(); + skeletonAnimation.state.SetAnimation("jump", false); + skeletonAnimation.state.AddAnimation("walk", true); } } diff --git a/spine-unity/Assets/examples/Unity 3.5/spineboy/spineboy.unity b/spine-unity/Assets/examples/Unity 3.5/spineboy/spineboy.unity index 98393305ab1df0a283edefdb39a38d0dc0c80294..552a1be83ac66e7729e56547e8345dcf7f4a3aa8 100644 GIT binary patch delta 445 zcmdlpjj?40qW}Yg+Y$x_9~K4%22LRRz(#?U%#3^+1MHY5PcUJf{FiMiS7u&jNoHbB zaCYY8S?nE?*Bi4<_U7QTl?G}70Y(tP0U{U}LOt_JEEr0QQyud%a}!H4^Yi=?b5p@e zWFRUa$~`Byvdc5dPF~8c%qTbcB#@M!{FYsjQDHJahZ3J6iqg&L9RAjpK0vYmKu`pv z|Jr4VEdaXM0LcCa75fJiy8sk(0E#(6@qeJ0z~uMNOM>9e(Mv97&@EY=F!A#$_qoPj zT_v=mkAXaplbKYMSX8N>oS2-Es-I#6L?-4*i3Vndmd0s`iRLCLmd3`WX{II?hDkf|~%h0S7ae9V&#JY_gReg%O)n>{`487C`vDNJr~ K6PUcgs|NrqbbK%X delta 378 zcmZpf!MJA{qW}Yg>r(~>ZyN>%22KVBH-?P@E14O2HYf63W}KWasY4c(W;|r?sUA zQ1Cwx6aneKc3EOGSQr=#fb4%zv423Z6F@NspqL{R{|Ab3Oy2IYB*-~Gw;(?+HLpZ3 zxtM_~)-Ugr{e6!adrbe!x$${}EX>JFDoQM>)K5-K&PdfyGytL$(^QjGv&7^yIl$-n!NXk#HV^L&Om~76f#HR>S0t67HoBLT`8#6{suD0|M&@EY= zF!A#$_qoPjT_v=mk4?UAX+1f|mT$9~RUfk;14Dy7NDs(8<%v1jjFTI!q$fYH-2niL Ck~$6m delta 191 zcmX?6JEK;Bfx+@C1B2ZR1_lOB1_mpEi30YFyqgULelu?NX1dGBSUlN)rE9Vvt0bfJ zWLp+xMw!WpKvH&cD~lqd+~ldON@nsvtsuY%B0NC^14CL)eqsqjNoHn~$=-Hf9W&ywTD}fGgH7@09(0j~RPR|I4}Yc~9oGvYx!(if!@*E56NP ZR(;GoApPZuIoTk+lNVSiOct=)0RS@mE&l)j diff --git a/spine-unity/Assets/examples/Unity 4/spineboy/Spineboy.cs b/spine-unity/Assets/examples/Unity 4/spineboy/Spineboy.cs new file mode 100644 index 000000000..2cbc5a3bd --- /dev/null +++ b/spine-unity/Assets/examples/Unity 4/spineboy/Spineboy.cs @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2013, Esoteric Software + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************/ + +using UnityEngine; +using System.Collections; + +public class Spineboy : MonoBehaviour { + public void Start () { + SkeletonAnimation skeletonAnimation = GetComponent(); + skeletonAnimation.state.SetAnimation("walk", true); + } + + public void OnMouseDown () { + SkeletonAnimation skeletonAnimation = GetComponent(); + skeletonAnimation.state.SetAnimation("jump", false); + skeletonAnimation.state.AddAnimation("walk", true); + } +} diff --git a/spine-unity/Assets/examples/Unity 4/spineboy/Spineboy.cs.meta b/spine-unity/Assets/examples/Unity 4/spineboy/Spineboy.cs.meta new file mode 100644 index 000000000..3e2eb3457 --- /dev/null +++ b/spine-unity/Assets/examples/Unity 4/spineboy/Spineboy.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f73aeaeed67fd5446ae964e07ef7e7e7 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/spine-unity/Assets/examples/Unity 4/spineboy/spineboy.unity b/spine-unity/Assets/examples/Unity 4/spineboy/spineboy.unity index c1df2cbe6c5369a884f7cac4e00f6380b8159b42..62e9f0c8587190f34e3c0690bc30256cfa27af2c 100644 GIT binary patch delta 265 zcmdnc%lM#|QGkKLaTf!F+XDs$22LRR!bX9W%#3^+1MHY5|6rTNk(rlSl9`wjJb5yE z*W~LQBDT^%g&@EPA~-+<14F21UWo-mX>qD!US@7$NoIbYUt(@5Scwco1w^^$WN{98 zM%l>=*p(UOCP#B9Gs;h1$RRxWH#;Ar0+6M|r--6_^G^?nuX3Mj{MA)L zJNnq<07oOi`o-(s<$jNKSvJp&?|FS)9rI*GC)v&09K#qz9ie7y`~1qQ2+H0xS<$(h cg@K{LesY4d?&Q19{Vcn3uQ+WkaB*M)0K;QQ7XSbN delta 246 zcmaFR%ebMJQGkKLv4w%bZ36=X11FHZV57iFW=7tP0d~xj4R~26|7DxXSUh