• Editor
  • Spine + Unity + 2d toolkit WIP

Hi folks.

I'm working on Spine integration with 2d toolkit. I've started simple and just replaced built-in atlas to tk2d one. So it's pretty close to current Unity runtime (in fact, I took code from it). You can find the package it in the attachments.

Warning: I tested only in Unity 4 so there might be some problems in Unity 3.x
Warning: You must have 2d toolkit in order to use that package
b Warning:[/b] You must have Spine-C# runtime in order to use that package

Also, there are two bugs: one in C#-runtime and another one in Unity-runtime. Both related to rotated sprites.

1) In RegionAttachment.cs, lines 70-73 (where 'region.rotate' check is placed)

If you're using rotated attachments then you got wrong polygon size. I guess that's because of typo with 'height and width' in that check. So I fixed that and it's working! Not sure I properly fixed it. You can see that file in the attachments.

2) In SkeletonComponent.cs, lines 130-133 (setting uv's for rotated polys)

Rotating polys got incorrect uv's. You just want to swap uv's between two vertices, other should look the same. You can find that fix in my Spine-tk2d package in tk2dSpineSkeleton component.

I hope this will help. Thank you for such great framework. Looking forward to make it better! 🙂

Related Discussions
...

Thanks for this! 🙂 I've looked over 2D Toolkit a bit and I've had some discussion with Unikron, but I haven't yet dived in. This sounds like it will help a lot, thank you! :clap:

Assets/Spine-tk2d/Code/tk2dSpineAttachmentLoader.cs(54,24): error CS0029: Cannot implicitly convert type tk2dSpriteDefinition.FlipMode' tobool'

Am i doing something wrong?

wagenheimer escreveu

Assets/Spine-tk2d/Code/tk2dSpineAttachmentLoader.cs(54,24): error CS0029: Cannot implicitly convert type tk2dSpriteDefinition.FlipMode' tobool'

Am i doing something wrong?

It's my fault, sorry. I'm using an old version of 2d toolkit. Will fix that soon and upload new version.

Ok, here is the fix for the latest 2d toolkit version. Hope this will work.

Hi aviktorov,

This is what I want! Thank you!

but, I tried latest Spine runtime and install v1.1 package, report compile error.

Assets/Spine-tk2d/Code/tk2dSpineAttachmentLoader.cs(62,28): error CS1061: Type Spine.RegionAttachment' does not contain a definition forRegion' and no extension method Region' of typeSpine.RegionAttachment' could be found (are you missing a using directive or an assembly reference?)

maybe Official runtime change (2 days ago) causes problem.

First of all thanks for this! Should be very useful.

I've imported your unitypackage (as well as the C#-runtime) and everything seems to compile fine. However, when I open the included Spine-tk2d example project, I don't see anything. I have the "spineboy tk2d Skeleton" object in the hierarchy and it appears to have all the necessary components, but nothing shows up in the scene or game view.

It's also writing these errors to the log without pointing to the file that causing the exception:

!IsFinite(outDistanceForSort)
!IsFinite(outDistanceAlongView)

The examples from the original C#-runtime work just fine.

I've seen something like that when Unity was freaking out. A restart fixed it. Unity likes to crash. 🙁

Nice!

FYI - we're cutting over to this implementation now - we were previously using a tk2d port of ngomes32's runtime - which used tk2dsprites for each bone rather than a single mesh. Single mesh definitely much more performant based on my preliminary comparisons.

Here's example showing flip, scale, tint and anim blending (we've currently got a bug where the walk/idle animations have a Y translation in em).

http://screencast.com/t/G8OCeywtkO

Made a few tweaks

1.) Color data seemed to be ignored by this runtime, Think this is as easy as setting mesh.colors from slot.color * skeleton.data for each vertex. Let me know if I'm mistaken here, possible I missed it

2.) Skeleton shader was complaining that the shader wanted normals but the mesh wasn't providing them. Not sure why I ran into this and you didn't. I added a recalc normals call in the update function() - there's probably a more efficient way to do this.

3.) Added a animation complete delegate for better scriptability - it'd be nice if they got raised anytime an animation completed irrespective of whether or not it was a loop. Think that requires some changes to generic runtime tho

https://gist.github.com/jmcguirk/5483536

ah also - one more bit of feedback. I Think you want to take the Tk2DSpriteCollection rather than the naked Tk2DSpriteCollectionData. That enables the Tk2D sprite framework to indirect to a different set of data (like for instance if you're using 1x/2x resolution skins)

Thank you guys for feedback!

At first, sorry for late reply, I took part in Ludum Dare jam competition so I wasn't able to add some tweaks and features for that framework. You can play our game here: http://www.ludumdare.com/compo/ludum-dare-26/?action=preview&uid=22220

Probably, I need to create a git repository and work over it so you guys will be able to do pull requests and have latest release all the time.

Still have errors stated above is there a fix for 2DTK. Thanks

6 dias depois

Hey guys!

Good news, version 1.2 is here!

Change log:

  • Fixed all compiler errors, now it's compatible with the latest c# runtime
  • Added skeleton & slot color support for generated mesh
  • tk2dSpriteCollection is used in the SkeletonDataAsset instead of tk2dSpriteCollectionData

Feel free to write any feedback and feature requests.

Roadmap:

  • Multi atlas support
  • FlipMode.TPackerCW support
  • Split skeleton and animation to separate components

Version 1.2 compile error.

error:
Assets/Spine-tk2d/Code/tk2dSpineSkeleton.cs(98,50): error CS1061: Type Spine.RegionAttachment' does not contain a definition forComputeVertices' and no extension method ComputeVertices' of typeSpine.RegionAttachment' could be found (are you missing a using directive or an assembly reference?)

Fix it please 🙂

sagolboss escreveu

Version 1.2 compile error.

error:
Assets/Spine-tk2d/Code/tk2dSpineSkeleton.cs(98,50): error CS1061: Type Spine.RegionAttachment' does not contain a definition forComputeVertices' and no extension method ComputeVertices' of typeSpine.RegionAttachment' could be found (are you missing a using directive or an assembly reference?)

Fix it please 🙂

Are you using latest spine-charp runtime?

Yeah update colliders are back. 🙂

Nice work, thanks a lot. 🙂
I'd like to point out that the OnMouseDown of the example file doesn't seem to work for me. When you change the skeleton.animationName string, it doesn't reset the state.Time to 0 properly before the Update() of the SpineBoy kicks in.

I basically added 'skeleton.state.Time = 0' after that line to fix it for now. It seems as if the Update() of the Spineboy is processed before the one in tk2dSpineSkeleton.cs (I'm new to Unity :S)

Edit: Nevermind, there's a few ways to get around that small issue, one being the Script Execution Order.

aviktorov escreveu
sagolboss escreveu

Version 1.2 compile error.

error:
Assets/Spine-tk2d/Code/tk2dSpineSkeleton.cs(98,50): error CS1061: Type Spine.RegionAttachment' does not contain a definition forComputeVertices' and no extension method ComputeVertices' of typeSpine.RegionAttachment' could be found (are you missing a using directive or an assembly reference?)

Fix it please 🙂

Are you using latest spine-charp runtime?

Oh! I'm sorry. My mistake.
Thank you!!