Adapters

An Adapter determines two things:

1. How external Unity components like MeshRenderer, TMP_Text, and Colliders affect gameObjects using SizeType.ComponentSize.

2. How layout results will modify those a gameObject's components and localScale.

Flexalon has built-in default adapters. These are used if FlexalonObject.UserDefaultAdapter is set.

TextMeshPro.TMP_TextThe component size is the size of the text. The RectTransform is resized to fit the text. The gameObject scale is set to the Scale value of the FlexalonObject.
RectTransformThe component size is the size of the rectTransform. The gameObject scale is set to the Scale value of the FlexalonObject.
MeshRendererThe component size is the size of the renderer local bounds. The gameObject is scaled uniformly where possible.
SpriteRendererThe component size is the size of the sprite. The gameObject is scaled uniformly, depth scale is 1.
ColliderThe component size is the size of the collider local bounds, which depends on the type of collider. The gameObject is scaled uniformly where possible.
Collider2DThe component size is the size of the collider local bounds, which depends on the type of collider. The gameObject is scaled uniformly where possible, depth scale is 1.
Canvas (UGUI)Non-root canvases or canvases with renderMode set to World Space are adapted as RectTransforms. Root canvas sizes are never modified, since they are controlled by Unity.
Image (UGUI)If only one axis is set to Component size, it is set to the aspect ratio of the sprite. The gameObject scale is set to the Scale value of the FlexalonObject.

Additionally, Flexalon comes with built-in adapter components that you add to your GameObject to override the default adapter, or inspiration from to create your own adapters.

FlexalonAspectRatioAdapterSet a custom aspect ratio that Flexalon should maintain for this object when you only set one or two of the size values.
FlexalonColliderAdapterBy default, Flexalon scales the GameObject to make the the collider match the size of the layout. This component instead resizes the collider itself to match the size of the Flexalon object.

Implementing a custom adapter

To provide your own sizing strategy, implement Adapter and call:

Flexalon­.GetOrCreateNode(gameObject)­.SetAdapter(yourObject);

Measure

Bounds Measure(FlexalonNode node, Vector3 size, Vector3 min, Vector3 max);

nodeThe node to be measured.
sizeThe size set by the Flexalon Object Component. Update any axis set to SizeType.Component.
minThe minimum set by the Flexalon Object Component. Ensure the returned bounds fit in min/max.
maxThe maximum set by the Flexalon Object Component. Ensure the returned bounds fit in min/max.
Return ValueThe measured size to use in layout.

Call node.GetSizeType() to determine which axes should be adjusted. Return a bounds that includes the passed in size and the auto size.

UpdateSize

Vector3 UpdateSize(FlexalonNode node);

nodeThe node to be sized.
sizeThe final layout size.
Return ValueThe desired scale of this gameObject.

Update components on this node's gameObject to match the passed in size. Do not adjust the Transform component. Return what the gameObject's scale should be in local space.