[ExecuteInEditMode]
public class Positioner : MonoBehaviour
{
/// <summary>
/// The background target widget.
/// </summary>
[SerializeField]
private UIWidget _target;
[SerializeField]
private Vector2 _relativePosition;
private void Update ()
{
if (_target != null) {
Vector3 bottomLeft = _target.worldCorners [0];
Vector3 topRight = _target.worldCorners [2];
float width = topRight.x - bottomLeft.x;
float height = topRight.y - bottomLeft.y;
// Calculate world coordinates relative to bottom left of target widget.
Vector3 worldPos
= new Vector3
( bottomLeft.x + width * _relativePosition.x,
bottomLeft.y + height * _relativePosition.y,
0.0f);
this.transform.position = worldPos;
}
}
}