From 2902fb2ec9ea4888c0dc2671835fae74b0829e41 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sun, 5 Oct 2014 20:29:11 +0200 Subject: [PATCH] Formatted source, committed formatter policy. --- .../Scripts/BasicPlatformerController.cs | 240 +++--- .../Examples/Scripts/ConstrainedCamera.cs | 2 - .../Examples/Scripts/SpineboyController.cs | 58 +- .../Examples/Spine/Dragon/dragon.png.meta | 3 +- .../Examples/Spine/Dragon/dragon2.png.meta | 3 +- .../Examples/Spine/Dragon/dragon_dragon.mat | Bin 727 -> 4216 bytes .../Examples/Spine/Dragon/dragon_dragon2.mat | Bin 728 -> 4216 bytes .../Assets/Examples/Spine/Eyes/eyes.png.meta | 2 +- .../Examples/Spine/Eyes/eyes_Material.mat | Bin 4216 -> 4216 bytes .../Spine/Goblins/goblins-mesh.png.meta | 2 + .../Spine/Goblins/goblins-mesh_Material.mat | Bin 4224 -> 4224 bytes .../Examples/Spine/Hero/Hero_Material.mat | Bin 4216 -> 4216 bytes .../Examples/Spine/Raptor/raptor.png.meta | 4 +- .../Examples/Spine/Raptor/raptor_Material.mat | Bin 4216 -> 4216 bytes .../Examples/Spine/Spineboy/spineboy.png.meta | 3 +- .../Spine/Spineboy/spineboy_Material.mat | Bin 731 -> 4220 bytes .../Assets/spine-unity/BoneFollower.cs | 40 +- .../spine-unity/Editor/AtlasAssetInspector.cs | 1 - .../Editor/BoneFollowerInspector.cs | 26 +- .../Assets/spine-unity/Editor/Menus.cs | 4 +- .../Editor/SkeletonAnimationInspector.cs | 20 +- .../Editor/SkeletonDataAssetInspector.cs | 723 +++++++++--------- .../Editor/SkeletonRendererInspector.cs | 7 +- .../Editor/SpineEditorUtilities.cs | 291 ++++--- .../Assets/spine-unity/SkeletonAnimation.cs | 21 +- .../Assets/spine-unity/SkeletonDataAsset.cs | 3 +- .../Assets/spine-unity/SkeletonExtensions.cs | 20 +- .../Assets/spine-unity/SkeletonRenderer.cs | 111 +-- .../Editor/SkeletonUtilityBoneInspector.cs | 171 ++--- .../Editor/SkeletonUtilityInspector.cs | 135 ++-- .../SkeletonUtility/SkeletonUtility.cs | 132 ++-- .../SkeletonUtility/SkeletonUtilityBone.cs | 268 +++---- .../SkeletonUtilityConstraint.cs | 6 +- .../SkeletonUtilityEyeConstraint.cs | 31 +- .../SkeletonUtilityGroundConstraint.cs | 73 +- .../SkeletonUtilityKinematicShadow.cs | 36 +- .../SkeletonUtilitySubmeshRenderer.cs | 44 +- spine-unity/Spine.mdpolicy | 28 + 38 files changed, 1207 insertions(+), 1301 deletions(-) create mode 100644 spine-unity/Spine.mdpolicy diff --git a/spine-unity/Assets/Examples/Scripts/BasicPlatformerController.cs b/spine-unity/Assets/Examples/Scripts/BasicPlatformerController.cs index 0ffc2ffa2..1eb015e1e 100644 --- a/spine-unity/Assets/Examples/Scripts/BasicPlatformerController.cs +++ b/spine-unity/Assets/Examples/Scripts/BasicPlatformerController.cs @@ -39,196 +39,168 @@ using System.Collections; [RequireComponent(typeof(CharacterController))] public class BasicPlatformerController : MonoBehaviour { -#if !UNITY_4_3 && !UNITY_4_4 +#if UNITY_4_5 [Header("Controls")] #endif - public string XAxis = "Horizontal"; - public string YAxis = "Vertical"; - public string JumpButton = "Jump"; + public string XAxis = "Horizontal"; + public string YAxis = "Vertical"; + public string JumpButton = "Jump"; -#if !UNITY_4_3 && !UNITY_4_4 +#if UNITY_4_5 [Header("Moving")] #endif public float walkSpeed = 4; - public float runSpeed = 10; - public float gravity = 65; + public float runSpeed = 10; + public float gravity = 65; -#if !UNITY_4_3 && !UNITY_4_4 +#if UNITY_4_5 [Header("Jumping")] #endif public float jumpSpeed = 25; - public float jumpDuration = 0.5f; - public float jumpInterruptFactor = 100; - public float forceCrouchVelocity = 25; - public float forceCrouchDuration = 0.5f; + public float jumpDuration = 0.5f; + public float jumpInterruptFactor = 100; + public float forceCrouchVelocity = 25; + public float forceCrouchDuration = 0.5f; -#if !UNITY_4_3 && !UNITY_4_4 +#if UNITY_4_5 [Header("Graphics")] #endif public Transform graphicsRoot; - public SkeletonAnimation skeletonAnimation; + public SkeletonAnimation skeletonAnimation; -#if !UNITY_4_3 && !UNITY_4_4 +#if UNITY_4_5 [Header("Animation")] #endif public string walkName = "Walk"; - public string runName = "Run"; - public string idleName = "Idle"; - public string jumpName = "Jump"; - public string fallName = "Fall"; - public string crouchName = "Crouch"; + public string runName = "Run"; + public string idleName = "Idle"; + public string jumpName = "Jump"; + public string fallName = "Fall"; + public string crouchName = "Crouch"; -#if !UNITY_4_3 && !UNITY_4_4 +#if UNITY_4_5 [Header("Audio")] #endif public AudioSource jumpAudioSource; public AudioSource hardfallAudioSource; public AudioSource footstepAudioSource; public string footstepEventName = "Footstep"; + CharacterController controller; + Vector2 velocity = Vector2.zero; + Vector2 lastVelocity = Vector2.zero; + bool lastGrounded = false; + float jumpEndTime = 0; + bool jumpInterrupt = false; + float forceCrouchEndTime; + Quaternion flippedRotation = Quaternion.Euler(0, 180, 0); - - - CharacterController controller; - Vector2 velocity = Vector2.zero; - Vector2 lastVelocity = Vector2.zero; - bool lastGrounded = false; - float jumpEndTime = 0; - bool jumpInterrupt = false; - float forceCrouchEndTime; - - - Quaternion flippedRotation = Quaternion.Euler(0, 180, 0); - - void Awake() - { - controller = GetComponent(); + void Awake () { + controller = GetComponent(); } - void Start(){ + void Start () { //register a callback for Spine Events (in this case, Footstep) skeletonAnimation.state.Event += HandleEvent; } - void HandleEvent (Spine.AnimationState state, int trackIndex, Spine.Event e) - { + void HandleEvent (Spine.AnimationState state, int trackIndex, Spine.Event e) { //play some sound if footstep event fired - if(e.Data.Name == footstepEventName){ + if (e.Data.Name == footstepEventName) { footstepAudioSource.Stop(); footstepAudioSource.Play(); } - } + } - void Update() - { - //control inputs - float x = Input.GetAxis(XAxis); - float y = Input.GetAxis(YAxis); - //check for force crouch - bool crouching = (controller.isGrounded && y < -0.5f) || (forceCrouchEndTime > Time.time); - velocity.x = 0; + void Update () { + //control inputs + float x = Input.GetAxis(XAxis); + float y = Input.GetAxis(YAxis); + //check for force crouch + bool crouching = (controller.isGrounded && y < -0.5f) || (forceCrouchEndTime > Time.time); + velocity.x = 0; - //Calculate control velocity - if (!crouching) { - if (Input.GetButtonDown(JumpButton) && controller.isGrounded) - { - //jump + //Calculate control velocity + if (!crouching) { + if (Input.GetButtonDown(JumpButton) && controller.isGrounded) { + //jump jumpAudioSource.Stop(); jumpAudioSource.Play(); - velocity.y = jumpSpeed; - jumpEndTime = Time.time + jumpDuration; - } - else if (Time.time < jumpEndTime && Input.GetButtonUp(JumpButton)) - { - jumpInterrupt = true; - } + velocity.y = jumpSpeed; + jumpEndTime = Time.time + jumpDuration; + } else if (Time.time < jumpEndTime && Input.GetButtonUp(JumpButton)) { + jumpInterrupt = true; + } - if (x != 0) - { - //walk or run - velocity.x = Mathf.Abs(x) > 0.6f ? runSpeed : walkSpeed; - velocity.x *= Mathf.Sign(x); - } + if (x != 0) { + //walk or run + velocity.x = Mathf.Abs(x) > 0.6f ? runSpeed : walkSpeed; + velocity.x *= Mathf.Sign(x); + } - if (jumpInterrupt) - { - //interrupt jump and smoothly cut Y velocity - if (velocity.y > 0) - { - velocity.y = Mathf.MoveTowards(velocity.y, 0, Time.deltaTime * 100); - } - else - { - jumpInterrupt = false; - } - } - } + if (jumpInterrupt) { + //interrupt jump and smoothly cut Y velocity + if (velocity.y > 0) { + velocity.y = Mathf.MoveTowards(velocity.y, 0, Time.deltaTime * 100); + } else { + jumpInterrupt = false; + } + } + } - //apply gravity F = mA (Learn it, love it, live it) - velocity.y -= gravity * Time.deltaTime; + //apply gravity F = mA (Learn it, love it, live it) + velocity.y -= gravity * Time.deltaTime; - //move - controller.Move(new Vector3(velocity.x, velocity.y, 0) * Time.deltaTime); + //move + controller.Move(new Vector3(velocity.x, velocity.y, 0) * Time.deltaTime); - if (controller.isGrounded) - { - //cancel out Y velocity if on ground - velocity.y = -gravity * Time.deltaTime; - jumpInterrupt = false; - } + if (controller.isGrounded) { + //cancel out Y velocity if on ground + velocity.y = -gravity * Time.deltaTime; + jumpInterrupt = false; + } - Vector2 deltaVelocity = lastVelocity - velocity; + Vector2 deltaVelocity = lastVelocity - velocity; - if (!lastGrounded && controller.isGrounded) - { - //detect hard fall - if ((gravity*Time.deltaTime) - deltaVelocity.y > forceCrouchVelocity) - { - forceCrouchEndTime = Time.time + forceCrouchDuration; + if (!lastGrounded && controller.isGrounded) { + //detect hard fall + if ((gravity * Time.deltaTime) - deltaVelocity.y > forceCrouchVelocity) { + forceCrouchEndTime = Time.time + forceCrouchDuration; hardfallAudioSource.Play(); - } - else{ + } else { //play footstep audio if light fall because why not footstepAudioSource.Play(); } - } + } - //graphics updates - if (controller.isGrounded) - { - if (crouching) //crouch - { - skeletonAnimation.AnimationName = crouchName; - } - else - { + //graphics updates + if (controller.isGrounded) { + if (crouching) { //crouch + skeletonAnimation.AnimationName = crouchName; + } else { + if (x == 0) //idle + skeletonAnimation.AnimationName = idleName; + else //move + skeletonAnimation.AnimationName = Mathf.Abs(x) > 0.6f ? runName : walkName; + } + } else { + if (velocity.y > 0) //jump + skeletonAnimation.AnimationName = jumpName; + else //fall + skeletonAnimation.AnimationName = fallName; + } - if (x == 0) //idle - skeletonAnimation.AnimationName = idleName; - else //move - skeletonAnimation.AnimationName = Mathf.Abs(x) > 0.6f ? runName : walkName; - } - } - else - { - if (velocity.y > 0) //jump - skeletonAnimation.AnimationName = jumpName; - else //fall - skeletonAnimation.AnimationName = fallName; - - } - - //flip left or right - if (x > 0) - graphicsRoot.localRotation = Quaternion.identity; - else if (x < 0) - graphicsRoot.localRotation = flippedRotation; + //flip left or right + if (x > 0) + graphicsRoot.localRotation = Quaternion.identity; + else if (x < 0) + graphicsRoot.localRotation = flippedRotation; - //store previous state - lastVelocity = velocity; - lastGrounded = controller.isGrounded; - } + //store previous state + lastVelocity = velocity; + lastGrounded = controller.isGrounded; + } } diff --git a/spine-unity/Assets/Examples/Scripts/ConstrainedCamera.cs b/spine-unity/Assets/Examples/Scripts/ConstrainedCamera.cs index 2dc8a1dff..c67ebdb7e 100644 --- a/spine-unity/Assets/Examples/Scripts/ConstrainedCamera.cs +++ b/spine-unity/Assets/Examples/Scripts/ConstrainedCamera.cs @@ -39,10 +39,8 @@ using System.Collections; public class ConstrainedCamera : MonoBehaviour { public Transform target; public Vector3 offset; - public Vector3 min; public Vector3 max; - public float smoothing = 5f; // Use this for initialization diff --git a/spine-unity/Assets/Examples/Scripts/SpineboyController.cs b/spine-unity/Assets/Examples/Scripts/SpineboyController.cs index be43009d9..4cebc7de3 100644 --- a/spine-unity/Assets/Examples/Scripts/SpineboyController.cs +++ b/spine-unity/Assets/Examples/Scripts/SpineboyController.cs @@ -5,19 +5,15 @@ using System.Collections; public class SpineboyController : MonoBehaviour { SkeletonAnimation skeletonAnimation; - public string idleAnimation = "idle"; public string walkAnimation = "walk"; public string runAnimation = "run"; public string hitAnimation = "hit"; public string deathAnimation = "death"; - public float walkVelocity = 1; public float runVelocity = 3; public int hp = 10; - string currentAnimation = ""; - bool hit = false; bool dead = false; @@ -25,59 +21,53 @@ public class SpineboyController : MonoBehaviour { skeletonAnimation = GetComponent(); } - - void Update(){ - if(!dead){ + void Update () { + if (!dead) { float x = Input.GetAxis("Horizontal"); float absX = Mathf.Abs(x); - if(!hit){ - if(x > 0) + if (!hit) { + if (x > 0) skeletonAnimation.skeleton.FlipX = false; - else if(x < 0) - skeletonAnimation.skeleton.FlipX = true; + else if (x < 0) + skeletonAnimation.skeleton.FlipX = true; - if(absX > 0.7f){ + if (absX > 0.7f) { SetAnimation(runAnimation, true); - rigidbody2D.velocity = new Vector2( runVelocity * Mathf.Sign(x), rigidbody2D.velocity.y); - } - else if(absX > 0){ - SetAnimation(walkAnimation, true); - rigidbody2D.velocity = new Vector2( walkVelocity * Mathf.Sign(x), rigidbody2D.velocity.y); - } - else{ - SetAnimation(idleAnimation, true); - rigidbody2D.velocity = new Vector2( 0, rigidbody2D.velocity.y); - } - } - else{ - if(skeletonAnimation.state.GetCurrent(0).Animation.Name != hitAnimation) + rigidbody2D.velocity = new Vector2(runVelocity * Mathf.Sign(x), rigidbody2D.velocity.y); + } else if (absX > 0) { + SetAnimation(walkAnimation, true); + rigidbody2D.velocity = new Vector2(walkVelocity * Mathf.Sign(x), rigidbody2D.velocity.y); + } else { + SetAnimation(idleAnimation, true); + rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y); + } + } else { + if (skeletonAnimation.state.GetCurrent(0).Animation.Name != hitAnimation) hit = false; } } } - - void SetAnimation(string anim, bool loop){ - if(currentAnimation != anim){ + void SetAnimation (string anim, bool loop) { + if (currentAnimation != anim) { skeletonAnimation.state.SetAnimation(0, anim, loop); currentAnimation = anim; } } - void OnMouseUp(){ + void OnMouseUp () { - if(hp > 0){ + if (hp > 0) { hp--; - if(hp == 0){ + if (hp == 0) { SetAnimation(deathAnimation, false); dead = true; - } - else{ + } else { skeletonAnimation.state.SetAnimation(0, hitAnimation, false); skeletonAnimation.state.AddAnimation(0, currentAnimation, true, 0); - rigidbody2D.velocity = new Vector2( 0, rigidbody2D.velocity.y); + rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y); hit = true; } diff --git a/spine-unity/Assets/Examples/Spine/Dragon/dragon.png.meta b/spine-unity/Assets/Examples/Spine/Dragon/dragon.png.meta index d5bf04f92..795bddb21 100644 --- a/spine-unity/Assets/Examples/Spine/Dragon/dragon.png.meta +++ b/spine-unity/Assets/Examples/Spine/Dragon/dragon.png.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 6bc52290ef03f2846ba38d67e2823598 TextureImporter: + fileIDToRecycleName: {} serializedVersion: 2 mipmaps: mipMapMode: 0 @@ -21,7 +22,7 @@ TextureImporter: generateCubemap: 0 seamlessCubemap: 0 textureFormat: -3 - maxTextureSize: 1024 + maxTextureSize: 2048 textureSettings: filterMode: -1 aniso: -1 diff --git a/spine-unity/Assets/Examples/Spine/Dragon/dragon2.png.meta b/spine-unity/Assets/Examples/Spine/Dragon/dragon2.png.meta index 3b2676cd9..9f683ac4f 100644 --- a/spine-unity/Assets/Examples/Spine/Dragon/dragon2.png.meta +++ b/spine-unity/Assets/Examples/Spine/Dragon/dragon2.png.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 12c126994123f12468cf4c5a2684078a TextureImporter: + fileIDToRecycleName: {} serializedVersion: 2 mipmaps: mipMapMode: 0 @@ -21,7 +22,7 @@ TextureImporter: generateCubemap: 0 seamlessCubemap: 0 textureFormat: -3 - maxTextureSize: 1024 + maxTextureSize: 2048 textureSettings: filterMode: -1 aniso: -1 diff --git a/spine-unity/Assets/Examples/Spine/Dragon/dragon_dragon.mat b/spine-unity/Assets/Examples/Spine/Dragon/dragon_dragon.mat index eafb01c27545cb07c5a26052c9094c7bf3ff1144..34533af5697e60adaea94a61d13849e843cef897 100644 GIT binary patch literal 4216 zcmeHKOLH7G5SDr7!6O6+Z&*Tr@NynFJc4ojz?-pH$&}b>33B-V>8`X%epj*40}LA9>k+k>JYt#d71TcleDtjsX_PJ z#`k8^UC9#D?(1Hu9wG=Pgy8M_9O1O6Y4fJ$exyhp45N)Lo-_=IqjmAsd%)gvWO>;`S#n9`X=HRhzuel*O-5duJD zsiJRgX{!?LH1{5r&ItsQvA(4fV?l;!Ou}OU8fuh;#{-bC8zJF|2xy1$rm$m=Uz*Vm zg-uFMye9)Z5)TtM=|CcnS4tQk-I$K22mtX>L9dx-Lcr;9bdoTpiaUC`wzIRvh@)o+ z02xO^`XuitFGz@xOj#M0t{7Z5Inn?1&^l$UbjXJj2Hr9>Sw~Rsgt?M0= z)Sa0T@}8>)gAkC1G8yP?LVsg+SMwb~Jr66%y;lB0ZTFZ16u-z*)RWZuw$AE|1Hmta zh)T$7>(cp!a0R59Egf(C%MCa@*L#-xT6racX(q?3gz;oYYvr|I5?&s)C-fr6MV=_|_<8_^3dXst2}ZCb z-i_ELecOmvviH3ZRLNd9bKrf#fH)?PFrMY{0r3GDA)a06li53qE|PGHdt~n!L66}W z*390s5ll1kbG1v1k7n=rU=knwWcGd-K?uur-r`=I3qZA6pA;)azpz5}g%DH;7tMe_ zA`Ax$EMX2%{V@zAK3M3JRDXgl5=K=2dr*AJ;C(oTHL1QB!89ZPj4(d(DAn`9BtH5{ zsy~k)n7`|nmzVr8f!k^!04mkux{^JytX~T3Gh~N|y~p-N?(y-qxFz-twlCe)uGzjE zv7-yiY8`DsrPDw@261Cy7uDatocR5pWAp7_|2Xy2?SK0{oNY?o{O;u8J7>>axq0!g zo!QgtKT9v0rjIEDQwF9COc}V38Nk1`#Ohv=cjZNGTmx!h4Nv|SM;jk>-K#pw>GKuW fLG>Fx&nmj9@Dl+J|8l!4Lsz7!`t#N;z7qcf=l$;! literal 727 zcmb7CO>fjN5WVMDOb_j8cV#=9G@DzsZJ~mNg;q!iRgn{q7o)_k9H(@t`rq*fl&#>x z9P;6L^WMxGAAdgEyal?T+40TUD>#~t!0}x@Y3260SafEXF+ypb&FAxwWfV>rB_Xm6 zcW4#w>kMFwU+M>nPiRMFbPc&b9-8;jZ@1i{b_r6$qf|X! zoqNdB0p?1374232%D>|S)*vk38Qr8;th@fo1=<7rvWgAQU^gjI1I3D$lyoa3w9Ct7 z)$(r1imJducI9a~1Gm5P%z0`f(Y?X_cVmSg;LB}PSx=)g!$;I!>%)YTFPPJ$&+k!e zt+_+%6pq23e;UMMVrXvg;X>d4!T|{Gc&Z6?QrXe{`32B%>Sn{0_Jxrm@pndxLtrF! zll6@~JIh`=QMO&d*ovSexn$L{Ye+H+1 yhu^uBBf1125fC>TN-ulE-G7d{o}7{LSz*LDDJ;@8BqX>VxYwpP)-UMsDfy6BT|02M+uIZWN}!?$KI17U9ZayJ|-*^(S@fQ|qxx9lN2_iG8Ki{Zvw+ z)Z+Z5`Nj02`upJEV2Mv}S0ZtOclgB1BP_3v1d>Rv}%lRFuUz1+bA z_#x&L>f*4S4b0}p?1#ge_z_P6>S(u9gAfozf)Nl0Bc2aq*vx7AIZYq4yqo(R_KNzy zrvXCsi2r*dpwiha@6+tB>Y*?VpAe3+l5*8rJy!C?YS7|MD4knT6HdzPYr}jTBLGCE zD*E=0wkpw1bL(+woI)@eTRS>27G#LVBs>tHp+-q~FaQa=5fUDXfc7YF3On)msTqG& z*repddpN)&@i1_c4kYqqriAg)P3SmD0EmwYdd)l&0!|-6BMD=wxT8mFJ3Cv6I66fD z$Rrxlr+LTrf`kakl=V^Ris5yW6aAl!%t%)9w7{oA|02)axMPc5W8HXb#~5tCExl)w zx-m0C-s5#=5CZbBO@?}x(4U+AjeJi~PryoYyO}>(+dbw8#ZU1N^&qvrtFt=eK=9Kc zq7w4jx^#XbyaUqAmW~(xOal(j^_t~=uRIgMG?U|5!g#Wyd*y5}2v3jd(`(j>Ab1Ug zMOB*ZB2N@}d@g`O1>?M}2;AVc+cyw8=P)01Rx*bk<;Z|1ayNp)DxxUlD)5npi0)dnFFs82E;LWgz+p-4v5#u2=VMfpU&QSG?9cu+$MY95cC9& zZq4j{GlFSGezA6m{?Y7R2nO-dPiOC25rnW@=PmBV#Q;>R^+~Z_3<@h$UkX8$aM29- zZNhM{z!K&N)$hPS;)8`gP4&BIB4I@Jp9jTz3_gUTTa)VdBba979}vbz9;JFI7{o_E zP4$Nn1oL~my?h`rDD6>jnIwzwwt9@|&{)vnpT z7O|rV(`p@WL8a3`9)q~Cu!`!po2P&JIpgRXl;XE{Az gaUE1Y;(1olO@*HbaQK(oT_3q3P1UcrZt<1)4^a>AfB*mh literal 728 zcmb7C%Wm5+5WMRvHiz_N8zLnuvTlLfv_b2}ZGr+tQ5b7->9UZ>fTGg4LH@lYm52Md zbPsxPXLfdHdHnfw^$ysKWye>iuinG+1pNLwlrF|T#&U0I|HC>NCiwC-sVs-y+wLQop!H#(ArPi))W;i= zYiF;?c};!v=bsM6Zlgz6bov y#|TSTswY1J@&rgLjnuQ&qW{lPmxH%TJt;g)3bXMZ=6Q5I)?V7yy0Daf? delta 12 TcmeyN@IzsO7^Cq<@k9XtA=U&$ diff --git a/spine-unity/Assets/Examples/Spine/Spineboy/spineboy.png.meta b/spine-unity/Assets/Examples/Spine/Spineboy/spineboy.png.meta index e05f9670c..1174bc26f 100644 --- a/spine-unity/Assets/Examples/Spine/Spineboy/spineboy.png.meta +++ b/spine-unity/Assets/Examples/Spine/Spineboy/spineboy.png.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 49bb65eefe08e424bbf7a38bc98ec638 TextureImporter: + fileIDToRecycleName: {} serializedVersion: 2 mipmaps: mipMapMode: 0 @@ -21,7 +22,7 @@ TextureImporter: generateCubemap: 0 seamlessCubemap: 0 textureFormat: -3 - maxTextureSize: 1024 + maxTextureSize: 2048 textureSettings: filterMode: -1 aniso: -1 diff --git a/spine-unity/Assets/Examples/Spine/Spineboy/spineboy_Material.mat b/spine-unity/Assets/Examples/Spine/Spineboy/spineboy_Material.mat index c6d21d2bca0894fd3cac6ae50cbbbfe6b532906e..33e439d9b19159039a65cf212938fd04a400e23c 100644 GIT binary patch literal 4220 zcmeHKOK%)S5N`7(;SnH&H`zcSgoh!);Sr4SBVMo&$r2~NT5WI7deH8S)zfRd2#Jvp z|9~SufS(YQ3uhF51P3H?ffLu5`l_bKz2hcaIc!P0Q{DA-SM}Fb-7`uZT2t!C*Gj4T z=}8ZzW~R?g&m?Emt-ZayDQZ7Xzt6NYHr0K#s0*XWum>dMPW+Wh-A9jMR;0bmbX#fW z)L{M6#usMOeUf%fyRUnNx{Dx~5Q3-II~`|dm%FLU?eeZOG)bP#(fE!viQedFYceNu zv6nk|0zbu+LR%cR)4o}`zS$C zpPJE^x$PF5cn=47BpxPi(t$*-S4tQkT}{U$1c3OcpjXT@A>i~;bdoTpj5~U)va_@K zh@+zffYi~DKF&MJ3lbtEQ%LkWDM)ZF^G(*|RV*(!w{c4uFQOD-n#=6n!mN6*5 zRlQ@nRcC61yeF!`AOz&0Oa^+J&{xdva<(I=Ct)SI-O8V;>>hJ~;-`6vYLZId)@hY- zAo!UOQ3`o&T{yoGu7D)9h2xEXwgHFdYR@uXE6+tR&E$BVFrMsatsD;~;pI_#e9u}D z1n+^cs0y>0XI%vzPXth?V4TZ}pl)al>Z($?uwH23J+FiH;B}+a=;?IB zj%MiT)reivw~crudtVDdrR;Sx2VN%(h-2~y<5{i`h&RXx@$5n$&)#Wtk%Uv+CVSr$ zbPdO_X7;`n!89X3Q@O#_66OHa@4`UhgM~g$^?T?dVMO_#2gUmg-iKpYlj`#kOf&Ki2;(D+b1NJ literal 731 zcmb7COK;RL5WeSEOb_L>yRwsPn$4|RC{$3o&GPT^HfNj%vF z^Jo?8nhe0DH}xCaFKC@Ix`85G_uEVU6NP`LT0HC6&NV>N^~R!Pe8VhiKS3I}ld8k> z*8y^WfH~K}MF*F^>K|E;4YU73JDcO zRo0w|GGEq9TuM=$R5S47KByN{E0f%N9Df~mU%XDB2Oyo{PQP(PLqd;l@7!tG3g7V+e2Uy z_Ja+LJ*At!Orl(IUM&$Nk{Zjr2JSQk}qLzXib!!suJ yc*5SLbm%7lNr1G~NImNe^Zz;OdhkZdCkKaVQdmsCA|WyLsJ%9wv0*`X_t_tbh|k3U diff --git a/spine-unity/Assets/spine-unity/BoneFollower.cs b/spine-unity/Assets/spine-unity/BoneFollower.cs index 5c8fa3f92..e900ba8ee 100644 --- a/spine-unity/Assets/spine-unity/BoneFollower.cs +++ b/spine-unity/Assets/spine-unity/BoneFollower.cs @@ -40,11 +40,10 @@ using Spine; public class BoneFollower : MonoBehaviour { [System.NonSerialized] - public bool valid; - + public bool + valid; public SkeletonRenderer skeletonRenderer; public Bone bone; - public bool followZPosition = true; public bool followBoneRotation = true; @@ -52,20 +51,18 @@ public class BoneFollower : MonoBehaviour { get { return skeletonRenderer; } set { skeletonRenderer = value; - Reset (); + Reset(); } } /// If a bone isn't set, boneName is used to find the bone. public String boneName; - public bool resetOnAwake = true; - protected Transform cachedTransform; protected Transform skeletonTransform; - public void HandleResetRenderer(SkeletonRenderer skeletonRenderer){ + public void HandleResetRenderer (SkeletonRenderer skeletonRenderer) { Reset(); } @@ -73,32 +70,32 @@ public class BoneFollower : MonoBehaviour { bone = null; cachedTransform = transform; valid = skeletonRenderer != null && skeletonRenderer.valid; - if (!valid) return; + if (!valid) + return; skeletonTransform = skeletonRenderer.transform; skeletonRenderer.OnReset -= HandleResetRenderer; skeletonRenderer.OnReset += HandleResetRenderer; - if(Application.isEditor) + if (Application.isEditor) DoUpdate(); } - void OnDestroy(){ + void OnDestroy () { //cleanup - if(skeletonRenderer != null) + if (skeletonRenderer != null) skeletonRenderer.OnReset -= HandleResetRenderer; } public void Awake () { - if(resetOnAwake) + if (resetOnAwake) Reset(); } - void LateUpdate(){ + void LateUpdate () { DoUpdate(); } - public void DoUpdate () { if (!valid) { Reset(); @@ -106,13 +103,13 @@ public class BoneFollower : MonoBehaviour { } if (bone == null) { - if (boneName == null || boneName.Length == 0) return; + if (boneName == null || boneName.Length == 0) + return; bone = skeletonRenderer.skeleton.FindBone(boneName); if (bone == null) { Debug.LogError("Bone not found: " + boneName, this); return; - } - else{ + } else { } } @@ -123,21 +120,22 @@ public class BoneFollower : MonoBehaviour { if (cachedTransform.parent == skeletonTransform) { cachedTransform.localPosition = new Vector3(bone.worldX, bone.worldY, followZPosition ? 0f : cachedTransform.localPosition.z); - if(followBoneRotation) { + if (followBoneRotation) { Vector3 rotation = cachedTransform.localRotation.eulerAngles; cachedTransform.localRotation = Quaternion.Euler(rotation.x, rotation.y, bone.worldRotation * flipRotation); } } else { Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, 0f)); - if(!followZPosition) targetWorldPosition.z = cachedTransform.position.z; + if (!followZPosition) + targetWorldPosition.z = cachedTransform.position.z; cachedTransform.position = targetWorldPosition; - if(followBoneRotation) { + if (followBoneRotation) { Vector3 rotation = skeletonTransform.rotation.eulerAngles; - cachedTransform.rotation = Quaternion.Euler(rotation.x, rotation.y, skeletonTransform.rotation.eulerAngles.z + (bone.worldRotation * flipRotation) ); + cachedTransform.rotation = Quaternion.Euler(rotation.x, rotation.y, skeletonTransform.rotation.eulerAngles.z + (bone.worldRotation * flipRotation)); } } diff --git a/spine-unity/Assets/spine-unity/Editor/AtlasAssetInspector.cs b/spine-unity/Assets/spine-unity/Editor/AtlasAssetInspector.cs index 8e778ceed..136b7aae8 100644 --- a/spine-unity/Assets/spine-unity/Editor/AtlasAssetInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/AtlasAssetInspector.cs @@ -27,7 +27,6 @@ * 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; diff --git a/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs b/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs index ffb74810b..943a98715 100644 --- a/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs @@ -27,7 +27,6 @@ * 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; @@ -36,6 +35,7 @@ using UnityEngine; public class BoneFollowerInspector : Editor { private SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation; BoneFollower component; + void OnEnable () { skeletonRenderer = serializedObject.FindProperty("skeletonRenderer"); boneName = serializedObject.FindProperty("boneName"); @@ -45,20 +45,20 @@ public class BoneFollowerInspector : Editor { ForceReload(); } - void FindRenderer(){ - if(skeletonRenderer.objectReferenceValue == null){ - SkeletonRenderer parentRenderer = SkeletonUtility.GetInParent( component.transform ); + void FindRenderer () { + if (skeletonRenderer.objectReferenceValue == null) { + SkeletonRenderer parentRenderer = SkeletonUtility.GetInParent(component.transform); - if(parentRenderer != null){ + if (parentRenderer != null) { skeletonRenderer.objectReferenceValue = (UnityEngine.Object)parentRenderer; } } } - void ForceReload(){ - if(component.skeletonRenderer != null){ - if(component.skeletonRenderer.valid == false) + void ForceReload () { + if (component.skeletonRenderer != null) { + if (component.skeletonRenderer.valid == false) component.skeletonRenderer.Reset(); } } @@ -72,10 +72,9 @@ public class BoneFollowerInspector : Editor { if (component.valid) { String[] bones = new String[1]; - try{ + try { bones = new String[component.skeletonRenderer.skeleton.Data.Bones.Count + 1]; - } - catch{ + } catch { } @@ -94,13 +93,12 @@ public class BoneFollowerInspector : Editor { boneName.stringValue = boneIndex == 0 ? null : bones[boneIndex]; EditorGUILayout.PropertyField(followBoneRotation); EditorGUILayout.PropertyField(followZPosition); - } - else{ + } else { GUILayout.Label("INVALID"); } if (serializedObject.ApplyModifiedProperties() || - (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") + (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") ) { component.Reset(); } diff --git a/spine-unity/Assets/spine-unity/Editor/Menus.cs b/spine-unity/Assets/spine-unity/Editor/Menus.cs index e4ed1db30..578493228 100644 --- a/spine-unity/Assets/spine-unity/Editor/Menus.cs +++ b/spine-unity/Assets/spine-unity/Editor/Menus.cs @@ -27,7 +27,6 @@ * 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 UnityEditor; @@ -50,7 +49,8 @@ public class Menus { var selected = Selection.activeObject; if (selected != null) { var assetDir = AssetDatabase.GetAssetPath(selected.GetInstanceID()); - if (assetDir.Length > 0 && Directory.Exists(assetDir)) dir = assetDir + "/"; + if (assetDir.Length > 0 && Directory.Exists(assetDir)) + dir = assetDir + "/"; } ScriptableObject asset = ScriptableObject.CreateInstance(); AssetDatabase.CreateAsset(asset, dir + name + ".asset"); diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs index 1035e8df7..f338626b2 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs @@ -27,7 +27,6 @@ * 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; @@ -44,7 +43,7 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector { loop = serializedObject.FindProperty("loop"); timeScale = serializedObject.FindProperty("timeScale"); - if(PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab) + if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab) isPrefab = true; @@ -54,13 +53,14 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector { base.gui(); SkeletonAnimation component = (SkeletonAnimation)target; - if (!component.valid) return; + if (!component.valid) + return; //catch case where SetAnimation was used to set track 0 without using AnimationName - if(Application.isPlaying){ + if (Application.isPlaying) { TrackEntry currentState = component.state.GetCurrent(0); - if(currentState != null){ - if(component.AnimationName != animationName.stringValue){ + if (currentState != null) { + if (component.AnimationName != animationName.stringValue) { animationName.stringValue = currentState.Animation.Name; } } @@ -86,7 +86,7 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector { EditorGUILayout.EndHorizontal(); String selectedAnimationName = animationIndex == 0 ? null : animations[animationIndex]; - if(component.AnimationName != selectedAnimationName){ + if (component.AnimationName != selectedAnimationName) { component.AnimationName = selectedAnimationName; animationName.stringValue = selectedAnimationName; } @@ -100,9 +100,9 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector { EditorGUILayout.Space(); - if(!isPrefab){ - if(component.GetComponent() == null){ - if(GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))){ + if (!isPrefab) { + if (component.GetComponent() == null) { + if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) { component.gameObject.AddComponent(); } } diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs index 09618fa45..df0061291 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs @@ -32,10 +32,10 @@ * Automatic import and advanced preview added by Mitch Thompson * Full irrevocable rights and permissions granted to Esoteric Software *****************************************************************************/ - using System; using System.Collections.Generic; using UnityEditor; + #if !UNITY_4_3 using UnityEditor.AnimatedValues; #endif @@ -58,7 +58,7 @@ public class SkeletonDataAssetInspector : Editor { private string m_skeletonDataAssetGUID; void OnEnable () { - try{ + try { atlasAsset = serializedObject.FindProperty("atlasAsset"); skeletonJSON = serializedObject.FindProperty("skeletonJSON"); @@ -69,23 +69,21 @@ public class SkeletonDataAssetInspector : Editor { defaultMix = serializedObject.FindProperty("defaultMix"); m_skeletonDataAsset = (SkeletonDataAsset)target; - m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath(m_skeletonDataAsset) ); + m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset)); EditorApplication.update += Update; - } - catch{ + } catch { } } - void OnDestroy(){ + void OnDestroy () { m_initialized = false; EditorApplication.update -= Update; this.DestroyPreviewInstances(); - if (this.m_previewUtility != null) - { + if (this.m_previewUtility != null) { this.m_previewUtility.Cleanup(); this.m_previewUtility = null; } @@ -99,8 +97,8 @@ public class SkeletonDataAssetInspector : Editor { EditorGUILayout.PropertyField(atlasAsset); EditorGUILayout.PropertyField(skeletonJSON); EditorGUILayout.PropertyField(scale); - if(EditorGUI.EndChangeCheck()){ - if(m_previewUtility != null){ + if (EditorGUI.EndChangeCheck()) { + if (m_previewUtility != null) { m_previewUtility.Cleanup(); m_previewUtility = null; } @@ -143,7 +141,7 @@ public class SkeletonDataAssetInspector : Editor { EditorGUILayout.EndHorizontal(); } - if(GUILayout.Button(new GUIContent("Setup Pose", SpineEditorUtilities.Icons.skeleton), GUILayout.Width(105), GUILayout.Height(18))){ + if (GUILayout.Button(new GUIContent("Setup Pose", SpineEditorUtilities.Icons.skeleton), GUILayout.Width(105), GUILayout.Height(18))) { StopAnimation(); m_skeletonAnimation.skeleton.SetToSetupPose(); m_requireRefresh = true; @@ -152,357 +150,342 @@ public class SkeletonDataAssetInspector : Editor { #if UNITY_4_3 m_showAnimationList = EditorGUILayout.Foldout(m_showAnimationList, new GUIContent("Animations", SpineEditorUtilities.Icons.animationRoot)); if(m_showAnimationList){ - #else - m_showAnimationList.target = EditorGUILayout.Foldout(m_showAnimationList.target, new GUIContent("Animations", SpineEditorUtilities.Icons.animationRoot)); - if(EditorGUILayout.BeginFadeGroup(m_showAnimationList.faded)){ - #endif - - - - - EditorGUILayout.LabelField("Name", "Duration"); - foreach(Spine.Animation a in skeletonData.Animations){ - GUILayout.BeginHorizontal(); - - if(m_skeletonAnimation != null && m_skeletonAnimation.state != null){ - if(m_skeletonAnimation.state.GetCurrent(0) != null && m_skeletonAnimation.state.GetCurrent(0).Animation == a){ - GUI.contentColor = Color.black; - if(GUILayout.Button("\u25BA", GUILayout.Width(24))){ - StopAnimation(); - } - GUI.contentColor = Color.white; - } - else{ - if(GUILayout.Button("\u25BA", GUILayout.Width(24))){ - PlayAnimation(a.Name, true); - } - } - } - else{ - GUILayout.Label("?", GUILayout.Width(24)); - } - EditorGUILayout.LabelField(new GUIContent(a.Name, SpineEditorUtilities.Icons.animation), new GUIContent(a.Duration.ToString("f3") + "s" + ("(" + (Mathf.RoundToInt(a.Duration * 30)) + ")").PadLeft(12, ' '))); - GUILayout.EndHorizontal(); - } - } - #if !UNITY_4_3 - EditorGUILayout.EndFadeGroup(); + #else + m_showAnimationList.target = EditorGUILayout.Foldout(m_showAnimationList.target, new GUIContent("Animations", SpineEditorUtilities.Icons.animationRoot)); + if (EditorGUILayout.BeginFadeGroup(m_showAnimationList.faded)) { #endif - } - - if (!Application.isPlaying) { - if (serializedObject.ApplyModifiedProperties() || - (UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed") - ) { - asset.Reset(); - } - } - } - - //preview window stuff - private PreviewRenderUtility m_previewUtility; - private GameObject m_previewInstance; - private Vector2 previewDir; - private SkeletonAnimation m_skeletonAnimation; - private SkeletonData m_skeletonData; - - private static int sliderHash = "Slider".GetHashCode(); - private float m_lastTime; - private bool m_playing; - private bool m_requireRefresh; - - private Color m_originColor = new Color(0.3f,0.3f,0.3f, 1); - - private void StopAnimation(){ - m_skeletonAnimation.state.ClearTrack(0); - m_playing = false; - } - - - List m_animEvents = new List(); - List m_animEventFrames = new List(); - private void PlayAnimation(string animName, bool loop){ - m_animEvents.Clear(); - m_animEventFrames.Clear(); - - m_skeletonAnimation.state.SetAnimation(0, animName, loop); - - Spine.Animation a = m_skeletonAnimation.state.GetCurrent(0).Animation; - foreach(Timeline t in a.Timelines){ - if(t.GetType() == typeof(EventTimeline)){ - EventTimeline et = (EventTimeline)t; - for(int i = 0; i < et.Events.Length; i++){ - m_animEvents.Add(et.Events[i]); - m_animEventFrames.Add(et.Frames[i]); + + + + EditorGUILayout.LabelField("Name", "Duration"); + foreach (Spine.Animation a in skeletonData.Animations) { + GUILayout.BeginHorizontal(); + + if (m_skeletonAnimation != null && m_skeletonAnimation.state != null) { + if (m_skeletonAnimation.state.GetCurrent(0) != null && m_skeletonAnimation.state.GetCurrent(0).Animation == a) { + GUI.contentColor = Color.black; + if (GUILayout.Button("\u25BA", GUILayout.Width(24))) { + StopAnimation(); + } + GUI.contentColor = Color.white; + } else { + if (GUILayout.Button("\u25BA", GUILayout.Width(24))) { + PlayAnimation(a.Name, true); + } + } + } else { + GUILayout.Label("?", GUILayout.Width(24)); } - + EditorGUILayout.LabelField(new GUIContent(a.Name, SpineEditorUtilities.Icons.animation), new GUIContent(a.Duration.ToString("f3") + "s" + ("(" + (Mathf.RoundToInt(a.Duration * 30)) + ")").PadLeft(12, ' '))); + GUILayout.EndHorizontal(); } } - - m_playing = true; + #if !UNITY_4_3 + EditorGUILayout.EndFadeGroup(); + #endif } - - private void InitPreview() - { - if (this.m_previewUtility == null) - { - this.m_lastTime = Time.realtimeSinceStartup; - this.m_previewUtility = new PreviewRenderUtility(true); - this.m_previewUtility.m_Camera.isOrthoGraphic = true; - this.m_previewUtility.m_Camera.orthographicSize = 1; - this.m_previewUtility.m_Camera.cullingMask = -2147483648; - this.CreatePreviewInstances(); + + if (!Application.isPlaying) { + if (serializedObject.ApplyModifiedProperties() || + (UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed") + ) { + asset.Reset(); } } + } - private void CreatePreviewInstances() - { - this.DestroyPreviewInstances(); - if (this.m_previewInstance == null) - { - string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", ""); + //preview window stuff + private PreviewRenderUtility m_previewUtility; + private GameObject m_previewInstance; + private Vector2 previewDir; + private SkeletonAnimation m_skeletonAnimation; + private SkeletonData m_skeletonData; + private static int sliderHash = "Slider".GetHashCode(); + private float m_lastTime; + private bool m_playing; + private bool m_requireRefresh; + private Color m_originColor = new Color(0.3f, 0.3f, 0.3f, 1); + + private void StopAnimation () { + m_skeletonAnimation.state.ClearTrack(0); + m_playing = false; + } + + List m_animEvents = new List(); + List m_animEventFrames = new List(); + + private void PlayAnimation (string animName, bool loop) { + m_animEvents.Clear(); + m_animEventFrames.Clear(); + + m_skeletonAnimation.state.SetAnimation(0, animName, loop); + + Spine.Animation a = m_skeletonAnimation.state.GetCurrent(0).Animation; + foreach (Timeline t in a.Timelines) { + if (t.GetType() == typeof(EventTimeline)) { + EventTimeline et = (EventTimeline)t; + + for (int i = 0; i < et.Events.Length; i++) { + m_animEvents.Add(et.Events[i]); + m_animEventFrames.Add(et.Frames[i]); + } + + } + } + + m_playing = true; + } + + private void InitPreview () { + if (this.m_previewUtility == null) { + this.m_lastTime = Time.realtimeSinceStartup; + this.m_previewUtility = new PreviewRenderUtility(true); + this.m_previewUtility.m_Camera.isOrthoGraphic = true; + this.m_previewUtility.m_Camera.orthographicSize = 1; + this.m_previewUtility.m_Camera.cullingMask = -2147483648; + this.CreatePreviewInstances(); + } + } + + private void CreatePreviewInstances () { + this.DestroyPreviewInstances(); + if (this.m_previewInstance == null) { + string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", ""); - m_previewInstance = SpineEditorUtilities.SpawnAnimatedSkeleton( (SkeletonDataAsset)target, skinName ).gameObject; - m_previewInstance.hideFlags = HideFlags.HideAndDontSave; - m_previewInstance.layer = 0x1f; + m_previewInstance = SpineEditorUtilities.SpawnAnimatedSkeleton((SkeletonDataAsset)target, skinName).gameObject; + m_previewInstance.hideFlags = HideFlags.HideAndDontSave; + m_previewInstance.layer = 0x1f; - m_skeletonAnimation = m_previewInstance.GetComponent(); - m_skeletonAnimation.initialSkinName = skinName; + m_skeletonAnimation = m_previewInstance.GetComponent(); + m_skeletonAnimation.initialSkinName = skinName; + m_skeletonAnimation.LateUpdate(); + + m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true); + + m_previewInstance.renderer.enabled = false; + + m_initialized = true; + AdjustCameraGoals(true); + } + } + + private void DestroyPreviewInstances () { + if (this.m_previewInstance != null) { + DestroyImmediate(this.m_previewInstance); + m_previewInstance = null; + } + m_initialized = false; + } + + public override bool HasPreviewGUI () { + //TODO: validate json data + return skeletonJSON.objectReferenceValue != null; + } + + Texture m_previewTex = new Texture(); + + public override void OnInteractivePreviewGUI (Rect r, GUIStyle background) { + this.InitPreview(); + + if (UnityEngine.Event.current.type == EventType.Repaint) { + if (m_requireRefresh) { + this.m_previewUtility.BeginPreview(r, background); + this.DoRenderPreview(true); + this.m_previewTex = this.m_previewUtility.EndPreview(); + m_requireRefresh = false; + } + if (this.m_previewTex != null) + GUI.DrawTexture(r, m_previewTex, ScaleMode.StretchToFill, false); + } + + DrawSkinToolbar(r); + NormalizedTimeBar(r); + //TODO: implement panning + // this.previewDir = Drag2D(this.previewDir, r); + MouseScroll(r); + } + + float m_orthoGoal = 1; + Vector3 m_posGoal = new Vector3(0, 0, -10); + double m_adjustFrameEndTime = 0; + + private void AdjustCameraGoals (bool calculateMixTime) { + if (calculateMixTime) { + if (m_skeletonAnimation.state.GetCurrent(0) != null) { + m_adjustFrameEndTime = EditorApplication.timeSinceStartup + m_skeletonAnimation.state.GetCurrent(0).Mix; + } + } + + + GameObject go = this.m_previewInstance; + Bounds bounds = go.renderer.bounds; + m_orthoGoal = bounds.size.y; + + m_posGoal = bounds.center + new Vector3(0, 0, -10); + } + + private void AdjustCameraGoals () { + AdjustCameraGoals(false); + } + + private void AdjustCamera () { + if (m_previewUtility == null) + return; + + + if (EditorApplication.timeSinceStartup < m_adjustFrameEndTime) { + AdjustCameraGoals(); + } + + float orthoSet = Mathf.Lerp(this.m_previewUtility.m_Camera.orthographicSize, m_orthoGoal, 0.1f); + + this.m_previewUtility.m_Camera.orthographicSize = orthoSet; + + float dist = Vector3.Distance(m_previewUtility.m_Camera.transform.position, m_posGoal); + if (dist > 60f * ((SkeletonDataAsset)target).scale) { + Vector3 pos = Vector3.Lerp(this.m_previewUtility.m_Camera.transform.position, m_posGoal, 0.1f); + pos.x = 0; + this.m_previewUtility.m_Camera.transform.position = pos; + this.m_previewUtility.m_Camera.transform.rotation = Quaternion.identity; + m_requireRefresh = true; + } + } + + private void DoRenderPreview (bool drawHandles) { + GameObject go = this.m_previewInstance; + + if (m_requireRefresh) { + go.renderer.enabled = true; + + if (EditorApplication.isPlaying) { + //do nothing + } else { + m_skeletonAnimation.Update((Time.realtimeSinceStartup - m_lastTime)); + } + + m_lastTime = Time.realtimeSinceStartup; + + if (!EditorApplication.isPlaying) m_skeletonAnimation.LateUpdate(); - m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true); - - m_previewInstance.renderer.enabled = false; - - m_initialized = true; - AdjustCameraGoals(true); - } - } - - private void DestroyPreviewInstances() - { - if (this.m_previewInstance != null) - { - DestroyImmediate(this.m_previewInstance); - m_previewInstance = null; - } - m_initialized = false; - } - - public override bool HasPreviewGUI () - { - //TODO: validate json data - return skeletonJSON.objectReferenceValue != null; - } - - Texture m_previewTex = new Texture(); - public override void OnInteractivePreviewGUI(Rect r, GUIStyle background) - { - this.InitPreview(); - - if (UnityEngine.Event.current.type == EventType.Repaint) - { - if(m_requireRefresh){ - this.m_previewUtility.BeginPreview(r, background); - this.DoRenderPreview(true); - this.m_previewTex = this.m_previewUtility.EndPreview(); - m_requireRefresh = false; - } - if(this.m_previewTex != null) - GUI.DrawTexture(r, m_previewTex, ScaleMode.StretchToFill, false); - } - - DrawSkinToolbar(r); - NormalizedTimeBar(r); - //TODO: implement panning - // this.previewDir = Drag2D(this.previewDir, r); - MouseScroll(r); - } - - float m_orthoGoal = 1; - Vector3 m_posGoal = new Vector3(0,0,-10); - double m_adjustFrameEndTime = 0; - private void AdjustCameraGoals(bool calculateMixTime){ - if(calculateMixTime){ - if(m_skeletonAnimation.state.GetCurrent(0) != null){ - m_adjustFrameEndTime = EditorApplication.timeSinceStartup + m_skeletonAnimation.state.GetCurrent(0).Mix; - } - } - - - GameObject go = this.m_previewInstance; - Bounds bounds = go.renderer.bounds; - m_orthoGoal = bounds.size.y; - - m_posGoal = bounds.center + new Vector3(0,0,-10); - } - - private void AdjustCameraGoals(){ - AdjustCameraGoals(false); - } - - private void AdjustCamera(){ - if(m_previewUtility == null) - return; - - - if(EditorApplication.timeSinceStartup < m_adjustFrameEndTime){ - AdjustCameraGoals(); - } - - float orthoSet = Mathf.Lerp(this.m_previewUtility.m_Camera.orthographicSize, m_orthoGoal, 0.1f); - - this.m_previewUtility.m_Camera.orthographicSize = orthoSet; - - float dist = Vector3.Distance(m_previewUtility.m_Camera.transform.position, m_posGoal); - if(dist > 60f * ((SkeletonDataAsset)target).scale){ - Vector3 pos = Vector3.Lerp(this.m_previewUtility.m_Camera.transform.position, m_posGoal, 0.1f); - pos.x = 0; - this.m_previewUtility.m_Camera.transform.position = pos; - this.m_previewUtility.m_Camera.transform.rotation = Quaternion.identity; - m_requireRefresh = true; - } - } - - private void DoRenderPreview(bool drawHandles) - { - GameObject go = this.m_previewInstance; - - if(m_requireRefresh){ - go.renderer.enabled = true; - - if(EditorApplication.isPlaying){ - //do nothing - } - else{ - m_skeletonAnimation.Update((Time.realtimeSinceStartup - m_lastTime)); - } - - m_lastTime = Time.realtimeSinceStartup; - - if(!EditorApplication.isPlaying) - m_skeletonAnimation.LateUpdate(); - - if(drawHandles){ - Handles.SetCamera(m_previewUtility.m_Camera); - Handles.color = m_originColor; + if (drawHandles) { + Handles.SetCamera(m_previewUtility.m_Camera); + Handles.color = m_originColor; - Handles.DrawLine(new Vector3(-1000 * m_skeletonDataAsset.scale,0,0), new Vector3(1000 * m_skeletonDataAsset.scale,0,0)); - Handles.DrawLine(new Vector3(0,1000 * m_skeletonDataAsset.scale,0), new Vector3(0,-1000 * m_skeletonDataAsset.scale,0)); - } + Handles.DrawLine(new Vector3(-1000 * m_skeletonDataAsset.scale, 0, 0), new Vector3(1000 * m_skeletonDataAsset.scale, 0, 0)); + Handles.DrawLine(new Vector3(0, 1000 * m_skeletonDataAsset.scale, 0), new Vector3(0, -1000 * m_skeletonDataAsset.scale, 0)); + } - this.m_previewUtility.m_Camera.Render(); - go.renderer.enabled = false; - } - - + this.m_previewUtility.m_Camera.Render(); + go.renderer.enabled = false; } - - void Update(){ - AdjustCamera(); - if (m_playing) { - m_requireRefresh = true; + + } + + void Update () { + AdjustCamera(); + + if (m_playing) { + m_requireRefresh = true; + Repaint(); + } else if (m_requireRefresh) { Repaint(); - } - else if (m_requireRefresh) { - Repaint (); - } - else{ + } else { #if !UNITY_4_3 - if(m_showAnimationList.isAnimating) + if (m_showAnimationList.isAnimating) Repaint(); #endif } - } + } - void DrawSkinToolbar(Rect r){ - if(m_skeletonAnimation == null) - return; + void DrawSkinToolbar (Rect r) { + if (m_skeletonAnimation == null) + return; - if(m_skeletonAnimation.skeleton != null){ - string label = (m_skeletonAnimation.skeleton != null && m_skeletonAnimation.skeleton.Skin != null) ? m_skeletonAnimation.skeleton.Skin.Name : "default"; + if (m_skeletonAnimation.skeleton != null) { + string label = (m_skeletonAnimation.skeleton != null && m_skeletonAnimation.skeleton.Skin != null) ? m_skeletonAnimation.skeleton.Skin.Name : "default"; - Rect popRect = new Rect(r); - popRect.y += 32; - popRect.x += 4; - popRect.height = 24; - popRect.width = 40; - EditorGUI.DropShadowLabel(popRect, new GUIContent("Skin", SpineEditorUtilities.Icons.skinsRoot)); + Rect popRect = new Rect(r); + popRect.y += 32; + popRect.x += 4; + popRect.height = 24; + popRect.width = 40; + EditorGUI.DropShadowLabel(popRect, new GUIContent("Skin", SpineEditorUtilities.Icons.skinsRoot)); - popRect.y += 11; - popRect.width = 150; - popRect.x += 44; + popRect.y += 11; + popRect.width = 150; + popRect.x += 44; - if(GUI.Button( popRect, label, EditorStyles.popup)){ - SelectSkinContext(); - } + if (GUI.Button(popRect, label, EditorStyles.popup)) { + SelectSkinContext(); } } + } - void SelectSkinContext(){ - GenericMenu menu = new GenericMenu(); + void SelectSkinContext () { + GenericMenu menu = new GenericMenu(); - foreach(Skin s in m_skeletonData.Skins){ - menu.AddItem( new GUIContent(s.Name), this.m_skeletonAnimation.skeleton.Skin == s, SetSkin, (object)s); - } - - menu.ShowAsContext(); + foreach (Skin s in m_skeletonData.Skins) { + menu.AddItem(new GUIContent(s.Name), this.m_skeletonAnimation.skeleton.Skin == s, SetSkin, (object)s); } + + menu.ShowAsContext(); + } - void SetSkin(object o){ - Skin skin = (Skin)o; + void SetSkin (object o) { + Skin skin = (Skin)o; - m_skeletonAnimation.initialSkinName = skin.Name; - m_skeletonAnimation.Reset(); - m_requireRefresh = true; + m_skeletonAnimation.initialSkinName = skin.Name; + m_skeletonAnimation.Reset(); + m_requireRefresh = true; - EditorPrefs.SetString(m_skeletonDataAssetGUID + "_lastSkin", skin.Name); - } + EditorPrefs.SetString(m_skeletonDataAssetGUID + "_lastSkin", skin.Name); + } - void NormalizedTimeBar(Rect r){ - Rect barRect = new Rect(r); - barRect.height = 32; - barRect.x += 4; - barRect.width -=4; + void NormalizedTimeBar (Rect r) { + Rect barRect = new Rect(r); + barRect.height = 32; + barRect.x += 4; + barRect.width -= 4; - GUI.Box(barRect, ""); + GUI.Box(barRect, ""); - Rect lineRect = new Rect(barRect); - float width = lineRect.width; - TrackEntry t = m_skeletonAnimation.state.GetCurrent(0); + Rect lineRect = new Rect(barRect); + float width = lineRect.width; + TrackEntry t = m_skeletonAnimation.state.GetCurrent(0); - if(t != null){ - int loopCount = (int)(t.Time / t.EndTime); - float currentTime = t.Time - (t.EndTime * loopCount); + if (t != null) { + int loopCount = (int)(t.Time / t.EndTime); + float currentTime = t.Time - (t.EndTime * loopCount); - float normalizedTime = currentTime / t.Animation.Duration; + float normalizedTime = currentTime / t.Animation.Duration; - lineRect.x = barRect.x + (width * normalizedTime) - 0.5f; - lineRect.width = 2; + lineRect.x = barRect.x + (width * normalizedTime) - 0.5f; + lineRect.width = 2; - GUI.color = Color.red; - GUI.DrawTexture(lineRect, EditorGUIUtility.whiteTexture); - GUI.color = Color.white; + GUI.color = Color.red; + GUI.DrawTexture(lineRect, EditorGUIUtility.whiteTexture); + GUI.color = Color.white; - for(int i = 0; i < m_animEvents.Count; i++){ - //TODO: Tooltip - //Spine.Event spev = animEvents[i]; + for (int i = 0; i < m_animEvents.Count; i++) { + //TODO: Tooltip + //Spine.Event spev = animEvents[i]; - float fr = m_animEventFrames[i]; + float fr = m_animEventFrames[i]; - Rect evRect = new Rect(barRect); - evRect.x = Mathf.Clamp(((fr / t.Animation.Duration) * width) - (SpineEditorUtilities.Icons._event.width/2), barRect.x, float.MaxValue); - evRect.width = SpineEditorUtilities.Icons._event.width; - evRect.height = SpineEditorUtilities.Icons._event.height; - evRect.y += SpineEditorUtilities.Icons._event.height; - GUI.DrawTexture(evRect, SpineEditorUtilities.Icons._event); + Rect evRect = new Rect(barRect); + evRect.x = Mathf.Clamp(((fr / t.Animation.Duration) * width) - (SpineEditorUtilities.Icons._event.width / 2), barRect.x, float.MaxValue); + evRect.width = SpineEditorUtilities.Icons._event.width; + evRect.height = SpineEditorUtilities.Icons._event.height; + evRect.y += SpineEditorUtilities.Icons._event.height; + GUI.DrawTexture(evRect, SpineEditorUtilities.Icons._event); - //TODO: Tooltip - /* + //TODO: Tooltip + /* UnityEngine.Event ev = UnityEngine.Event.current; if(ev.isMouse){ if(evRect.Contains(ev.mousePosition)){ @@ -514,29 +497,29 @@ public class SkeletonDataAssetInspector : Editor { } } */ - } } } + } - void MouseScroll(Rect position){ - UnityEngine.Event current = UnityEngine.Event.current; - int controlID = GUIUtility.GetControlID(sliderHash, FocusType.Passive); + void MouseScroll (Rect position) { + UnityEngine.Event current = UnityEngine.Event.current; + int controlID = GUIUtility.GetControlID(sliderHash, FocusType.Passive); - switch(current.GetTypeForControl(controlID)){ - case EventType.ScrollWheel: - if(position.Contains(current.mousePosition)){ + switch (current.GetTypeForControl(controlID)) { + case EventType.ScrollWheel: + if (position.Contains(current.mousePosition)) { - m_orthoGoal += current.delta.y * ((SkeletonDataAsset)target).scale * 10; - GUIUtility.hotControl = controlID; - current.Use(); - } - break; + m_orthoGoal += current.delta.y * ((SkeletonDataAsset)target).scale * 10; + GUIUtility.hotControl = controlID; + current.Use(); } - + break; } + + } - //TODO: Implement preview panning - /* + //TODO: Implement preview panning + /* static Vector2 Drag2D(Vector2 scrollPosition, Rect position) { int controlID = GUIUtility.GetControlID(sliderHash, FocusType.Passive); @@ -577,56 +560,52 @@ public class SkeletonDataAssetInspector : Editor { } */ - public override GUIContent GetPreviewTitle () - { - return new GUIContent ("Preview"); - } + public override GUIContent GetPreviewTitle () { + return new GUIContent("Preview"); + } - public override void OnPreviewSettings () - { - if(!m_initialized){ - GUILayout.HorizontalSlider(0,0,2, GUILayout.MaxWidth(64)); - } - else{ - float speed = GUILayout.HorizontalSlider( m_skeletonAnimation.timeScale, 0, 2, GUILayout.MaxWidth(64)); + public override void OnPreviewSettings () { + if (!m_initialized) { + GUILayout.HorizontalSlider(0, 0, 2, GUILayout.MaxWidth(64)); + } else { + float speed = GUILayout.HorizontalSlider(m_skeletonAnimation.timeScale, 0, 2, GUILayout.MaxWidth(64)); - //snap to nearest 0.25 - float y = speed / 0.25f; - int q = Mathf.RoundToInt(y); - speed = q * 0.25f; + //snap to nearest 0.25 + float y = speed / 0.25f; + int q = Mathf.RoundToInt(y); + speed = q * 0.25f; - m_skeletonAnimation.timeScale = speed; - } + m_skeletonAnimation.timeScale = speed; } + } - //TODO: Fix first-import error - //TODO: Update preview without thumbnail - public override Texture2D RenderStaticPreview (string assetPath, UnityEngine.Object[] subAssets, int width, int height) - { - Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false); + //TODO: Fix first-import error + //TODO: Update preview without thumbnail + public override Texture2D RenderStaticPreview (string assetPath, UnityEngine.Object[] subAssets, int width, int height) { + Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false); - this.InitPreview(); + this.InitPreview(); - if(this.m_previewUtility.m_Camera == null) - return null; + if (this.m_previewUtility.m_Camera == null) + return null; - m_requireRefresh = true; - this.DoRenderPreview(false); - AdjustCameraGoals(false); + m_requireRefresh = true; + this.DoRenderPreview(false); + AdjustCameraGoals(false); - this.m_previewUtility.m_Camera.orthographicSize = m_orthoGoal/2; - this.m_previewUtility.m_Camera.transform.position = m_posGoal; - this.m_previewUtility.BeginStaticPreview(new Rect(0,0,width,height)); - this.DoRenderPreview(false); + this.m_previewUtility.m_Camera.orthographicSize = m_orthoGoal / 2; + this.m_previewUtility.m_Camera.transform.position = m_posGoal; + this.m_previewUtility.BeginStaticPreview(new Rect(0, 0, width, height)); + this.DoRenderPreview(false); - //TODO: Figure out why this is throwing errors on first attempt - // if(m_previewUtility != null){ - // Handles.SetCamera(this.m_previewUtility.m_Camera); - // Handles.BeginGUI(); - // GUI.DrawTexture(new Rect(40,60,width,height), SpineEditorUtilities.Icons.spine, ScaleMode.StretchToFill); - // Handles.EndGUI(); - // } - tex = this.m_previewUtility.EndStaticPreview(); - return tex; - } - } \ No newline at end of file + //TODO: Figure out why this is throwing errors on first attempt + // if(m_previewUtility != null){ + // Handles.SetCamera(this.m_previewUtility.m_Camera); + // Handles.BeginGUI(); + // GUI.DrawTexture(new Rect(40,60,width,height), SpineEditorUtilities.Icons.spine, ScaleMode.StretchToFill); + // Handles.EndGUI(); + // } + tex = this.m_previewUtility.EndStaticPreview(); + return tex; + } +} \ No newline at end of file diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs index 4a9803827..3c918ac89 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs @@ -27,7 +27,6 @@ * 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; @@ -64,7 +63,8 @@ public class SkeletonRendererInspector : Editor { if (!component.valid) { component.Reset(); component.LateUpdate(); - if (!component.valid) return; + if (!component.valid) + return; } // Initial skin name. @@ -100,7 +100,8 @@ public class SkeletonRendererInspector : Editor { if (serializedObject.ApplyModifiedProperties() || (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") ) { - if (!Application.isPlaying) ((SkeletonRenderer)target).Reset(); + if (!Application.isPlaying) + ((SkeletonRenderer)target).Reset(); } } } diff --git a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs index e3afbb71a..3b95ba432 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs @@ -33,7 +33,6 @@ * Spine Editor Utilities created by Mitch Thompson * Full irrevocable rights and permissions granted to Esoteric Software *****************************************************************************/ - using UnityEngine; using UnityEditor; using System.Collections; @@ -45,7 +44,7 @@ using Spine; [InitializeOnLoad] public class SpineEditorUtilities : AssetPostprocessor { - public static class Icons{ + public static class Icons { public static Texture2D skeleton; public static Texture2D nullBone; public static Texture2D bone; @@ -68,11 +67,16 @@ public class SpineEditorUtilities : AssetPostprocessor { public static Texture2D hingeChain; public static Texture2D subMeshRenderer; - public static Mesh boneMesh{ - get{ - if(_boneMesh == null){ + public static Mesh boneMesh { + get { + if (_boneMesh == null) { _boneMesh = new Mesh(); - _boneMesh.vertices = new Vector3[4]{Vector3.zero, new Vector3(-0.1f,0.1f,0), Vector3.up, new Vector3(0.1f,0.1f,0)}; + _boneMesh.vertices = new Vector3[4] { + Vector3.zero, + new Vector3(-0.1f, 0.1f, 0), + Vector3.up, + new Vector3(0.1f, 0.1f, 0) + }; _boneMesh.uv = new Vector2[4]; _boneMesh.triangles = new int[6]{0,1,2,2,3,0}; _boneMesh.RecalculateBounds(); @@ -82,12 +86,12 @@ public class SpineEditorUtilities : AssetPostprocessor { return _boneMesh; } } + internal static Mesh _boneMesh; - - public static Material boneMaterial{ - get{ - if(_boneMaterial == null){ + public static Material boneMaterial { + get { + if (_boneMaterial == null) { #if UNITY_4_3 _boneMaterial = new Material(Shader.Find("Particles/Alpha Blended")); _boneMaterial.SetColor("_TintColor", new Color(0.4f, 0.4f, 0.4f, 0.25f)); @@ -101,48 +105,43 @@ public class SpineEditorUtilities : AssetPostprocessor { return _boneMaterial; } } + internal static Material _boneMaterial; - public static void Initialize(){ - skeleton = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-skeleton.png"); - nullBone = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-null.png"); - bone = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-bone.png"); - poseBones = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-poseBones.png"); - boneNib = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-boneNib.png"); - slot = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-slot.png"); - skinPlaceholder = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-skinPlaceholder.png"); - image = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-image.png"); - boundingBox = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-boundingBox.png"); - mesh = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-mesh.png"); - skin = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-skinPlaceholder.png"); - skinsRoot = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-skinsRoot.png"); - animation = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-animation.png"); - animationRoot = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-animationRoot.png"); - spine = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-spine.png"); - _event = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-event.png"); - constraintNib = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-constraintNib.png"); - warning = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-warning.png"); - skeletonUtility = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-skeletonUtility.png"); - hingeChain = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-hingeChain.png"); - subMeshRenderer = (Texture2D)AssetDatabase.LoadMainAssetAtPath( SpineEditorUtilities.editorGUIPath + "/icon-subMeshRenderer.png"); - + public static void Initialize () { + skeleton = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-skeleton.png"); + nullBone = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-null.png"); + bone = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-bone.png"); + poseBones = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-poseBones.png"); + boneNib = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-boneNib.png"); + slot = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-slot.png"); + skinPlaceholder = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-skinPlaceholder.png"); + image = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-image.png"); + boundingBox = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-boundingBox.png"); + mesh = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-mesh.png"); + skin = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-skinPlaceholder.png"); + skinsRoot = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-skinsRoot.png"); + animation = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-animation.png"); + animationRoot = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-animationRoot.png"); + spine = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-spine.png"); + _event = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-event.png"); + constraintNib = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-constraintNib.png"); + warning = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-warning.png"); + skeletonUtility = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-skeletonUtility.png"); + hingeChain = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-hingeChain.png"); + subMeshRenderer = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-subMeshRenderer.png"); } - } - - public static string editorPath = ""; public static string editorGUIPath = ""; - static Dictionary skeletonRendererTable; static Dictionary skeletonUtilityBoneTable; - public static float defaultScale = 0.01f; public static float defaultMix = 0.2f; public static string defaultShader = "Spine/Skeleton"; - static SpineEditorUtilities(){ + static SpineEditorUtilities () { DirectoryInfo rootDir = new DirectoryInfo(Application.dataPath); FileInfo[] files = rootDir.GetFiles("SpineEditorUtilities.cs", SearchOption.AllDirectories); editorPath = Path.GetDirectoryName(files[0].FullName.Replace("\\", "/").Replace(Application.dataPath, "Assets")); @@ -159,81 +158,79 @@ public class SpineEditorUtilities : AssetPostprocessor { HierarchyWindowChanged(); } - static void HierarchyWindowChanged(){ + static void HierarchyWindowChanged () { skeletonRendererTable.Clear(); skeletonUtilityBoneTable.Clear(); SkeletonRenderer[] arr = Object.FindObjectsOfType(); - foreach(SkeletonRenderer r in arr) - skeletonRendererTable.Add( r.gameObject.GetInstanceID(), r.gameObject ); + foreach (SkeletonRenderer r in arr) + skeletonRendererTable.Add(r.gameObject.GetInstanceID(), r.gameObject); SkeletonUtilityBone[] boneArr = Object.FindObjectsOfType(); - foreach(SkeletonUtilityBone b in boneArr) + foreach (SkeletonUtilityBone b in boneArr) skeletonUtilityBoneTable.Add(b.gameObject.GetInstanceID(), b); } - static void HierarchyWindowItemOnGUI(int instanceId, Rect selectionRect){ - if(skeletonRendererTable.ContainsKey(instanceId)){ - Rect r = new Rect (selectionRect); + static void HierarchyWindowItemOnGUI (int instanceId, Rect selectionRect) { + if (skeletonRendererTable.ContainsKey(instanceId)) { + Rect r = new Rect(selectionRect); r.x = r.width - 15; r.width = 15; GUI.Label(r, Icons.spine); - } - else if(skeletonUtilityBoneTable.ContainsKey(instanceId)){ - Rect r = new Rect (selectionRect); - r.x -= 26; + } else if (skeletonUtilityBoneTable.ContainsKey(instanceId)) { + Rect r = new Rect(selectionRect); + r.x -= 26; - if(skeletonUtilityBoneTable[instanceId] != null){ - if( skeletonUtilityBoneTable[instanceId].transform.childCount == 0 ) - r.x += 13; + if (skeletonUtilityBoneTable[instanceId] != null) { + if (skeletonUtilityBoneTable[instanceId].transform.childCount == 0) + r.x += 13; - r.y += 2; + r.y += 2; - r.width = 13; - r.height = 13; + r.width = 13; + r.height = 13; - if( skeletonUtilityBoneTable[instanceId].mode == SkeletonUtilityBone.Mode.Follow ){ - GUI.DrawTexture(r, Icons.bone); - } - else{ - GUI.DrawTexture(r, Icons.poseBones); + if (skeletonUtilityBoneTable[instanceId].mode == SkeletonUtilityBone.Mode.Follow) { + GUI.DrawTexture(r, Icons.bone); + } else { + GUI.DrawTexture(r, Icons.poseBones); + } } + } - } - } [MenuItem("Assets/Spine/Ingest")] - static void IngestSpineProjectFromSelection(){ + static void IngestSpineProjectFromSelection () { TextAsset spineJson = null; TextAsset atlasText = null; List spineJsonList = new List(); - foreach(UnityEngine.Object o in Selection.objects){ - if(o.GetType() != typeof(TextAsset)) + foreach (UnityEngine.Object o in Selection.objects) { + if (o.GetType() != typeof(TextAsset)) continue; string fileName = Path.GetFileName(AssetDatabase.GetAssetPath(o)); - if(fileName.EndsWith(".json")) + if (fileName.EndsWith(".json")) spineJson = (TextAsset)o; - else if(fileName.EndsWith(".atlas.txt")) - atlasText = (TextAsset)o; + else if (fileName.EndsWith(".atlas.txt")) + atlasText = (TextAsset)o; } - if(spineJson == null){ + if (spineJson == null) { EditorUtility.DisplayDialog("Error!", "Spine JSON file not found in selection!", "OK"); return; } string primaryName = Path.GetFileNameWithoutExtension(spineJson.name); - string assetPath = Path.GetDirectoryName( AssetDatabase.GetAssetPath(spineJson)); + string assetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(spineJson)); - if(atlasText == null){ + if (atlasText == null) { string atlasPath = assetPath + "/" + primaryName + ".atlas.txt"; atlasText = (TextAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(TextAsset)); } @@ -243,7 +240,7 @@ public class SpineEditorUtilities : AssetPostprocessor { IngestSpineProject(spineJson, atlasAsset); } - static void OnPostprocessAllAssets(string[] imported, string[] deleted, string[] moved, string[] movedFromAssetPaths){ + static void OnPostprocessAllAssets (string[] imported, string[] deleted, string[] moved, string[] movedFromAssetPaths) { //debug // return; @@ -251,20 +248,20 @@ public class SpineEditorUtilities : AssetPostprocessor { System.Array.Sort(imported); - foreach(string str in imported){ - if(Path.GetExtension(str).ToLower() == ".json"){ + foreach (string str in imported) { + if (Path.GetExtension(str).ToLower() == ".json") { TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)); - if(IsSpineJSON(spineJson)){ + if (IsSpineJSON(spineJson)) { - if(sharedAtlas != null){ + if (sharedAtlas != null) { string spinePath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(spineJson)); string atlasPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(sharedAtlas)); - if(spinePath != atlasPath) + if (spinePath != atlasPath) sharedAtlas = null; } SkeletonDataAsset data = AutoIngestSpineProject(spineJson, sharedAtlas); - if(data == null) + if (data == null) continue; sharedAtlas = data.atlasAsset; @@ -273,15 +270,14 @@ public class SpineEditorUtilities : AssetPostprocessor { string dir = Path.GetDirectoryName(Path.GetDirectoryName(AssetDatabase.GetAssetPath(data))); string prefabPath = Path.Combine(dir, data.skeletonJSON.name + ".prefab").Replace("\\", "/"); - if(File.Exists(prefabPath) == false){ + if (File.Exists(prefabPath) == false) { SkeletonAnimation anim = SpawnAnimatedSkeleton(data); PrefabUtility.CreatePrefab(prefabPath, anim.gameObject, ReplacePrefabOptions.ReplaceNameBased); - if(EditorApplication.isPlaying) + if (EditorApplication.isPlaying) GameObject.Destroy(anim.gameObject); else GameObject.DestroyImmediate(anim.gameObject); - } - else{ + } else { } @@ -291,58 +287,54 @@ public class SpineEditorUtilities : AssetPostprocessor { } } - static bool IsSpineJSON(TextAsset asset){ - object obj = Json.Deserialize( new StringReader(asset.text)); - if(obj == null){ + static bool IsSpineJSON (TextAsset asset) { + object obj = Json.Deserialize(new StringReader(asset.text)); + if (obj == null) { Debug.LogError("Is not valid JSON"); return false; } Dictionary root = (Dictionary)obj; - if(!root.ContainsKey("skeleton")) + if (!root.ContainsKey("skeleton")) return false; Dictionary skeletonInfo = (Dictionary)root["skeleton"]; string spineVersion = (string)skeletonInfo["spine"]; - //TODO: reject old versions return true; - } - static SkeletonDataAsset AutoIngestSpineProject(TextAsset spineJson, Object atlasSource = null){ + static SkeletonDataAsset AutoIngestSpineProject (TextAsset spineJson, Object atlasSource = null) { TextAsset atlasText = null; AtlasAsset atlasAsset = null; - if(atlasSource != null){ - if(atlasSource.GetType() == typeof(TextAsset)){ + if (atlasSource != null) { + if (atlasSource.GetType() == typeof(TextAsset)) { atlasText = (TextAsset)atlasSource; - } - else if(atlasSource.GetType() == typeof(AtlasAsset)){ - atlasAsset = (AtlasAsset)atlasSource; - } + } else if (atlasSource.GetType() == typeof(AtlasAsset)) { + atlasAsset = (AtlasAsset)atlasSource; + } } - if(atlasText == null && atlasAsset == null){ + if (atlasText == null && atlasAsset == null) { string primaryName = Path.GetFileNameWithoutExtension(spineJson.name); - string assetPath = Path.GetDirectoryName( AssetDatabase.GetAssetPath(spineJson)); + string assetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(spineJson)); - if(atlasText == null){ + if (atlasText == null) { string atlasPath = assetPath + "/" + primaryName + ".atlas.txt"; atlasText = (TextAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(TextAsset)); - if(atlasText == null){ + if (atlasText == null) { //can't find atlas, likely because using a shared atlas bool abort = !EditorUtility.DisplayDialog("Atlas not Found", "Expecting " + spineJson.name + ".atlas\n" + "Press OK to select Atlas", "OK", "Abort"); - if(abort){ + if (abort) { //do nothing, let it error later - } - else{ - string path = EditorUtility.OpenFilePanel( "Find Atlas source...", Path.GetDirectoryName(Application.dataPath) + "/" + assetPath, "txt"); - if(path != ""){ + } else { + string path = EditorUtility.OpenFilePanel("Find Atlas source...", Path.GetDirectoryName(Application.dataPath) + "/" + assetPath, "txt"); + if (path != "") { path = path.Replace("\\", "/"); path = path.Replace(Application.dataPath.Replace("\\", "/"), "Assets"); atlasText = (TextAsset)AssetDatabase.LoadAssetAtPath(path, typeof(TextAsset)); @@ -353,52 +345,52 @@ public class SpineEditorUtilities : AssetPostprocessor { } } - if(atlasAsset == null) + if (atlasAsset == null) atlasAsset = IngestSpineAtlas(atlasText); return IngestSpineProject(spineJson, atlasAsset); } - static AtlasAsset IngestSpineAtlas(TextAsset atlasText){ - if(atlasText == null){ + static AtlasAsset IngestSpineAtlas (TextAsset atlasText) { + if (atlasText == null) { Debug.LogWarning("Atlas source cannot be null!"); return null; } string primaryName = Path.GetFileNameWithoutExtension(atlasText.name).Replace(".atlas", ""); - string assetPath = Path.GetDirectoryName( AssetDatabase.GetAssetPath(atlasText)); + string assetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(atlasText)); string atlasPath = assetPath + "/" + primaryName + "_Atlas.asset"; AtlasAsset atlasAsset = (AtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAsset)); - if(atlasAsset == null) + if (atlasAsset == null) atlasAsset = AtlasAsset.CreateInstance(); atlasAsset.atlasFile = atlasText; - //strip CR - string atlasStr = atlasText.text; - atlasStr = atlasStr.Replace("\r", ""); + //strip CR + string atlasStr = atlasText.text; + atlasStr = atlasStr.Replace("\r", ""); string[] atlasLines = atlasStr.Split('\n'); List pageFiles = new List(); - for(int i = 0; i < atlasLines.Length-1; i++){ - if(atlasLines[i].Length == 0) - pageFiles.Add(atlasLines[i+1]); + for (int i = 0; i < atlasLines.Length-1; i++) { + if (atlasLines[i].Length == 0) + pageFiles.Add(atlasLines[i + 1]); } atlasAsset.materials = new Material[pageFiles.Count]; - for(int i = 0; i < pageFiles.Count; i++){ + for (int i = 0; i < pageFiles.Count; i++) { string texturePath = assetPath + "/" + pageFiles[i]; Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)); TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath); texImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor; texImporter.mipmapEnabled = false; - texImporter.maxTextureSize = 2048; + texImporter.maxTextureSize = 2048; EditorUtility.SetDirty(texImporter); AssetDatabase.ImportAsset(texturePath); @@ -407,14 +399,14 @@ public class SpineEditorUtilities : AssetPostprocessor { string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]); //because this looks silly - if(pageName == primaryName && pageFiles.Count == 1) + if (pageName == primaryName && pageFiles.Count == 1) pageName = "Material"; string materialPath = assetPath + "/" + primaryName + "_" + pageName + ".mat"; Material mat = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)); - if(mat == null){ - mat = new Material(Shader.Find(defaultShader)); + if (mat == null) { + mat = new Material(Shader.Find(defaultShader)); AssetDatabase.CreateAsset(mat, materialPath); } @@ -426,7 +418,7 @@ public class SpineEditorUtilities : AssetPostprocessor { atlasAsset.materials[i] = mat; } - if(AssetDatabase.GetAssetPath( atlasAsset ) == "") + if (AssetDatabase.GetAssetPath(atlasAsset) == "") AssetDatabase.CreateAsset(atlasAsset, atlasPath); else atlasAsset.Reset(); @@ -436,17 +428,15 @@ public class SpineEditorUtilities : AssetPostprocessor { return (AtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAsset)); } - - static SkeletonDataAsset IngestSpineProject(TextAsset spineJson, AtlasAsset atlasAsset = null){ - + static SkeletonDataAsset IngestSpineProject (TextAsset spineJson, AtlasAsset atlasAsset = null) { string primaryName = Path.GetFileNameWithoutExtension(spineJson.name); - string assetPath = Path.GetDirectoryName( AssetDatabase.GetAssetPath(spineJson)); + string assetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(spineJson)); string filePath = assetPath + "/" + primaryName + "_SkeletonData.asset"; - if(spineJson != null && atlasAsset != null){ + if (spineJson != null && atlasAsset != null) { SkeletonDataAsset skelDataAsset = (SkeletonDataAsset)AssetDatabase.LoadAssetAtPath(filePath, typeof(SkeletonDataAsset)); - if(skelDataAsset == null){ + if (skelDataAsset == null) { skelDataAsset = SkeletonDataAsset.CreateInstance(); skelDataAsset.atlasAsset = atlasAsset; skelDataAsset.skeletonJSON = spineJson; @@ -458,27 +448,23 @@ public class SpineEditorUtilities : AssetPostprocessor { AssetDatabase.CreateAsset(skelDataAsset, filePath); AssetDatabase.SaveAssets(); - } - else{ + } else { skelDataAsset.Reset(); skelDataAsset.GetSkeletonData(true); } return skelDataAsset; - } - else{ + } else { EditorUtility.DisplayDialog("Error!", "Must specify both Spine JSON and Atlas TextAsset", "OK"); return null; } } [MenuItem("Assets/Spine/Spawn")] - static void SpawnAnimatedSkeleton(){ + static void SpawnAnimatedSkeleton () { Object[] arr = Selection.objects; - - foreach(Object o in arr){ - - string guid = AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath( o ) ); + foreach (Object o in arr) { + string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(o)); string skinName = EditorPrefs.GetString(guid + "_lastSkin", ""); SpawnAnimatedSkeleton((SkeletonDataAsset)o, skinName); @@ -487,34 +473,33 @@ public class SpineEditorUtilities : AssetPostprocessor { } [MenuItem("Assets/Spine/Spawn", true)] - static bool ValidateSpawnAnimatedSkeleton(){ + static bool ValidateSpawnAnimatedSkeleton () { Object[] arr = Selection.objects; - if(arr.Length == 0) + if (arr.Length == 0) return false; - foreach(Object o in arr){ - if(o.GetType() != typeof(SkeletonDataAsset)) + foreach (Object o in arr) { + if (o.GetType() != typeof(SkeletonDataAsset)) return false; } return true; } - public static SkeletonAnimation SpawnAnimatedSkeleton(SkeletonDataAsset skeletonDataAsset, string skinName){ + public static SkeletonAnimation SpawnAnimatedSkeleton (SkeletonDataAsset skeletonDataAsset, string skinName) { return SpawnAnimatedSkeleton(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName)); } - public static SkeletonAnimation SpawnAnimatedSkeleton(SkeletonDataAsset skeletonDataAsset, Skin skin = null){ - + public static SkeletonAnimation SpawnAnimatedSkeleton (SkeletonDataAsset skeletonDataAsset, Skin skin = null) { GameObject go = new GameObject(skeletonDataAsset.name.Replace("_SkeletonData", ""), typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation)); SkeletonAnimation anim = go.GetComponent(); anim.skeletonDataAsset = skeletonDataAsset; bool requiresNormals = false; - foreach(Material m in anim.skeletonDataAsset.atlasAsset.materials){ - if(m.shader.name.Contains("Lit")){ + foreach (Material m in anim.skeletonDataAsset.atlasAsset.materials) { + if (m.shader.name.Contains("Lit")) { requiresNormals = true; break; } @@ -524,16 +509,16 @@ public class SpineEditorUtilities : AssetPostprocessor { SkeletonData data = skeletonDataAsset.GetSkeletonData(true); - if(data == null){ - string reloadAtlasPath = AssetDatabase.GetAssetPath( skeletonDataAsset.atlasAsset ); - skeletonDataAsset.atlasAsset = (AtlasAsset)AssetDatabase.LoadAssetAtPath( reloadAtlasPath, typeof(AtlasAsset)); + if (data == null) { + string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAsset); + skeletonDataAsset.atlasAsset = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset)); data = skeletonDataAsset.GetSkeletonData(true); } - if(skin == null) + if (skin == null) skin = data.DefaultSkin; - if(skin == null) + if (skin == null) skin = data.Skins[0]; anim.Reset(); @@ -548,8 +533,4 @@ public class SpineEditorUtilities : AssetPostprocessor { return anim; } - - } - - diff --git a/spine-unity/Assets/spine-unity/SkeletonAnimation.cs b/spine-unity/Assets/spine-unity/SkeletonAnimation.cs index b2b367167..0c4c9a44f 100644 --- a/spine-unity/Assets/spine-unity/SkeletonAnimation.cs +++ b/spine-unity/Assets/spine-unity/SkeletonAnimation.cs @@ -41,20 +41,23 @@ public class SkeletonAnimation : SkeletonRenderer { public bool loop; public Spine.AnimationState state; - public delegate void UpdateBonesDelegate(SkeletonAnimation skeleton); + public delegate void UpdateBonesDelegate (SkeletonAnimation skeleton); + public UpdateBonesDelegate UpdateLocal; public UpdateBonesDelegate UpdateWorld; public UpdateBonesDelegate UpdateComplete; - [SerializeField] - private String _animationName; + private String + _animationName; + public String AnimationName { get { TrackEntry entry = state.GetCurrent(0); return entry == null ? null : entry.Animation.Name; } set { - if (_animationName == value) return; + if (_animationName == value) + return; _animationName = value; if (value == null || value.Length == 0) state.ClearTrack(0); @@ -65,7 +68,8 @@ public class SkeletonAnimation : SkeletonRenderer { public override void Reset () { base.Reset(); - if (!valid) return; + if (!valid) + return; state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData()); if (_animationName != null && _animationName.Length > 0) { @@ -79,7 +83,8 @@ public class SkeletonAnimation : SkeletonRenderer { } public virtual void Update (float deltaTime) { - if (!valid) return; + if (!valid) + return; deltaTime *= timeScale; skeleton.Update(deltaTime); @@ -91,12 +96,12 @@ public class SkeletonAnimation : SkeletonRenderer { skeleton.UpdateWorldTransform(); - if (UpdateWorld != null){ + if (UpdateWorld != null) { UpdateWorld(this); skeleton.UpdateWorldTransform(); } - if (UpdateComplete != null){ + if (UpdateComplete != null) { UpdateComplete(this); } } diff --git a/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs b/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs index 9e92238f1..3e6242dcb 100644 --- a/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs +++ b/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs @@ -87,7 +87,8 @@ public class SkeletonDataAsset : ScriptableObject { stateData = new AnimationStateData(skeletonData); stateData.DefaultMix = defaultMix; for (int i = 0, n = fromAnimation.Length; i < n; i++) { - if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) continue; + if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) + continue; stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]); } diff --git a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs index 06b414658..a483e47e6 100644 --- a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs +++ b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs @@ -39,68 +39,68 @@ using Spine; public static class SkeletonExtensions { - public static void SetColor(this Slot slot, Color color){ + public static void SetColor (this Slot slot, Color color) { slot.A = color.a; slot.R = color.r; slot.G = color.g; slot.B = color.b; } - public static void SetColor(this Slot slot, Color32 color){ + public static void SetColor (this Slot slot, Color32 color) { slot.A = color.a / 255f; slot.R = color.r / 255f; slot.G = color.g / 255f; slot.B = color.b / 255f; } - public static void SetColor(this RegionAttachment attachment, Color color){ + public static void SetColor (this RegionAttachment attachment, Color color) { attachment.A = color.a; attachment.R = color.r; attachment.G = color.g; attachment.B = color.b; } - public static void SetColor(this RegionAttachment attachment, Color32 color){ + public static void SetColor (this RegionAttachment attachment, Color32 color) { attachment.A = color.a / 255f; attachment.R = color.r / 255f; attachment.G = color.g / 255f; attachment.B = color.b / 255f; } - public static void SetColor(this MeshAttachment attachment, Color color){ + public static void SetColor (this MeshAttachment attachment, Color color) { attachment.A = color.a; attachment.R = color.r; attachment.G = color.g; attachment.B = color.b; } - public static void SetColor(this MeshAttachment attachment, Color32 color){ + public static void SetColor (this MeshAttachment attachment, Color32 color) { attachment.A = color.a / 255f; attachment.R = color.r / 255f; attachment.G = color.g / 255f; attachment.B = color.b / 255f; } - public static void SetColor(this SkinnedMeshAttachment attachment, Color color){ + public static void SetColor (this SkinnedMeshAttachment attachment, Color color) { attachment.A = color.a; attachment.R = color.r; attachment.G = color.g; attachment.B = color.b; } - public static void SetColor(this SkinnedMeshAttachment attachment, Color32 color){ + public static void SetColor (this SkinnedMeshAttachment attachment, Color32 color) { attachment.A = color.a / 255f; attachment.R = color.r / 255f; attachment.G = color.g / 255f; attachment.B = color.b / 255f; } - public static void SetPosition(this Bone bone, Vector2 position){ + public static void SetPosition (this Bone bone, Vector2 position) { bone.X = position.x; bone.Y = position.y; } - public static void SetPosition(this Bone bone, Vector3 position){ + public static void SetPosition (this Bone bone, Vector3 position) { bone.X = position.x; bone.Y = position.y; } diff --git a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs index a09838247..7f039b636 100644 --- a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs +++ b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs @@ -38,21 +38,19 @@ using Spine; [ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] public class SkeletonRenderer : MonoBehaviour { - public delegate void SkeletonRendererDelegate(SkeletonRenderer skeletonRenderer); + public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer); + public SkeletonRendererDelegate OnReset; - [System.NonSerialized] public bool valid; [System.NonSerialized] public Skeleton skeleton; - public SkeletonDataAsset skeletonDataAsset; public String initialSkinName; public bool calculateNormals, calculateTangents; public float zSpacing; public bool renderMeshes = true, immutableTriangles; public bool logErrors = false; - private MeshFilter meshFilter; private Mesh mesh, mesh1, mesh2; private bool useMesh1; @@ -66,9 +64,12 @@ public class SkeletonRenderer : MonoBehaviour { private readonly List submeshes = new List(); public virtual void Reset () { - if (meshFilter != null) meshFilter.sharedMesh = null; - if (mesh != null) DestroyImmediate(mesh); - if (renderer != null) renderer.sharedMaterial = null; + if (meshFilter != null) + meshFilter.sharedMesh = null; + if (mesh != null) + DestroyImmediate(mesh); + if (renderer != null) + renderer.sharedMaterial = null; mesh = null; mesh1 = null; mesh2 = null; @@ -83,13 +84,14 @@ public class SkeletonRenderer : MonoBehaviour { valid = false; if (!skeletonDataAsset) { - if(logErrors) + if (logErrors) Debug.LogError("Missing SkeletonData asset.", this); return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); - if (skeletonData == null) return; + if (skeletonData == null) + return; valid = true; meshFilter = GetComponent(); @@ -100,7 +102,8 @@ public class SkeletonRenderer : MonoBehaviour { skeleton = new Skeleton(skeletonData); if (initialSkinName != null && initialSkinName.Length > 0 && initialSkinName != "default") skeleton.SetSkin(initialSkinName); - if(OnReset != null) OnReset(this); + if (OnReset != null) + OnReset(this); } public void Awake () { @@ -116,7 +119,8 @@ public class SkeletonRenderer : MonoBehaviour { } public virtual void LateUpdate () { - if (!valid) return; + if (!valid) + return; // Count vertices and submesh triangles. int vertexCount = 0; int submeshTriangleCount = 0, submeshFirstVertex = 0, submeshStartSlotIndex = 0; @@ -137,19 +141,20 @@ public class SkeletonRenderer : MonoBehaviour { attachmentVertexCount = 4; attachmentTriangleCount = 6; } else { - if (!renderMeshes) continue; + if (!renderMeshes) + continue; if (attachment is MeshAttachment) { MeshAttachment meshAttachment = (MeshAttachment)attachment; rendererObject = meshAttachment.RendererObject; attachmentVertexCount = meshAttachment.vertices.Length >> 1; attachmentTriangleCount = meshAttachment.triangles.Length; } else if (attachment is SkinnedMeshAttachment) { - SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment; - rendererObject = meshAttachment.RendererObject; - attachmentVertexCount = meshAttachment.uvs.Length >> 1; - attachmentTriangleCount = meshAttachment.triangles.Length; - } else - continue; + SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment; + rendererObject = meshAttachment.RendererObject; + attachmentVertexCount = meshAttachment.uvs.Length >> 1; + attachmentTriangleCount = meshAttachment.triangles.Length; + } else + continue; } // Populate submesh when material changes. @@ -217,7 +222,8 @@ public class SkeletonRenderer : MonoBehaviour { color.r = (byte)(r * slot.r * regionAttachment.r * color.a); color.g = (byte)(g * slot.g * regionAttachment.g * color.a); color.b = (byte)(b * slot.b * regionAttachment.b * color.a); - if (slot.data.additiveBlending) color.a = 0; + if (slot.data.additiveBlending) + color.a = 0; colors[vertexIndex] = color; colors[vertexIndex + 1] = color; colors[vertexIndex + 2] = color; @@ -231,18 +237,21 @@ public class SkeletonRenderer : MonoBehaviour { vertexIndex += 4; } else { - if (!renderMeshes) continue; + if (!renderMeshes) + continue; if (attachment is MeshAttachment) { MeshAttachment meshAttachment = (MeshAttachment)attachment; int meshVertexCount = meshAttachment.vertices.Length; - if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount]; + if (tempVertices.Length < meshVertexCount) + tempVertices = new float[meshVertexCount]; meshAttachment.ComputeWorldVertices(slot, tempVertices); color.a = (byte)(a * slot.a * meshAttachment.a); color.r = (byte)(r * slot.r * meshAttachment.r * color.a); color.g = (byte)(g * slot.g * meshAttachment.g * color.a); color.b = (byte)(b * slot.b * meshAttachment.b * color.a); - if (slot.data.additiveBlending) color.a = 0; + if (slot.data.additiveBlending) + color.a = 0; float[] meshUVs = meshAttachment.uvs; float z = i * zSpacing; @@ -252,25 +261,27 @@ public class SkeletonRenderer : MonoBehaviour { uvs[vertexIndex] = new Vector2(meshUVs[ii], meshUVs[ii + 1]); } } else if (attachment is SkinnedMeshAttachment) { - SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment; - int meshVertexCount = meshAttachment.uvs.Length; - if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount]; - meshAttachment.ComputeWorldVertices(slot, tempVertices); + SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment; + int meshVertexCount = meshAttachment.uvs.Length; + if (tempVertices.Length < meshVertexCount) + tempVertices = new float[meshVertexCount]; + meshAttachment.ComputeWorldVertices(slot, tempVertices); - color.a = (byte)(a * slot.a * meshAttachment.a); - color.r = (byte)(r * slot.r * meshAttachment.r * color.a); - color.g = (byte)(g * slot.g * meshAttachment.g * color.a); - color.b = (byte)(b * slot.b * meshAttachment.b * color.a); - if (slot.data.additiveBlending) color.a = 0; + color.a = (byte)(a * slot.a * meshAttachment.a); + color.r = (byte)(r * slot.r * meshAttachment.r * color.a); + color.g = (byte)(g * slot.g * meshAttachment.g * color.a); + color.b = (byte)(b * slot.b * meshAttachment.b * color.a); + if (slot.data.additiveBlending) + color.a = 0; - float[] meshUVs = meshAttachment.uvs; - float z = i * zSpacing; - for (int ii = 0; ii < meshVertexCount; ii += 2, vertexIndex++) { - vertices[vertexIndex] = new Vector3(tempVertices[ii], tempVertices[ii + 1], z); - colors[vertexIndex] = color; - uvs[vertexIndex] = new Vector2(meshUVs[ii], meshUVs[ii + 1]); + float[] meshUVs = meshAttachment.uvs; + float z = i * zSpacing; + for (int ii = 0; ii < meshVertexCount; ii += 2, vertexIndex++) { + vertices[vertexIndex] = new Vector3(tempVertices[ii], tempVertices[ii + 1], z); + colors[vertexIndex] = color; + uvs[vertexIndex] = new Vector2(meshUVs[ii], meshUVs[ii + 1]); + } } - } } } @@ -318,7 +329,7 @@ public class SkeletonRenderer : MonoBehaviour { if (submeshes.Count <= submeshIndex) submeshes.Add(new Submesh()); else if (immutableTriangles) - return; + return; Submesh submesh = submeshes[submeshIndex]; @@ -330,10 +341,10 @@ public class SkeletonRenderer : MonoBehaviour { triangles[i] = 0; submesh.triangleCount = triangleCount; } else if (trianglesCapacity != triangleCount) { - // Reallocate triangles when not the exact size needed. - submesh.triangles = triangles = new int[triangleCount]; - submesh.triangleCount = 0; - } + // Reallocate triangles when not the exact size needed. + submesh.triangles = triangles = new int[triangleCount]; + submesh.triangleCount = 0; + } if (!renderMeshes) { // Use stored triangles if possible. @@ -374,18 +385,18 @@ public class SkeletonRenderer : MonoBehaviour { attachmentVertexCount = meshAttachment.vertices.Length >> 1; attachmentTriangles = meshAttachment.triangles; } else if (attachment is SkinnedMeshAttachment) { - SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment; - attachmentVertexCount = meshAttachment.uvs.Length >> 1; - attachmentTriangles = meshAttachment.triangles; - } else - continue; + SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment; + attachmentVertexCount = meshAttachment.uvs.Length >> 1; + attachmentTriangles = meshAttachment.triangles; + } else + continue; for (int ii = 0, nn = attachmentTriangles.Length; ii < nn; ii++, triangleIndex++) triangles[triangleIndex] = firstVertex + attachmentTriangles[ii]; firstVertex += attachmentVertexCount; } } - #if UNITY_EDITOR +#if UNITY_EDITOR void OnDrawGizmos() { // Make selection easier by drawing a clear gizmo over the skeleton. if (vertices == null) return; @@ -405,7 +416,7 @@ public class SkeletonRenderer : MonoBehaviour { Gizmos.matrix = transform.localToWorldMatrix; Gizmos.DrawCube(gizmosCenter, gizmosSize); } - #endif +#endif } class Submesh { diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs index c0eb706d5..a6950aa84 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs @@ -32,7 +32,6 @@ * Skeleton Utility created by Mitch Thompson * Full irrevocable rights and permissions granted to Esoteric Software *****************************************************************************/ - using UnityEngine; using UnityEditor; using System.Collections; @@ -41,7 +40,7 @@ using Spine; [CustomEditor(typeof(SkeletonUtilityBone)), CanEditMultipleObjects] public class SkeletonUtilityBoneInspector : Editor { - SerializedProperty mode, boneName, zPosition, position, rotation, scale, overrideAlpha, parentReference, flip, flipX; + SerializedProperty mode, boneName, zPosition, position, rotation, scale, overrideAlpha, parentReference, flip, flipX; //multi selected flags bool containsFollows, containsOverrides, multiObject; @@ -51,7 +50,7 @@ public class SkeletonUtilityBoneInspector : Editor { SkeletonUtility skeletonUtility; bool canCreateHingeChain = false; - void OnEnable(){ + void OnEnable () { mode = this.serializedObject.FindProperty("mode"); boneName = this.serializedObject.FindProperty("boneName"); zPosition = this.serializedObject.FindProperty("zPosition"); @@ -60,72 +59,69 @@ public class SkeletonUtilityBoneInspector : Editor { scale = this.serializedObject.FindProperty("scale"); overrideAlpha = this.serializedObject.FindProperty("overrideAlpha"); parentReference = this.serializedObject.FindProperty("parentReference"); - flip = this.serializedObject.FindProperty("flip"); - flipX = this.serializedObject.FindProperty("flipX"); + flip = this.serializedObject.FindProperty("flip"); + flipX = this.serializedObject.FindProperty("flipX"); EvaluateFlags(); - if(utilityBone.valid == false && skeletonUtility != null && skeletonUtility.skeletonRenderer != null){ + if (utilityBone.valid == false && skeletonUtility != null && skeletonUtility.skeletonRenderer != null) { skeletonUtility.skeletonRenderer.Reset(); } canCreateHingeChain = CanCreateHingeChain(); } - /// - /// Evaluates the flags. - /// - void EvaluateFlags(){ + void EvaluateFlags () { utilityBone = (SkeletonUtilityBone)target; skeletonUtility = utilityBone.skeletonUtility; - if(Selection.objects.Length == 1){ + if (Selection.objects.Length == 1) { containsFollows = utilityBone.mode == SkeletonUtilityBone.Mode.Follow; containsOverrides = utilityBone.mode == SkeletonUtilityBone.Mode.Override; - } - else{ + } else { int boneCount = 0; - foreach(Object o in Selection.objects){ - if(o is GameObject){ + foreach (Object o in Selection.objects) { + if (o is GameObject) { GameObject go = (GameObject)o; SkeletonUtilityBone sub = go.GetComponent(); - if(sub != null){ + if (sub != null) { boneCount++; - if(sub.mode == SkeletonUtilityBone.Mode.Follow) + if (sub.mode == SkeletonUtilityBone.Mode.Follow) containsFollows = true; - if(sub.mode == SkeletonUtilityBone.Mode.Override) + if (sub.mode == SkeletonUtilityBone.Mode.Override) containsOverrides = true; } } } - if(boneCount > 1) + if (boneCount > 1) multiObject = true; } } - public override void OnInspectorGUI () - { + public override void OnInspectorGUI () { serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(mode); - if(EditorGUI.EndChangeCheck()){ + if (EditorGUI.EndChangeCheck()) { containsOverrides = mode.enumValueIndex == 1; containsFollows = mode.enumValueIndex == 0; } - EditorGUI.BeginDisabledGroup( multiObject ); + EditorGUI.BeginDisabledGroup(multiObject); { string str = boneName.stringValue; - if(str == "") str = ""; - if(multiObject) str = ""; + if (str == "") + str = ""; + if (multiObject) + str = ""; GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Bone"); - if(GUILayout.Button( str, EditorStyles.popup )){ - BoneSelectorContextMenu( str, ((SkeletonUtilityBone)target).skeletonUtility.skeletonRenderer.skeleton.Bones, "", TargetBoneSelected ); + if (GUILayout.Button(str, EditorStyles.popup)) { + BoneSelectorContextMenu(str, ((SkeletonUtilityBone)target).skeletonUtility.skeletonRenderer.skeleton.Bones, "", TargetBoneSelected); } GUILayout.EndHorizontal(); @@ -136,23 +132,22 @@ public class SkeletonUtilityBoneInspector : Editor { EditorGUILayout.PropertyField(position); EditorGUILayout.PropertyField(rotation); EditorGUILayout.PropertyField(scale); - EditorGUILayout.PropertyField(flip); + EditorGUILayout.PropertyField(flip); - EditorGUI.BeginDisabledGroup( containsFollows ); + EditorGUI.BeginDisabledGroup(containsFollows); { EditorGUILayout.PropertyField(overrideAlpha); EditorGUILayout.PropertyField(parentReference); - EditorGUI.BeginDisabledGroup(multiObject || !flip.boolValue); - { - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(flipX); - if (EditorGUI.EndChangeCheck()) - { - FlipX(flipX.boolValue); - } - } - EditorGUI.EndDisabledGroup(); + EditorGUI.BeginDisabledGroup(multiObject || !flip.boolValue); + { + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(flipX); + if (EditorGUI.EndChangeCheck()) { + FlipX(flipX.boolValue); + } + } + EditorGUI.EndDisabledGroup(); } EditorGUI.EndDisabledGroup(); @@ -161,23 +156,23 @@ public class SkeletonUtilityBoneInspector : Editor { GUILayout.BeginHorizontal(); { - EditorGUI.BeginDisabledGroup( multiObject || !utilityBone.valid || utilityBone.bone == null || utilityBone.bone.Children.Count == 0); + EditorGUI.BeginDisabledGroup(multiObject || !utilityBone.valid || utilityBone.bone == null || utilityBone.bone.Children.Count == 0); { - if(GUILayout.Button(new GUIContent("Add Child", SpineEditorUtilities.Icons.bone), GUILayout.Width(150), GUILayout.Height(24))) - BoneSelectorContextMenu( "", utilityBone.bone.Children, "", SpawnChildBoneSelected); + if (GUILayout.Button(new GUIContent("Add Child", SpineEditorUtilities.Icons.bone), GUILayout.Width(150), GUILayout.Height(24))) + BoneSelectorContextMenu("", utilityBone.bone.Children, "", SpawnChildBoneSelected); } EditorGUI.EndDisabledGroup(); - EditorGUI.BeginDisabledGroup( multiObject || !utilityBone.valid || utilityBone.bone == null || containsOverrides); + EditorGUI.BeginDisabledGroup(multiObject || !utilityBone.valid || utilityBone.bone == null || containsOverrides); { - if(GUILayout.Button(new GUIContent("Add Override", SpineEditorUtilities.Icons.poseBones), GUILayout.Width(150), GUILayout.Height(24))) + if (GUILayout.Button(new GUIContent("Add Override", SpineEditorUtilities.Icons.poseBones), GUILayout.Width(150), GUILayout.Height(24))) SpawnOverride(); } EditorGUI.EndDisabledGroup(); - EditorGUI.BeginDisabledGroup( multiObject || !utilityBone.valid || !canCreateHingeChain ); + EditorGUI.BeginDisabledGroup(multiObject || !utilityBone.valid || !canCreateHingeChain); { - if(GUILayout.Button(new GUIContent("Create Hinge Chain", SpineEditorUtilities.Icons.hingeChain), GUILayout.Width(150), GUILayout.Height(24))) + if (GUILayout.Button(new GUIContent("Create Hinge Chain", SpineEditorUtilities.Icons.hingeChain), GUILayout.Width(150), GUILayout.Height(24))) CreateHingeChain(); } EditorGUI.EndDisabledGroup(); @@ -188,36 +183,32 @@ public class SkeletonUtilityBoneInspector : Editor { serializedObject.ApplyModifiedProperties(); } - void FlipX(bool state) - { - utilityBone.FlipX(state); - if (Application.isPlaying == false) - { - skeletonUtility.skeletonAnimation.LateUpdate(); - } - } + void FlipX (bool state) { + utilityBone.FlipX(state); + if (Application.isPlaying == false) { + skeletonUtility.skeletonAnimation.LateUpdate(); + } + } - void BoneSelectorContextMenu(string current, List bones, string topValue, GenericMenu.MenuFunction2 callback){ + void BoneSelectorContextMenu (string current, List bones, string topValue, GenericMenu.MenuFunction2 callback) { GenericMenu menu = new GenericMenu(); - if(topValue != "") - menu.AddItem( new GUIContent(topValue), current == topValue, callback, null ); + if (topValue != "") + menu.AddItem(new GUIContent(topValue), current == topValue, callback, null); - for(int i = 0; i < bones.Count; i++){ - menu.AddItem( new GUIContent(bones[i].Data.Name), bones[i].Data.Name == current, callback, bones[i] ); + for (int i = 0; i < bones.Count; i++) { + menu.AddItem(new GUIContent(bones[i].Data.Name), bones[i].Data.Name == current, callback, bones[i]); } menu.ShowAsContext(); } - - void TargetBoneSelected(object obj){ - if(obj == null){ + void TargetBoneSelected (object obj) { + if (obj == null) { boneName.stringValue = ""; serializedObject.ApplyModifiedProperties(); - } - else{ + } else { Bone bone = (Bone)obj; boneName.stringValue = bone.Data.Name; serializedObject.ApplyModifiedProperties(); @@ -226,56 +217,59 @@ public class SkeletonUtilityBoneInspector : Editor { } } - void SpawnChildBoneSelected(object obj){ - if(obj == null){ + void SpawnChildBoneSelected (object obj) { + if (obj == null) { //add recursively - foreach(var bone in utilityBone.bone.Children){ - GameObject go = skeletonUtility.SpawnBoneRecursively( bone, utilityBone.transform, utilityBone.mode, utilityBone.position, utilityBone.rotation, utilityBone.scale ); + foreach (var bone in utilityBone.bone.Children) { + GameObject go = skeletonUtility.SpawnBoneRecursively(bone, utilityBone.transform, utilityBone.mode, utilityBone.position, utilityBone.rotation, utilityBone.scale); SkeletonUtilityBone[] newUtilityBones = go.GetComponentsInChildren(); - foreach(SkeletonUtilityBone utilBone in newUtilityBones) + foreach (SkeletonUtilityBone utilBone in newUtilityBones) SkeletonUtilityInspector.AttachIcon(utilBone); } - } - else{ + } else { Bone bone = (Bone)obj; - GameObject go = skeletonUtility.SpawnBone( bone, utilityBone.transform, utilityBone.mode, utilityBone.position, utilityBone.rotation, utilityBone.scale ); + GameObject go = skeletonUtility.SpawnBone(bone, utilityBone.transform, utilityBone.mode, utilityBone.position, utilityBone.rotation, utilityBone.scale); SkeletonUtilityInspector.AttachIcon(go.GetComponent()); Selection.activeGameObject = go; EditorGUIUtility.PingObject(go); } } - void SpawnOverride(){ - GameObject go = skeletonUtility.SpawnBone( utilityBone.bone, utilityBone.transform.parent, SkeletonUtilityBone.Mode.Override, utilityBone.position, utilityBone.rotation, utilityBone.scale); + void SpawnOverride () { + GameObject go = skeletonUtility.SpawnBone(utilityBone.bone, utilityBone.transform.parent, SkeletonUtilityBone.Mode.Override, utilityBone.position, utilityBone.rotation, utilityBone.scale); go.name = go.name + " [Override]"; SkeletonUtilityInspector.AttachIcon(go.GetComponent()); Selection.activeGameObject = go; EditorGUIUtility.PingObject(go); } - bool CanCreateHingeChain(){ - if(utilityBone == null) return false; - if(utilityBone.rigidbody != null) return false; - if(utilityBone.bone != null && utilityBone.bone.Children.Count == 0) return false; + bool CanCreateHingeChain () { + if (utilityBone == null) + return false; + if (utilityBone.rigidbody != null) + return false; + if (utilityBone.bone != null && utilityBone.bone.Children.Count == 0) + return false; Rigidbody[] rigidbodies = utilityBone.GetComponentsInChildren(); - if(rigidbodies.Length > 0) return false; + if (rigidbodies.Length > 0) + return false; return true; } - void CreateHingeChain(){ + void CreateHingeChain () { var utilBoneArr = utilityBone.GetComponentsInChildren(); - foreach(var utilBone in utilBoneArr){ + foreach (var utilBone in utilBoneArr) { AttachRigidbody(utilBone); } utilityBone.rigidbody.isKinematic = true; - foreach(var utilBone in utilBoneArr){ - if(utilBone == utilityBone) + foreach (var utilBone in utilBoneArr) { + if (utilBone == utilityBone) continue; utilBone.mode = SkeletonUtilityBone.Mode.Override; @@ -292,16 +286,15 @@ public class SkeletonUtilityBoneInspector : Editor { } } - void AttachRigidbody(SkeletonUtilityBone utilBone){ - if(utilBone.GetComponent() == null){ - if(utilBone.bone.Data.Length == 0){ + void AttachRigidbody (SkeletonUtilityBone utilBone) { + if (utilBone.GetComponent() == null) { + if (utilBone.bone.Data.Length == 0) { SphereCollider sphere = utilBone.gameObject.AddComponent(); sphere.radius = 0.1f; - } - else{ + } else { float length = utilBone.bone.Data.Length; BoxCollider box = utilBone.gameObject.AddComponent(); - box.size = new Vector3( length, length / 3, 0.2f); + box.size = new Vector3(length, length / 3, 0.2f); box.center = new Vector3(length / 2, 0, 0); } } diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityInspector.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityInspector.cs index 7358c7635..4c6d02d09 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityInspector.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityInspector.cs @@ -32,9 +32,9 @@ * Skeleton Utility created by Mitch Thompson * Full irrevocable rights and permissions granted to Esoteric Software *****************************************************************************/ - using UnityEngine; using UnityEditor; + #if UNITY_4_3 //nothing #else @@ -49,16 +49,16 @@ using System.Reflection; [CustomEditor(typeof(SkeletonUtility))] public class SkeletonUtilityInspector : Editor { - public static void AttachIcon(SkeletonUtilityBone utilityBone){ + public static void AttachIcon (SkeletonUtilityBone utilityBone) { Skeleton skeleton = utilityBone.skeletonUtility.skeletonRenderer.skeleton; Texture2D icon; - if(utilityBone.bone.Data.Length == 0) + if (utilityBone.bone.Data.Length == 0) icon = SpineEditorUtilities.Icons.nullBone; else icon = SpineEditorUtilities.Icons.boneNib; - foreach(IkConstraint c in skeleton.IkConstraints){ - if(c.Target == utilityBone.bone){ + foreach (IkConstraint c in skeleton.IkConstraints) { + if (c.Target == utilityBone.bone) { icon = SpineEditorUtilities.Icons.constraintNib; break; } @@ -66,21 +66,22 @@ public class SkeletonUtilityInspector : Editor { - typeof(EditorGUIUtility).InvokeMember("SetIconForObject", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[2]{ utilityBone.gameObject, icon}); + typeof(EditorGUIUtility).InvokeMember("SetIconForObject", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[2] { + utilityBone.gameObject, + icon + }); } - static void AttachIconsToChildren(Transform root){ - if(root != null){ + static void AttachIconsToChildren (Transform root) { + if (root != null) { var utilityBones = root.GetComponentsInChildren(); - foreach(var utilBone in utilityBones){ + foreach (var utilBone in utilityBones) { AttachIcon(utilBone); } } } - - - static SkeletonUtilityInspector(){ + static SkeletonUtilityInspector () { #if UNITY_4_3 showSlots = false; #else @@ -89,13 +90,10 @@ public class SkeletonUtilityInspector : Editor { } SkeletonUtility skeletonUtility; - Skeleton skeleton; SkeletonRenderer skeletonRenderer; Transform transform; bool isPrefab; - - Dictionary> attachmentTable = new Dictionary>(); @@ -106,13 +104,13 @@ public class SkeletonUtilityInspector : Editor { static AnimBool showSlots; #endif - void OnEnable(){ + void OnEnable () { skeletonUtility = (SkeletonUtility)target; skeletonRenderer = skeletonUtility.GetComponent(); skeleton = skeletonRenderer.skeleton; transform = skeletonRenderer.transform; - if(skeleton == null){ + if (skeleton == null) { skeletonRenderer.Reset(); skeletonRenderer.LateUpdate(); @@ -121,44 +119,44 @@ public class SkeletonUtilityInspector : Editor { UpdateAttachments(); - if(PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab) + if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab) isPrefab = true; } - void OnDestroy(){ + void OnDestroy () { } - void OnSceneGUI(){ - if(skeleton == null){ + void OnSceneGUI () { + if (skeleton == null) { OnEnable(); return; } float flipRotation = skeleton.FlipX ? -1 : 1; - foreach(Bone b in skeleton.Bones){ + foreach (Bone b in skeleton.Bones) { Vector3 vec = transform.TransformPoint(new Vector3(b.WorldX, b.WorldY, 0)); - Quaternion rot = Quaternion.Euler(0,0,b.WorldRotation * flipRotation); - Vector3 forward = transform.TransformDirection( rot * Vector3.right); + Quaternion rot = Quaternion.Euler(0, 0, b.WorldRotation * flipRotation); + Vector3 forward = transform.TransformDirection(rot * Vector3.right); forward *= flipRotation; SpineEditorUtilities.Icons.boneMaterial.SetPass(0); - Graphics.DrawMeshNow( SpineEditorUtilities.Icons.boneMesh, Matrix4x4.TRS ( vec, Quaternion.LookRotation(transform.forward, forward), Vector3.one * b.Data.Length * b.WorldScaleX)); + Graphics.DrawMeshNow(SpineEditorUtilities.Icons.boneMesh, Matrix4x4.TRS(vec, Quaternion.LookRotation(transform.forward, forward), Vector3.one * b.Data.Length * b.WorldScaleX)); } } - void UpdateAttachments(){ + void UpdateAttachments () { attachmentTable = new Dictionary>(); Skin skin = skeleton.Skin; - if(skin == null){ + if (skin == null) { skin = skeletonRenderer.skeletonDataAsset.GetSkeletonData(true).DefaultSkin; } - for(int i = skeleton.Slots.Count-1; i >= 0; i--){ + for (int i = skeleton.Slots.Count-1; i >= 0; i--) { List attachments = new List(); skin.FindAttachmentsForSlot(i, attachments); @@ -166,49 +164,48 @@ public class SkeletonUtilityInspector : Editor { } } - void SpawnHierarchyButton(string label, string tooltip, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca, params GUILayoutOption[] options){ + void SpawnHierarchyButton (string label, string tooltip, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca, params GUILayoutOption[] options) { GUIContent content = new GUIContent(label, tooltip); - if(GUILayout.Button(content, options)){ - if(skeletonUtility.skeletonRenderer == null) + if (GUILayout.Button(content, options)) { + if (skeletonUtility.skeletonRenderer == null) skeletonUtility.skeletonRenderer = skeletonUtility.GetComponent(); - if(skeletonUtility.boneRoot != null){ + if (skeletonUtility.boneRoot != null) { return; } skeletonUtility.SpawnHierarchy(mode, pos, rot, sca); SkeletonUtilityBone[] boneComps = skeletonUtility.GetComponentsInChildren(); - foreach(SkeletonUtilityBone b in boneComps) + foreach (SkeletonUtilityBone b in boneComps) AttachIcon(b); } } - public override void OnInspectorGUI () - { - if(isPrefab){ + public override void OnInspectorGUI () { + if (isPrefab) { GUILayout.Label(new GUIContent("Cannot edit Prefabs", SpineEditorUtilities.Icons.warning)); return; } - skeletonUtility.boneRoot = (Transform)EditorGUILayout.ObjectField( "Bone Root", skeletonUtility.boneRoot, typeof(Transform), true); + skeletonUtility.boneRoot = (Transform)EditorGUILayout.ObjectField("Bone Root", skeletonUtility.boneRoot, typeof(Transform), true); GUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(skeletonUtility.boneRoot != null); { - if(GUILayout.Button(new GUIContent("Spawn Hierarchy", SpineEditorUtilities.Icons.skeleton), GUILayout.Width(150), GUILayout.Height(24))) + if (GUILayout.Button(new GUIContent("Spawn Hierarchy", SpineEditorUtilities.Icons.skeleton), GUILayout.Width(150), GUILayout.Height(24))) SpawnHierarchyContextMenu(); } EditorGUI.EndDisabledGroup(); - if(GUILayout.Button(new GUIContent("Spawn Submeshes", SpineEditorUtilities.Icons.subMeshRenderer), GUILayout.Width(150), GUILayout.Height(24))) + if (GUILayout.Button(new GUIContent("Spawn Submeshes", SpineEditorUtilities.Icons.subMeshRenderer), GUILayout.Width(150), GUILayout.Height(24))) skeletonUtility.SpawnSubRenderers(true); GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); skeleton.FlipX = EditorGUILayout.ToggleLeft("Flip X", skeleton.FlipX); skeleton.FlipY = EditorGUILayout.ToggleLeft("Flip Y", skeleton.FlipY); - if(EditorGUI.EndChangeCheck()){ + if (EditorGUI.EndChangeCheck()) { skeletonRenderer.LateUpdate(); SceneView.RepaintAll(); } @@ -217,9 +214,9 @@ public class SkeletonUtilityInspector : Editor { showSlots = EditorGUILayout.Foldout(showSlots, "Slots"); #else showSlots.target = EditorGUILayout.Foldout(showSlots.target, "Slots"); - if(EditorGUILayout.BeginFadeGroup(showSlots.faded)){ + if (EditorGUILayout.BeginFadeGroup(showSlots.faded)) { #endif - foreach(KeyValuePair> pair in attachmentTable){ + foreach (KeyValuePair> pair in attachmentTable) { Slot slot = pair.Key; @@ -230,8 +227,8 @@ public class SkeletonUtilityInspector : Editor { EditorGUI.BeginChangeCheck(); Color c = EditorGUILayout.ColorField(new Color(slot.R, slot.G, slot.B, slot.A), GUILayout.Width(60)); - if(EditorGUI.EndChangeCheck()){ - slot.SetColor( c ); + if (EditorGUI.EndChangeCheck()) { + slot.SetColor(c); skeletonRenderer.LateUpdate(); } @@ -239,12 +236,11 @@ public class SkeletonUtilityInspector : Editor { - foreach(Attachment attachment in pair.Value){ + foreach (Attachment attachment in pair.Value) { - if(slot.Attachment == attachment){ + if (slot.Attachment == attachment) { GUI.contentColor = Color.white; - } - else{ + } else { GUI.contentColor = Color.grey; } @@ -253,21 +249,20 @@ public class SkeletonUtilityInspector : Editor { Texture2D icon = null; - if(attachment is MeshAttachment || attachment is SkinnedMeshAttachment) + if (attachment is MeshAttachment || attachment is SkinnedMeshAttachment) icon = SpineEditorUtilities.Icons.mesh; else icon = SpineEditorUtilities.Icons.image; - bool swap = EditorGUILayout.ToggleLeft( new GUIContent( attachment.Name, icon ), attachment == slot.Attachment ); + bool swap = EditorGUILayout.ToggleLeft(new GUIContent(attachment.Name, icon), attachment == slot.Attachment); - if(!isAttached && swap){ + if (!isAttached && swap) { slot.Attachment = attachment; skeletonRenderer.LateUpdate(); - } - else if(isAttached && !swap){ - slot.Attachment = null; - skeletonRenderer.LateUpdate(); - } + } else if (isAttached && !swap) { + slot.Attachment = null; + skeletonRenderer.LateUpdate(); + } GUI.contentColor = Color.white; } @@ -277,12 +272,12 @@ public class SkeletonUtilityInspector : Editor { #else } EditorGUILayout.EndFadeGroup(); - if(showSlots.isAnimating) + if (showSlots.isAnimating) Repaint(); #endif } - void SpawnHierarchyContextMenu(){ + void SpawnHierarchyContextMenu () { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Follow"), false, SpawnFollowHierarchy); @@ -294,23 +289,23 @@ public class SkeletonUtilityInspector : Editor { menu.ShowAsContext(); } - void SpawnFollowHierarchy(){ - Selection.activeGameObject = skeletonUtility.SpawnHierarchy( SkeletonUtilityBone.Mode.Follow, true, true, true ); - AttachIconsToChildren( skeletonUtility.boneRoot ); + void SpawnFollowHierarchy () { + Selection.activeGameObject = skeletonUtility.SpawnHierarchy(SkeletonUtilityBone.Mode.Follow, true, true, true); + AttachIconsToChildren(skeletonUtility.boneRoot); } - void SpawnFollowHierarchyRootOnly(){ - Selection.activeGameObject = skeletonUtility.SpawnRoot( SkeletonUtilityBone.Mode.Follow, true, true, true ); - AttachIconsToChildren( skeletonUtility.boneRoot ); + void SpawnFollowHierarchyRootOnly () { + Selection.activeGameObject = skeletonUtility.SpawnRoot(SkeletonUtilityBone.Mode.Follow, true, true, true); + AttachIconsToChildren(skeletonUtility.boneRoot); } - void SpawnOverrideHierarchy(){ - Selection.activeGameObject = skeletonUtility.SpawnHierarchy( SkeletonUtilityBone.Mode.Override, true, true, true ); - AttachIconsToChildren( skeletonUtility.boneRoot ); + void SpawnOverrideHierarchy () { + Selection.activeGameObject = skeletonUtility.SpawnHierarchy(SkeletonUtilityBone.Mode.Override, true, true, true); + AttachIconsToChildren(skeletonUtility.boneRoot); } - void SpawnOverrideHierarchyRootOnly(){ - Selection.activeGameObject = skeletonUtility.SpawnRoot( SkeletonUtilityBone.Mode.Override, true, true, true ); - AttachIconsToChildren( skeletonUtility.boneRoot ); + void SpawnOverrideHierarchyRootOnly () { + Selection.activeGameObject = skeletonUtility.SpawnRoot(SkeletonUtilityBone.Mode.Override, true, true, true); + AttachIconsToChildren(skeletonUtility.boneRoot); } } diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs index 77caf627e..c274c3db6 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs @@ -42,7 +42,7 @@ using Spine; [ExecuteInEditMode] public class SkeletonUtility : MonoBehaviour { - public static T GetInParent(Transform origin) where T : Component{ + public static T GetInParent (Transform origin) where T : Component { #if UNITY_4_3 Transform parent = origin.parent; while(parent.GetComponent() == null){ @@ -58,18 +58,19 @@ public class SkeletonUtility : MonoBehaviour { } - public delegate void SkeletonUtilityDelegate(); + public delegate void SkeletonUtilityDelegate (); + public event SkeletonUtilityDelegate OnReset; public Transform boneRoot; - void Update(){ - if(boneRoot != null && skeletonRenderer.skeleton != null){ + void Update () { + if (boneRoot != null && skeletonRenderer.skeleton != null) { Vector3 flipScale = Vector3.one; - if(skeletonRenderer.skeleton.FlipX) + if (skeletonRenderer.skeleton.FlipX) flipScale.x = -1; - if(skeletonRenderer.skeleton.FlipY) + if (skeletonRenderer.skeleton.FlipY) flipScale.y = -1; boneRoot.localScale = flipScale; @@ -78,35 +79,31 @@ public class SkeletonUtility : MonoBehaviour { [HideInInspector] public SkeletonRenderer skeletonRenderer; - [HideInInspector] public SkeletonAnimation skeletonAnimation; - [System.NonSerialized] public List utilityBones = new List(); - [System.NonSerialized] public List utilityConstraints = new List(); // Dictionary utilityBoneTable; - protected bool hasTransformBones; protected bool hasUtilityConstraints; protected bool needToReprocessBones; - void OnEnable(){ - if(skeletonRenderer == null){ + void OnEnable () { + if (skeletonRenderer == null) { skeletonRenderer = GetComponent(); } - if(skeletonAnimation == null){ + if (skeletonAnimation == null) { skeletonAnimation = GetComponent(); } skeletonRenderer.OnReset -= HandleRendererReset; skeletonRenderer.OnReset += HandleRendererReset; - if(skeletonAnimation != null){ + if (skeletonAnimation != null) { skeletonAnimation.UpdateLocal -= UpdateLocal; skeletonAnimation.UpdateLocal += UpdateLocal; } @@ -115,147 +112,144 @@ public class SkeletonUtility : MonoBehaviour { CollectBones(); } - void Start(){ + void Start () { //recollect because order of operations failure when switching between game mode and edit mode... // CollectBones(); } - - - void OnDisable(){ + void OnDisable () { skeletonRenderer.OnReset -= HandleRendererReset; - if(skeletonAnimation != null){ + if (skeletonAnimation != null) { skeletonAnimation.UpdateLocal -= UpdateLocal; skeletonAnimation.UpdateWorld -= UpdateWorld; skeletonAnimation.UpdateComplete -= UpdateComplete; } } - void HandleRendererReset(SkeletonRenderer r){ - if(OnReset != null) + void HandleRendererReset (SkeletonRenderer r) { + if (OnReset != null) OnReset(); CollectBones(); } - public void RegisterBone(SkeletonUtilityBone bone){ - if(utilityBones.Contains(bone)) + public void RegisterBone (SkeletonUtilityBone bone) { + if (utilityBones.Contains(bone)) return; - else{ + else { utilityBones.Add(bone); needToReprocessBones = true; } } - public void UnregisterBone(SkeletonUtilityBone bone){ + public void UnregisterBone (SkeletonUtilityBone bone) { utilityBones.Remove(bone); } - public void RegisterConstraint(SkeletonUtilityConstraint constraint){ + public void RegisterConstraint (SkeletonUtilityConstraint constraint) { - if(utilityConstraints.Contains(constraint)) + if (utilityConstraints.Contains(constraint)) return; - else{ + else { utilityConstraints.Add(constraint); needToReprocessBones = true; } } - public void UnregisterConstraint(SkeletonUtilityConstraint constraint){ + public void UnregisterConstraint (SkeletonUtilityConstraint constraint) { utilityConstraints.Remove(constraint); } - public void CollectBones(){ - if(skeletonRenderer.skeleton == null) + public void CollectBones () { + if (skeletonRenderer.skeleton == null) return; - if(boneRoot != null){ + if (boneRoot != null) { List constraintTargetNames = new List(); - foreach(IkConstraint c in skeletonRenderer.skeleton.IkConstraints){ + foreach (IkConstraint c in skeletonRenderer.skeleton.IkConstraints) { constraintTargetNames.Add(c.Target.Data.Name); } - foreach(var b in utilityBones){ - if(b.bone == null){ + foreach (var b in utilityBones) { + if (b.bone == null) { return; } - if(b.mode == SkeletonUtilityBone.Mode.Override){ + if (b.mode == SkeletonUtilityBone.Mode.Override) { hasTransformBones = true; } - if(constraintTargetNames.Contains( b.bone.Data.Name )){ + if (constraintTargetNames.Contains(b.bone.Data.Name)) { hasUtilityConstraints = true; } } - if(utilityConstraints.Count > 0) + if (utilityConstraints.Count > 0) hasUtilityConstraints = true; - if(skeletonAnimation != null){ + if (skeletonAnimation != null) { skeletonAnimation.UpdateWorld -= UpdateWorld; skeletonAnimation.UpdateComplete -= UpdateComplete; - if(hasTransformBones || hasUtilityConstraints){ + if (hasTransformBones || hasUtilityConstraints) { skeletonAnimation.UpdateWorld += UpdateWorld; } - if(hasUtilityConstraints){ + if (hasUtilityConstraints) { skeletonAnimation.UpdateComplete += UpdateComplete; } } needToReprocessBones = false; - } - else{ + } else { utilityBones.Clear(); utilityConstraints.Clear(); } } - void UpdateLocal(SkeletonAnimation anim){ + void UpdateLocal (SkeletonAnimation anim) { - if(needToReprocessBones) + if (needToReprocessBones) CollectBones(); - if(utilityBones == null) + if (utilityBones == null) return; - foreach(SkeletonUtilityBone b in utilityBones){ + foreach (SkeletonUtilityBone b in utilityBones) { b.transformLerpComplete = false; } UpdateAllBones(); } - void UpdateWorld(SkeletonAnimation anim){ + void UpdateWorld (SkeletonAnimation anim) { UpdateAllBones(); - foreach(SkeletonUtilityConstraint c in utilityConstraints) + foreach (SkeletonUtilityConstraint c in utilityConstraints) c.DoUpdate(); } - void UpdateComplete(SkeletonAnimation anim){ + void UpdateComplete (SkeletonAnimation anim) { UpdateAllBones(); } - void UpdateAllBones(){ - if(boneRoot == null){ + void UpdateAllBones () { + if (boneRoot == null) { CollectBones(); } - if(utilityBones == null) + if (utilityBones == null) return; - foreach(SkeletonUtilityBone b in utilityBones){ + foreach (SkeletonUtilityBone b in utilityBones) { b.DoUpdate(); } } - public Transform GetBoneRoot(){ - if(boneRoot != null) + public Transform GetBoneRoot () { + if (boneRoot != null) return boneRoot; boneRoot = new GameObject("SkeletonUtility-Root").transform; @@ -267,18 +261,18 @@ public class SkeletonUtility : MonoBehaviour { return boneRoot; } - public GameObject SpawnRoot(SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca){ + public GameObject SpawnRoot (SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) { GetBoneRoot(); Skeleton skeleton = this.skeletonRenderer.skeleton; - GameObject go = SpawnBone( skeleton.RootBone, boneRoot, mode, pos, rot, sca ); + GameObject go = SpawnBone(skeleton.RootBone, boneRoot, mode, pos, rot, sca); CollectBones(); return go; } - public GameObject SpawnHierarchy(SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca){ + public GameObject SpawnHierarchy (SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) { GetBoneRoot(); Skeleton skeleton = this.skeletonRenderer.skeleton; @@ -290,17 +284,17 @@ public class SkeletonUtility : MonoBehaviour { return go; } - public GameObject SpawnBoneRecursively(Bone bone, Transform parent, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca){ + public GameObject SpawnBoneRecursively (Bone bone, Transform parent, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) { GameObject go = SpawnBone(bone, parent, mode, pos, rot, sca); - foreach(Bone child in bone.Children){ + foreach (Bone child in bone.Children) { SpawnBoneRecursively(child, go.transform, mode, pos, rot, sca); } return go; } - public GameObject SpawnBone(Bone bone, Transform parent, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca){ + public GameObject SpawnBone (Bone bone, Transform parent, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca) { GameObject go = new GameObject(bone.Data.Name); go.transform.parent = parent; @@ -316,11 +310,11 @@ public class SkeletonUtility : MonoBehaviour { b.boneName = bone.Data.Name; b.valid = true; - if(mode == SkeletonUtilityBone.Mode.Override){ - if(rot) + if (mode == SkeletonUtilityBone.Mode.Override) { + if (rot) go.transform.localRotation = Quaternion.Euler(0, 0, b.bone.RotationIK); - if(pos) + if (pos) go.transform.localPosition = new Vector3(b.bone.X, b.bone.Y, 0); go.transform.localScale = new Vector3(b.bone.scaleX, b.bone.scaleY, 0); @@ -329,10 +323,10 @@ public class SkeletonUtility : MonoBehaviour { return go; } - public void SpawnSubRenderers(bool disablePrimaryRenderer){ + public void SpawnSubRenderers (bool disablePrimaryRenderer) { int submeshCount = GetComponent().sharedMesh.subMeshCount; - for(int i = 0; i < submeshCount; i++){ + for (int i = 0; i < submeshCount; i++) { GameObject go = new GameObject("Submesh " + i, typeof(MeshFilter), typeof(MeshRenderer)); go.transform.parent = transform; go.transform.localPosition = Vector3.zero; @@ -342,11 +336,11 @@ public class SkeletonUtility : MonoBehaviour { SkeletonUtilitySubmeshRenderer s = go.AddComponent(); s.sortingOrder = i * 10; s.submeshIndex = i; - s.Initialize( renderer ); + s.Initialize(renderer); s.Update(); } - if(disablePrimaryRenderer) + if (disablePrimaryRenderer) renderer.enabled = false; } } diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs index ca0b56bde..99c561499 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs @@ -44,52 +44,49 @@ using Spine; [AddComponentMenu("Spine/SkeletonUtilityBone")] public class SkeletonUtilityBone : MonoBehaviour { - public enum Mode { Follow, Override } + public enum Mode { + Follow, + Override + } [System.NonSerialized] public bool valid; - [System.NonSerialized] public SkeletonUtility skeletonUtility; - [System.NonSerialized] public Bone bone; - public Mode mode; - public bool zPosition = true; public bool position; public bool rotation; public bool scale; - public bool flip; - public bool flipX; - + public bool flip; + public bool flipX; [Range(0f,1f)] public float overrideAlpha = 1; /// If a bone isn't set, boneName is used to find the bone. public String boneName; - public Transform parentReference; - [HideInInspector] public bool transformLerpComplete; - protected Transform cachedTransform; protected Transform skeletonTransform; - public bool NonUniformScaleWarning{ - get{ + public bool NonUniformScaleWarning { + get { return nonUniformScaleWarning; } } + private bool nonUniformScaleWarning; public void Reset () { bone = null; cachedTransform = transform; valid = skeletonUtility != null && skeletonUtility.skeletonRenderer != null && skeletonUtility.skeletonRenderer.valid; - if (!valid) return; + if (!valid) + return; skeletonTransform = skeletonUtility.transform; skeletonUtility.OnReset -= HandleOnReset; @@ -98,10 +95,10 @@ public class SkeletonUtilityBone : MonoBehaviour { DoUpdate(); } - void OnEnable(){ + void OnEnable () { skeletonUtility = SkeletonUtility.GetInParent(transform); - if(skeletonUtility == null) + if (skeletonUtility == null) return; skeletonUtility.RegisterBone(this); @@ -109,13 +106,12 @@ public class SkeletonUtilityBone : MonoBehaviour { skeletonUtility.OnReset += HandleOnReset; } - void HandleOnReset () - { - Reset (); + void HandleOnReset () { + Reset(); } - void OnDisable(){ - if(skeletonUtility != null){ + void OnDisable () { + if (skeletonUtility != null) { skeletonUtility.OnReset -= HandleOnReset; skeletonUtility.UnregisterBone(this); @@ -132,7 +128,8 @@ public class SkeletonUtilityBone : MonoBehaviour { Spine.Skeleton skeleton = skeletonUtility.skeletonRenderer.skeleton; if (bone == null) { - if (boneName == null || boneName.Length == 0) return; + if (boneName == null || boneName.Length == 0) + return; bone = skeleton.FindBone(boneName); if (bone == null) { Debug.LogError("Bone not found: " + boneName, this); @@ -144,170 +141,153 @@ public class SkeletonUtilityBone : MonoBehaviour { float skeletonFlipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f; - float flipCompensation = 0; - if (flip && (flipX || ( flipX != bone.flipX)) && bone.parent != null) - { - flipCompensation = bone.parent.WorldRotation * -2; - } + float flipCompensation = 0; + if (flip && (flipX || (flipX != bone.flipX)) && bone.parent != null) { + flipCompensation = bone.parent.WorldRotation * -2; + } - if(mode == Mode.Follow){ - if (flip) - { - flipX = bone.flipX; - } + if (mode == Mode.Follow) { + if (flip) { + flipX = bone.flipX; + } - if(position){ + if (position) { cachedTransform.localPosition = new Vector3(bone.x, bone.y, 0); } - if(rotation){ + if (rotation) { - if(bone.Data.InheritRotation){ - if (bone.FlipX) - { - cachedTransform.localRotation = Quaternion.Euler(0, 180, bone.rotationIK - flipCompensation); - } - else { - cachedTransform.localRotation = Quaternion.Euler(0,0,bone.rotationIK); - } - } - else{ + if (bone.Data.InheritRotation) { + if (bone.FlipX) { + cachedTransform.localRotation = Quaternion.Euler(0, 180, bone.rotationIK - flipCompensation); + } else { + cachedTransform.localRotation = Quaternion.Euler(0, 0, bone.rotationIK); + } + } else { Vector3 euler = skeletonTransform.rotation.eulerAngles; - cachedTransform.rotation = Quaternion.Euler(euler.x, euler.y, skeletonTransform.rotation.eulerAngles.z + (bone.worldRotation * skeletonFlipRotation) ); + cachedTransform.rotation = Quaternion.Euler(euler.x, euler.y, skeletonTransform.rotation.eulerAngles.z + (bone.worldRotation * skeletonFlipRotation)); } } - if(scale){ + if (scale) { cachedTransform.localScale = new Vector3(bone.scaleX, bone.scaleY, 1); nonUniformScaleWarning = (bone.scaleX != bone.scaleY); } - } - else if(mode == Mode.Override){ + } else if (mode == Mode.Override) { - if(transformLerpComplete) - return; + if (transformLerpComplete) + return; - if(parentReference == null){ - if(position){ - bone.x = Mathf.Lerp(bone.x, cachedTransform.localPosition.x, overrideAlpha); - bone.y = Mathf.Lerp(bone.y, cachedTransform.localPosition.y, overrideAlpha); - } + if (parentReference == null) { + if (position) { + bone.x = Mathf.Lerp(bone.x, cachedTransform.localPosition.x, overrideAlpha); + bone.y = Mathf.Lerp(bone.y, cachedTransform.localPosition.y, overrideAlpha); + } - if(rotation){ - float angle = Mathf.LerpAngle(bone.Rotation, cachedTransform.localRotation.eulerAngles.z, overrideAlpha) + flipCompensation; + if (rotation) { + float angle = Mathf.LerpAngle(bone.Rotation, cachedTransform.localRotation.eulerAngles.z, overrideAlpha) + flipCompensation; - if (flip) { - if ((!flipX && bone.flipX)) - { - angle -= flipCompensation; - } + if (flip) { + if ((!flipX && bone.flipX)) { + angle -= flipCompensation; + } - //TODO fix this... - if (angle >= 360) - angle -= 360; - else if (angle <= -360) - angle += 360; - } + //TODO fix this... + if (angle >= 360) + angle -= 360; + else if (angle <= -360) + angle += 360; + } - bone.Rotation = angle; - } + bone.Rotation = angle; + } - if(scale){ - bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); - bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); + if (scale) { + bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); + bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); - nonUniformScaleWarning = (bone.scaleX != bone.scaleY); - } + nonUniformScaleWarning = (bone.scaleX != bone.scaleY); + } - if (flip) - { - bone.flipX = flipX; - } - } - else{ + if (flip) { + bone.flipX = flipX; + } + } else { - if (transformLerpComplete) - return; + if (transformLerpComplete) + return; - if(position){ - Vector3 pos = parentReference.InverseTransformPoint(cachedTransform.position); - bone.x = Mathf.Lerp(bone.x, pos.x, overrideAlpha); - bone.y = Mathf.Lerp(bone.y, pos.y, overrideAlpha); - } + if (position) { + Vector3 pos = parentReference.InverseTransformPoint(cachedTransform.position); + bone.x = Mathf.Lerp(bone.x, pos.x, overrideAlpha); + bone.y = Mathf.Lerp(bone.y, pos.y, overrideAlpha); + } - if(rotation){ - float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(flipX ? Vector3.forward * -1 : Vector3.forward, parentReference.InverseTransformDirection(cachedTransform.up)).eulerAngles.z, overrideAlpha) + flipCompensation; + if (rotation) { + float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(flipX ? Vector3.forward * -1 : Vector3.forward, parentReference.InverseTransformDirection(cachedTransform.up)).eulerAngles.z, overrideAlpha) + flipCompensation; - if (flip) - { - if ((!flipX && bone.flipX)) - { - angle -= flipCompensation; - } + if (flip) { + if ((!flipX && bone.flipX)) { + angle -= flipCompensation; + } - //TODO fix this... - if (angle >= 360) - angle -= 360; - else if (angle <= -360) - angle += 360; - } + //TODO fix this... + if (angle >= 360) + angle -= 360; + else if (angle <= -360) + angle += 360; + } - bone.Rotation = angle; - } + bone.Rotation = angle; + } - //TODO: Something about this - if(scale){ - bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); - bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); + //TODO: Something about this + if (scale) { + bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); + bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); - nonUniformScaleWarning = (bone.scaleX != bone.scaleY); + nonUniformScaleWarning = (bone.scaleX != bone.scaleY); + } + + if (flip) { + bone.flipX = flipX; + } + } - if (flip) - { - bone.flipX = flipX; - } - - } - - transformLerpComplete = true; - } + transformLerpComplete = true; + } } - public void FlipX(bool state) - { - if (state != flipX) - { - flipX = state; - if (flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) > 90) - { - skeletonUtility.skeletonAnimation.LateUpdate(); - return; - } - else if (!flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) < 90) - { - skeletonUtility.skeletonAnimation.LateUpdate(); - return; - } - } + public void FlipX (bool state) { + if (state != flipX) { + flipX = state; + if (flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) > 90) { + skeletonUtility.skeletonAnimation.LateUpdate(); + return; + } else if (!flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) < 90) { + skeletonUtility.skeletonAnimation.LateUpdate(); + return; + } + } - bone.FlipX = state; - transform.RotateAround(transform.position, skeletonUtility.transform.up, 180); - Vector3 euler = transform.localRotation.eulerAngles; - euler.x = 0; - euler.y = bone.FlipX ? 180 : 0; - transform.localRotation = Quaternion.Euler(euler); - } + bone.FlipX = state; + transform.RotateAround(transform.position, skeletonUtility.transform.up, 180); + Vector3 euler = transform.localRotation.eulerAngles; + euler.x = 0; + euler.y = bone.FlipX ? 180 : 0; + transform.localRotation = Quaternion.Euler(euler); + } - void OnDrawGizmos(){ - if(NonUniformScaleWarning){ - Gizmos.DrawIcon(transform.position + new Vector3(0,0.128f,0), "icon-warning"); + void OnDrawGizmos () { + if (NonUniformScaleWarning) { + Gizmos.DrawIcon(transform.position + new Vector3(0, 0.128f, 0), "icon-warning"); } } } \ No newline at end of file diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityConstraint.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityConstraint.cs index 767707bdb..3be62228c 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityConstraint.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityConstraint.cs @@ -8,15 +8,15 @@ public abstract class SkeletonUtilityConstraint : MonoBehaviour { protected SkeletonUtilityBone utilBone; protected SkeletonUtility skeletonUtility; - protected virtual void OnEnable(){ + protected virtual void OnEnable () { utilBone = GetComponent(); skeletonUtility = SkeletonUtility.GetInParent(transform); skeletonUtility.RegisterConstraint(this); } - protected virtual void OnDisable(){ + protected virtual void OnDisable () { skeletonUtility.UnregisterConstraint(this); } - public abstract void DoUpdate(); + public abstract void DoUpdate (); } diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityEyeConstraint.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityEyeConstraint.cs index 07203faef..6aefded5a 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityEyeConstraint.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityEyeConstraint.cs @@ -7,41 +7,36 @@ public class SkeletonUtilityEyeConstraint : SkeletonUtilityConstraint { public float radius = 0.5f; public Transform target; public Vector3 targetPosition; - public float speed = 10; - Vector3[] origins; Vector3 centerPoint; - protected override void OnEnable () - { - if(!Application.isPlaying) + protected override void OnEnable () { + if (!Application.isPlaying) return; - base.OnEnable (); + base.OnEnable(); - Bounds centerBounds = new Bounds( eyes[0].localPosition, Vector3.zero ); + Bounds centerBounds = new Bounds(eyes[0].localPosition, Vector3.zero); origins = new Vector3[eyes.Length]; - for(int i = 0; i < eyes.Length; i++){ + for (int i = 0; i < eyes.Length; i++) { origins[i] = eyes[i].localPosition; - centerBounds.Encapsulate( origins[i] ); + centerBounds.Encapsulate(origins[i]); } centerPoint = centerBounds.center; } - protected override void OnDisable () - { - if(!Application.isPlaying) + protected override void OnDisable () { + if (!Application.isPlaying) return; - base.OnDisable (); + base.OnDisable(); } - public override void DoUpdate () - { + public override void DoUpdate () { - if(target != null) + if (target != null) targetPosition = target.position; Vector3 goal = targetPosition; @@ -49,10 +44,10 @@ public class SkeletonUtilityEyeConstraint : SkeletonUtilityConstraint { Vector3 center = transform.TransformPoint(centerPoint); Vector3 dir = goal - center; - if(dir.magnitude > 1) + if (dir.magnitude > 1) dir.Normalize(); - for(int i = 0; i < eyes.Length; i++){ + for (int i = 0; i < eyes.Length; i++) { center = transform.TransformPoint(origins[i]); eyes[i].position = Vector3.MoveTowards(eyes[i].position, center + (dir * radius), speed * Time.deltaTime); } diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityGroundConstraint.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityGroundConstraint.cs index 3efa51e96..b9608e9bc 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityGroundConstraint.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityGroundConstraint.cs @@ -34,71 +34,63 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint { Vector3 rayOrigin; - Vector3 rayDir = new Vector3(0,-1,0); + Vector3 rayDir = new Vector3(0, -1, 0); float hitY; float lastHitY; - protected override void OnEnable () - { - base.OnEnable (); + protected override void OnEnable () { + base.OnEnable(); } - protected override void OnDisable () - { - base.OnDisable (); + protected override void OnDisable () { + base.OnDisable(); } - public override void DoUpdate() - { - rayOrigin = transform.position + new Vector3(castOffset,castDistance,0); + public override void DoUpdate () { + rayOrigin = transform.position + new Vector3(castOffset, castDistance, 0); hitY = float.MinValue; - if(use2D){ + if (use2D) { RaycastHit2D hit; - if(useRadius){ + if (useRadius) { #if UNITY_4_3 //NOTE: Unity 4.3.x does not have CircleCast hit = Physics2D.Raycast(rayOrigin , rayDir, castDistance + groundOffset, groundMask); #else - hit = Physics2D.CircleCast( rayOrigin, castRadius, rayDir, castDistance + groundOffset, groundMask ); + hit = Physics2D.CircleCast(rayOrigin, castRadius, rayDir, castDistance + groundOffset, groundMask); #endif - } - else{ - hit = Physics2D.Raycast(rayOrigin , rayDir, castDistance + groundOffset, groundMask); + } else { + hit = Physics2D.Raycast(rayOrigin, rayDir, castDistance + groundOffset, groundMask); } - if(hit.collider != null){ + if (hit.collider != null) { hitY = hit.point.y + groundOffset; - if(Application.isPlaying){ - hitY = Mathf.MoveTowards( lastHitY, hitY, adjustSpeed * Time.deltaTime ); + if (Application.isPlaying) { + hitY = Mathf.MoveTowards(lastHitY, hitY, adjustSpeed * Time.deltaTime); } + } else { + if (Application.isPlaying) + hitY = Mathf.MoveTowards(lastHitY, transform.position.y, adjustSpeed * Time.deltaTime); } - else{ - if(Application.isPlaying) - hitY = Mathf.MoveTowards( lastHitY, transform.position.y, adjustSpeed * Time.deltaTime ); - } - } - else{ + } else { RaycastHit hit; bool validHit = false; - if(useRadius){ - validHit = Physics.SphereCast( rayOrigin, castRadius, rayDir, out hit, castDistance + groundOffset, groundMask ); - } - else{ - validHit = Physics.Raycast( rayOrigin, rayDir, out hit, castDistance + groundOffset, groundMask); + if (useRadius) { + validHit = Physics.SphereCast(rayOrigin, castRadius, rayDir, out hit, castDistance + groundOffset, groundMask); + } else { + validHit = Physics.Raycast(rayOrigin, rayDir, out hit, castDistance + groundOffset, groundMask); } - if(validHit){ + if (validHit) { hitY = hit.point.y + groundOffset; - if(Application.isPlaying){ - hitY = Mathf.MoveTowards( lastHitY, hitY, adjustSpeed * Time.deltaTime ); + if (Application.isPlaying) { + hitY = Mathf.MoveTowards(lastHitY, hitY, adjustSpeed * Time.deltaTime); } - } - else{ - if(Application.isPlaying) - hitY = Mathf.MoveTowards( lastHitY, transform.position.y, adjustSpeed * Time.deltaTime ); + } else { + if (Application.isPlaying) + hitY = Mathf.MoveTowards(lastHitY, transform.position.y, adjustSpeed * Time.deltaTime); } } @@ -110,21 +102,18 @@ public class SkeletonUtilityGroundConstraint : SkeletonUtilityConstraint { utilBone.bone.Y = transform.localPosition.y; lastHitY = hitY; - } - void OnDrawGizmos(){ + void OnDrawGizmos () { Vector3 hitEnd = rayOrigin + (rayDir * Mathf.Min(castDistance, rayOrigin.y - hitY)); Vector3 clearEnd = rayOrigin + (rayDir * castDistance); Gizmos.DrawLine(rayOrigin, hitEnd); - if(useRadius){ + if (useRadius) { Gizmos.DrawLine(new Vector3(hitEnd.x - castRadius, hitEnd.y - groundOffset, hitEnd.z), new Vector3(hitEnd.x + castRadius, hitEnd.y - groundOffset, hitEnd.z)); Gizmos.DrawLine(new Vector3(clearEnd.x - castRadius, clearEnd.y, clearEnd.z), new Vector3(clearEnd.x + castRadius, clearEnd.y, clearEnd.z)); } - - Gizmos.color = Color.red; Gizmos.DrawLine(hitEnd, clearEnd); } diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityKinematicShadow.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityKinematicShadow.cs index 917eb5a45..c088353f2 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityKinematicShadow.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityKinematicShadow.cs @@ -3,15 +3,13 @@ using System.Collections; using System.Collections.Generic; public class SkeletonUtilityKinematicShadow : MonoBehaviour { - public bool hideShadow = true; - Dictionary shadowTable; GameObject shadowRoot; - void Start(){ + void Start () { shadowRoot = (GameObject)Instantiate(gameObject); - if(hideShadow) + if (hideShadow) shadowRoot.hideFlags = HideFlags.HideInHierarchy; shadowRoot.transform.parent = transform.root; @@ -28,20 +26,20 @@ public class SkeletonUtilityKinematicShadow : MonoBehaviour { shadowRoot.transform.localScale = Vector3.one; var shadowJoints = shadowRoot.GetComponentsInChildren(); - foreach(Joint j in shadowJoints){ + foreach (Joint j in shadowJoints) { j.connectedAnchor *= scale; } var joints = GetComponentsInChildren(); - foreach(var j in joints) + foreach (var j in joints) Destroy(j); var rbs = GetComponentsInChildren(); - foreach(var rb in rbs) + foreach (var rb in rbs) Destroy(rb); var colliders = GetComponentsInChildren(); - foreach(var c in colliders) + foreach (var c in colliders) Destroy(c); @@ -50,30 +48,30 @@ public class SkeletonUtilityKinematicShadow : MonoBehaviour { var bones = GetComponentsInChildren(); //build bone lookup - foreach(var b in bones){ - if(b.gameObject == gameObject) + foreach (var b in bones) { + if (b.gameObject == gameObject) continue; - foreach(var sb in shadowBones){ - if(sb.rigidbody == null) + foreach (var sb in shadowBones) { + if (sb.rigidbody == null) continue; - if(sb.boneName == b.boneName){ - shadowTable.Add( sb.transform, b.transform ); + if (sb.boneName == b.boneName) { + shadowTable.Add(sb.transform, b.transform); break; } } } - foreach(var b in shadowBones) + foreach (var b in shadowBones) Destroy(b); } - void FixedUpdate(){ - shadowRoot.rigidbody.MovePosition( transform.position ); - shadowRoot.rigidbody.MoveRotation( transform.rotation ); + void FixedUpdate () { + shadowRoot.rigidbody.MovePosition(transform.position); + shadowRoot.rigidbody.MoveRotation(transform.rotation); - foreach(var pair in shadowTable){ + foreach (var pair in shadowTable) { pair.Value.localPosition = pair.Key.localPosition; pair.Value.localRotation = pair.Key.localRotation; } diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilitySubmeshRenderer.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilitySubmeshRenderer.cs index f6a2e682b..fc8867e6b 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilitySubmeshRenderer.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilitySubmeshRenderer.cs @@ -3,46 +3,42 @@ using System.Collections; [ExecuteInEditMode] public class SkeletonUtilitySubmeshRenderer : MonoBehaviour { - public Renderer parentRenderer; - [System.NonSerialized] public Mesh mesh; - public int submeshIndex = 0; public int sortingOrder = 0; public int sortingLayerID = 0; - public Material hiddenPassMaterial; Renderer cachedRenderer; MeshFilter filter; Material[] sharedMaterials; MeshFilter parentFilter; - void Awake(){ + void Awake () { cachedRenderer = renderer; sharedMaterials = cachedRenderer.sharedMaterials; filter = GetComponent(); - if(parentRenderer != null) - Initialize( parentRenderer ); + if (parentRenderer != null) + Initialize(parentRenderer); } - void OnEnable(){ + void OnEnable () { parentRenderer = transform.parent.GetComponent(); parentRenderer.GetComponent().OnReset += HandleSkeletonReset; } - void OnDisable(){ + void OnDisable () { parentRenderer.GetComponent().OnReset -= HandleSkeletonReset; } - void HandleSkeletonReset(SkeletonRenderer r){ - if(parentRenderer != null) + void HandleSkeletonReset (SkeletonRenderer r) { + if (parentRenderer != null) Initialize(parentRenderer); } - public void Initialize(Renderer parentRenderer){ + public void Initialize (Renderer parentRenderer) { this.parentRenderer = parentRenderer; parentFilter = parentRenderer.GetComponent(); mesh = parentFilter.sharedMesh; @@ -50,52 +46,50 @@ public class SkeletonUtilitySubmeshRenderer : MonoBehaviour { Debug.Log("Mesh: " + mesh); } - public void Update(){ - if(mesh == null || mesh != parentFilter.sharedMesh){ + public void Update () { + if (mesh == null || mesh != parentFilter.sharedMesh) { mesh = parentFilter.sharedMesh; filter.sharedMesh = mesh; } - if(cachedRenderer == null) + if (cachedRenderer == null) cachedRenderer = renderer; - if(mesh == null || submeshIndex > mesh.subMeshCount - 1){ + if (mesh == null || submeshIndex > mesh.subMeshCount - 1) { cachedRenderer.enabled = false; return; - } - else{ + } else { renderer.enabled = true; } bool changed = false; - if(sharedMaterials.Length != parentRenderer.sharedMaterials.Length){ + if (sharedMaterials.Length != parentRenderer.sharedMaterials.Length) { sharedMaterials = parentRenderer.sharedMaterials; changed = true; } - for(int i = 0; i < renderer.sharedMaterials.Length; i++){ - if(i == submeshIndex) + for (int i = 0; i < renderer.sharedMaterials.Length; i++) { + if (i == submeshIndex) continue; - if(sharedMaterials[i] != hiddenPassMaterial){ + if (sharedMaterials[i] != hiddenPassMaterial) { sharedMaterials[i] = hiddenPassMaterial; changed = true; } } - if(sharedMaterials[submeshIndex] != parentRenderer.sharedMaterials[submeshIndex]){ + if (sharedMaterials[submeshIndex] != parentRenderer.sharedMaterials[submeshIndex]) { sharedMaterials[submeshIndex] = parentRenderer.sharedMaterials[submeshIndex]; changed = true; } - if(changed){ + if (changed) { cachedRenderer.sharedMaterials = sharedMaterials; } - cachedRenderer.sortingLayerID = sortingLayerID; cachedRenderer.sortingOrder = sortingOrder; } diff --git a/spine-unity/Spine.mdpolicy b/spine-unity/Spine.mdpolicy new file mode 100644 index 000000000..8af1049a9 --- /dev/null +++ b/spine-unity/Spine.mdpolicy @@ -0,0 +1,28 @@ + + + + 130 + 3 + 3 + + + False + False + False + EndOfLine + EndOfLine + EndOfLine + EndOfLine + EndOfLine + EndOfLine + EndOfLine + EndOfLine + SameLine + False + True + False + False + 1 + 1 + + \ No newline at end of file