- Modifié
Unity UI scaling with Spine objects.
Hi guys,
I have a set of Spine exports which I am using in Unity with their UI system with SkeletonGraphic components, which for the most part work well.
The issue I am having is that the UI anchors don't seem to alter Spine elements in a similar fashion to built in Unity UI elements. An example of this is that if I have a 16:9 full screen object and I want this object to be anchored to 100% of the screen, when I switch to another resolution, say 18:9, the graphics do not resize to fit the screen size and will have a portion off the screen.
Is there a way I can get SkeletonGraphic components to respect the settings of the RectTransform anchors for the object they are attached to? Positional anchoring works without issue in respect to the RectTransform but all scaling is ignored.
Thanks,
John
An example can be seen here.
On the left is a Spine SkeletonGraphic anchored within the screen boundary, on the right is a Unity UI Image, anchored to a similar portion of the screen.
At 16:9 the top of the Spine object is within the screen and the image on the right is within the screen as can be seen below:
At 18:9 the top of the Spine object has left the top of the screen while the Unity UI Image on the right has maintained its position and scale to fall within the screen as can be seen below:
This functionality is essential to handling multiple devices (e.g. phones at 18:9 against tablets at 4:3 for example). If anyone has any input on how I could achieve the same effect with Spine objects I would appreciate it.
Thanks.
You are correct. The skeleton's scale is unaffected by the RectTransform of the GameObject. Mostly because a skeleton doesn't actually have a fixed scale, unlike sprites. This is the same behavior you'd run into if you were to put a multi-GameObject character using Unity's own system, or other skeletal animation systems.
In the current implementation, we make no assumptions as to how the skeleton scale relates or behaves relative to the RectTransform's dimensions.
An additional component/script could probably be written to do this scaling. The script can have a base RectTransform size, watch the dimensions, then calculate and apply the appropriate scale for the skeleton. It would need to keep the RectTransform pivot in mind to align it properly with the pivot of the skeleton as it scales.
I just stumbled upon this issue myself.
Has anything shifted in this department? I would really love our animator to be able to pump out more menu animation using spine and it would be awesome if this would be handled natively.
There is now an issue ticket here:
https://github.com/EsotericSoftware/spine-runtimes/issues/1640
Thanks to ggzerosum, there is now a component shared on the forum/github:
[Script] Make SkeletonGraphic respecting RectTranform
https://github.com/ggzerosum/SpineUtility/tree/master/RespectRectTransform
While we are still planning to support it natively in SkeletonGraphic, I'm sure this will help a lot of users in the meantime.
This feature has just been implemented and pushed to the 4.1 and 4.2-beta branches. We're sorry it took us longer to get to this issue ticket.
From the changelog:
SkeletonGraphic
now supports automatic scaling based on itsRectTransform
bounds. Automatic scaling can be enabled by setting the addedLayout Scale Mode
Inspector property to eitherWidth Controls Height
,Height Controls Width
,FitInParent
orEnvelopeParent
. It is set toNone
by default to keep previous behaviour and avoid breaking existing projects. To modify the reference layout bounds, hit the additionalEdit Layout Bounds
toggle button to switch into edit mode, adjust the bounds or hitMatch RectTransform with Mesh
, and hit the button again when done adjusting. The skeleton will now be scaled accordingly to fit the reference layout bounds to the object'sRectTransform
.
New 4.1 and 4.2-beta unitypackages are available for download here as usual:
https://esotericsoftware.com/spine-unity-download
- Modifié
i found it thx