Here's SkeletonGraphic
: https://gist.github.com/pharan/d06c771a696fbf7ec733
(EDIT: This SkeltonGraphic is the old implementation. The latest official implementation is now a Module and part of the official runtime when you download it.)
This is a naive port and merging of SkeletonRenderer and SkeletonAnimation into one script that works in Canvases, sans the incompatible features like submesh separators. You use it like the other Unity UI components and the scripting API is similar to SkeletonAnimation. I haven't ripped out the part of the rendering code that does submeshes. Ideally, it should outright reject skeletons that use multiple materials since it's just not compatible.
The single script should work by itself.
- This hasn't been thoroughly tested yet but I figured it'd tide you over for basic cases. It does work. The inspector works. It animates, updates. You can set
freeze
to true
in case you want to stop it from updating the mesh, but don't want to clear the mesh inside CanvasRenderer.
- You can't use skeletons that use more than 1 material (this is a Canvas/CanvasRenderer limitation, afaik.
SetMaterials(material, int)
doesn't seem to work or make sense. no documentation on it either.)
- It has a few editor conveniences but no Instantiate shortcut from Project view. But all you usually need to do is assign it a SkeletonDataAsset and it'll start working.
- It uses the
color
property that comes with the Graphic class. Haven't seen if it interacts with the grouped alpha tweens that canvas elements have.
- It also uses the Reference Pixels Per Unit scale set on your Canvas's CanvasScaler.
- It doesn't use the Rect on the RectTransform since that actually involves having static bounds which Spine.Skeletons simply don't have. You can resize via the transform scale, and alignment is done by moving the RectTransform pivot.
- It also doesn't have support for Masking.
I'm busy these days so I don't think I'll have time to work on this much more anytime soon.
Masking involve some stuff about the stencil buffer and possibly some shader stuff. That's research I can't get into right now.
But if anyone wants to take a whack at switching it over to MaskableGraphic or whatever other features you need, feel free.
11 Feb 2016 2:11 am
SkeletonGraphic is going to get a new cleaner (temporarily less performant) implementation soon with compatibility with UnityEngine.UI Mask and RectMask2D.
Did some testing. Shader needed to check the stencil buffer for 1. But the MaskableGraphic class needs to do some other things to change each graphic's material/shader depending on whether or not it's a child of a Mask.
22 Feb 2016 12:03 pm
Solgryn wrote
A couple of things about the new runtime, when I updated (downloaded a new copy from the github), it said this field doesnt exist
Loading Image
I just commented it out and haven't noticed it affecting anything in my game but just thought I'd tell you.
Solgryn wrote@[削除済み]
Running on Unity 5.3.1p3.
@[削除済み]
The compilation error isn't making much sense since you're using 5.3.
It's supposed to be accessing this property, which DOES exist as it says right there in the docs: http://docs.unity3d.com/ScriptReference/UI.Graphic-raycastTarget.html
I'll try to look into this.
22 Feb 2016 12:10 pm
A note to everyone else, SkeletonGraphic is now part of the official runtime under Modules. You can find a sample scene in the Examples folder.
If you don't need it or it causes you problems, you can delete the whole folder named SkeletonGraphic without affecting anything else in your project.
I've already tested it some and squashed a few bugs here and there. And the instantiation shortcut is also already in the project menu if you right-click on a SkeletonDataAsset. Feel free to use it and report any problems.
It's only ever so slightly slower than how SkeletonAnimation does things. The difference is small enough that any slowdown you have is much more likely because of UnityEngine's current UI performance issues.
It has some small API differences.
- You'll have to access its Skeleton and AnimationState through SkeletonGraphic.Skeleton and SkeletonGraphic.AnimationState properties, unlike
SkeletonAnimation
which lets you access the fields directly.
- Its Skeleton color is controlled by SkeletonGraphic.color (inherited from UnityEngine.UI.Graphic.color) so changing the Skeleton's color directly will yield unpredictable results. But this means (at least it should) that you can use it with grouped and animated alpha fading in UI elements.
- As it was with the first implementation of SkeletonGraphic, because of the limitations of the UI system, you can't use skeletons that require more than one Unity Material. It just doesn't work.
- You can right-click on the component in the Inspector and you have the option to resize the RectTransform's rect to fit the currently rendered skeleton in the editor. Graphic design-wise, this is usually not a good idea since the skeleton's mesh usually has a bunch of transparent and uneven stuff sticking out of it, but it does make for a good starting point in some cases.
I'll be making a how-to-use video for it soonish.