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 adapters for:

TextMeshPro.TMP_Text The component size is the size of the text. The RectTransform is resized to fit the text. The gameObject scale is set to 1.
RectTransform The component size is the size of the rectTransform. The gameObject is scaled uniformly where possible, depth scale is 1.
MeshRenderer The component size is the size of the renderer local bounds. The gameObject is scaled uniformly where possible.
SpriteRenderer The component size is the size of the sprite. The gameObject is scaled uniformly, depth scale is 1.
Collider The component size is the size of the collider local bounds, which depends on the type of collider. The gameObject is scaled uniformly where possible.
Collider2D The 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.

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);

node The node to be measured.
size The size set by the Flexalon Object Component. Update any axis set to SizeType.Component.
min The minimum set by the Flexalon Object Component. Ensure the returned bounds fit in min/max.
max The maximum set by the Flexalon Object Component. Ensure the returned bounds fit in min/max.
Return Value The 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);

node The node to be sized.
size The final layout size.
Return Value The 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.