• Showcase
  • Bounding Box + Unity UI RectTransform for text

I'm working with an artist to make a silly airport game. I wanted the Artist to be able to decide where text should go without dealing with Unity so, we compromised and I got the Artist to make a BoundingBox within Spine for the location of the text.

The Unity script I made will then search for all bounding box and try to make its size and position with a UI object and match them up. Pretty nifty, saves me a lot of time. It works changing resolution too, iterate all the objects and do it again.

Related Discussions
...

For context, I do "approximate" the location in the Editor before the game is run but this is 100% not needed. I do it to remind myself where things should be.

Here are some code snippets of the useful parts.

1: Find all the BoundingBoxAttachment in a SkeletonUtility
2: Pass the Attachment to my own method to copy its location

	void FindBoundingBoxThenProrcess()
	{
		var skeleton = m_skeletonUtility.Skeleton;
		int slotCount = skeleton.Slots.Count;
		var skin = skeleton.Skin;
		if (skeleton.Skin == null)
			skin = skeleton.Data.DefaultSkin;

		for (int i = 0; i < slotCount; i++) {
			var slot = skeleton.Slots.Items[i];
		
				var slotAttachments = new List<Spine.Skin.SkinEntry>();
				int slotIndex = skeleton.Data.FindSlot(slot.Data.Name).Index;
				skin.GetAttachments(slotIndex, slotAttachments);

				var boundingBoxes = new List<Spine.BoundingBoxAttachment>();
				foreach (var skinEntry in slotAttachments) {
					var boundingBoxAttachment = skinEntry.Attachment as Spine.BoundingBoxAttachment;
					if (boundingBoxAttachment != null)
					{
						var boneTarget = m_skeletonUtility.boneComponents.FirstOrDefault( x => x.bone == slot.Bone);
						var polygon = SkeletonUtility.AddBoundingBoxGameObject(boneTarget.bone.Skeleton, skin.Name, slot.Data.Name, boundingBoxAttachment.Name, boneTarget.transform);
						polygon.gameObject.name = slot.Data.Name;

						if(polygon.name.StartsWith("BUTT_"))
							AddButton(polygon, polygon.name.Replace("BUTT_", ""));
						else if(polygon.name.StartsWith("AREA_"))
							AddArea(polygon, polygon.name.Replace("AREA_", ""));
					}
				}
		}
	}

Very cool idea, thanks for sharing!

@_twistedhorror Very cool indeed! Thanks for sharing the code as well, much appreciated!