From dc5873876b75d5dc950271bd4e662ece132a8b68 Mon Sep 17 00:00:00 2001 From: Fenrisul Date: Mon, 26 Jan 2015 22:02:55 -0800 Subject: [PATCH 1/2] Modified SkeletonRenderer to destroy mesh1 and mesh2 when disabled if the gameobject its attached to is no longer visible. --- .../Examples/Scripts/FootSoldierExample.cs | 24 +++++++++++++++---- .../Assets/spine-unity/AtlasRegionAttacher.cs | 16 ++++++------- .../Assets/spine-unity/SkeletonRenderer.cs | 16 ++++++++++--- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/spine-unity/Assets/Examples/Scripts/FootSoldierExample.cs b/spine-unity/Assets/Examples/Scripts/FootSoldierExample.cs index 655445869..3a7152ef5 100644 --- a/spine-unity/Assets/Examples/Scripts/FootSoldierExample.cs +++ b/spine-unity/Assets/Examples/Scripts/FootSoldierExample.cs @@ -42,6 +42,9 @@ public class FootSoldierExample : MonoBehaviour { [SpineAnimation] public string attackAnimation; + [SpineAnimation] + public string moveAnimation; + [SpineSlot] public string eyesSlot; @@ -54,22 +57,33 @@ public class FootSoldierExample : MonoBehaviour { [Range(0, 0.2f)] public float blinkDuration = 0.05f; + public float moveSpeed = 3; + private SkeletonAnimation skeletonAnimation; void Awake() { skeletonAnimation = GetComponent(); + skeletonAnimation.OnReset += Apply; } - void Start() { - skeletonAnimation.state.SetAnimation(0, idleAnimation, true); + void Apply(SkeletonRenderer skeletonRenderer) { StartCoroutine("Blink"); } void Update() { if (Input.GetKey(KeyCode.Space)) { - if (skeletonAnimation.state.GetCurrent(0).Animation.Name != attackAnimation) { - skeletonAnimation.state.SetAnimation(0, attackAnimation, false); - skeletonAnimation.state.AddAnimation(0, idleAnimation, true, 0); + skeletonAnimation.AnimationName = attackAnimation; + } else { + if (Input.GetKey(KeyCode.RightArrow)) { + skeletonAnimation.AnimationName = moveAnimation; + skeletonAnimation.skeleton.FlipX = false; + transform.Translate(moveSpeed * Time.deltaTime, 0, 0); + } else if(Input.GetKey(KeyCode.LeftArrow)) { + skeletonAnimation.AnimationName = moveAnimation; + skeletonAnimation.skeleton.FlipX = true; + transform.Translate(-moveSpeed * Time.deltaTime, 0, 0); + } else { + skeletonAnimation.AnimationName = idleAnimation; } } } diff --git a/spine-unity/Assets/spine-unity/AtlasRegionAttacher.cs b/spine-unity/Assets/spine-unity/AtlasRegionAttacher.cs index 193ab754d..d3824f521 100644 --- a/spine-unity/Assets/spine-unity/AtlasRegionAttacher.cs +++ b/spine-unity/Assets/spine-unity/AtlasRegionAttacher.cs @@ -17,16 +17,16 @@ public class AtlasRegionAttacher : MonoBehaviour { public AtlasAsset atlasAsset; public SlotRegionPair[] attachments; - [HideInInspector] - public SkeletonRenderer skeletonRenderer; - - Atlas atlas; - void Start() { - atlas = atlasAsset.GetAtlas(); - this.skeletonRenderer = GetComponent(); + void Awake() { + GetComponent().OnReset += Apply; + } + + void Apply(SkeletonRenderer skeletonRenderer) { + atlas = atlasAsset.GetAtlas(); + AtlasAttachmentLoader loader = new AtlasAttachmentLoader(atlas); float scaleMultiplier = skeletonRenderer.skeletonDataAsset.scale; @@ -41,7 +41,7 @@ public class AtlasRegionAttacher : MonoBehaviour { regionAttachment.SetColor(new Color(1, 1, 1, 1)); regionAttachment.UpdateOffset(); - var slot = this.skeletonRenderer.skeleton.FindSlot(entry.slot); + var slot = skeletonRenderer.skeleton.FindSlot(entry.slot); slot.Attachment = regionAttachment; } } diff --git a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs index 07cabff32..ad4d0137a 100644 --- a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs +++ b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs @@ -117,9 +117,19 @@ public class SkeletonRenderer : MonoBehaviour { if (OnReset != null) OnReset(this); } - - public void Awake () { - Reset(); + + public virtual void OnEnable() { + if(mesh1 == null || mesh2 == null) + Reset(); + } + + public virtual void OnDisable() { + if (Application.isPlaying && gameObject.activeInHierarchy == false) { + if (mesh1 != null) + Destroy(mesh1); + if (mesh2 != null) + Destroy(mesh2); + } } private Mesh newMesh () { From 86a5b5289dfb49f9b831d35e038696a28870d0a7 Mon Sep 17 00:00:00 2001 From: Fenrisul Date: Mon, 26 Jan 2015 22:05:39 -0800 Subject: [PATCH 2/2] updated footsoldier example --- .../Scenes/Attributes and AtlasRegions.unity | Bin 23236 -> 21052 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/spine-unity/Assets/Examples/Scenes/Attributes and AtlasRegions.unity b/spine-unity/Assets/Examples/Scenes/Attributes and AtlasRegions.unity index cc0f39f32e3b0e7df6ea0d5cfaa6a71699067dfc..4842a5799ddb70c01bd60d3f27ffe723f6b2cac8 100644 GIT binary patch delta 551 zcmXw$KS*0~5XbLK@@iBxnt9ZPb9lHpI5=bzU0oa<~i_uYLzzx&-g?wz0T=>gXh4R#QXb`g;i zc?^*{La#&N*)Tm63I&%rq1{!Qv0$F%L-QMR!*#)OR{g?k@V2mfG4m}IT}m%bFQ+q0 zgz|!atGrQu=`#}3opPtI$hBT8f9rn8p1oAQ*15SA1ss&9$Il_TEOX1cw~}8yWg&+q zPG1eTNyg!=QoZBZRO%zyF;m#|`A*uoMy`hEa&v+4rngMAiUWiv&4cA({O}`|(qOk1 z`w6DB09IO3teb>a`UKVtrp`TBjlrt{l)60c2gpV_+Jt%ja5vz#jc6H6ZQu)H z510!#){v_$D%K134=juP-eM6|=OCH_tF;sb%Yp^q>n-(xZG#nu!H-hYXhiaV`MrVnFhVNoHv>UfPGSM(H;iN+J>AxKDl?6%sI9Y?EChSFQTod_Ts! T_&6k(Y{$*%WG6c9CJ!G0>s^03 delta 1364 zcmaKsUuaWT9LLXXqm8cqX-#UxVsB^r(n(bmsZwpzCU&v0H@QhSCJuX>oHm*1z4hi6 z3=_JE%ElbXeryQ7i1?svP9!QKf`1?OBtFR8(R+!2B((^L8kWbf9Nj z@#f|$O0lQrFJ)EIHq88(Wl!u7`AI3$x*U_XG*gm#>r?b#Nu6iZG9}&c99cP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