62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
namespace Wizard;
|
|
|
|
public class CenteringUIWidget : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Transform _offset;
|
|
|
|
[SerializeField]
|
|
private bool _isCenteringHorizontal = true;
|
|
|
|
[SerializeField]
|
|
private bool _isCenteringVertical;
|
|
|
|
private static Bounds GetBounds(UIWidget widget, Transform parent)
|
|
{
|
|
if (!(widget is UILabel))
|
|
{
|
|
return widget.CalculateBounds(parent);
|
|
}
|
|
UILabel uILabel = (UILabel)widget;
|
|
NGUIText.Alignment alignment = uILabel.alignment;
|
|
if (alignment == NGUIText.Alignment.Automatic)
|
|
{
|
|
switch (uILabel.pivot)
|
|
{
|
|
case UIWidget.Pivot.TopLeft:
|
|
case UIWidget.Pivot.Left:
|
|
case UIWidget.Pivot.BottomLeft:
|
|
alignment = NGUIText.Alignment.Left;
|
|
break;
|
|
case UIWidget.Pivot.Top:
|
|
case UIWidget.Pivot.Center:
|
|
case UIWidget.Pivot.Bottom:
|
|
alignment = NGUIText.Alignment.Center;
|
|
break;
|
|
case UIWidget.Pivot.TopRight:
|
|
case UIWidget.Pivot.Right:
|
|
case UIWidget.Pivot.BottomRight:
|
|
alignment = NGUIText.Alignment.Right;
|
|
break;
|
|
}
|
|
}
|
|
Bounds result = uILabel.CalculateBounds(parent);
|
|
Vector3 vector = new Vector3(uILabel.printedSize.x, uILabel.printedSize.y, 0f);
|
|
switch (alignment)
|
|
{
|
|
case NGUIText.Alignment.Left:
|
|
result.max = result.min + vector;
|
|
break;
|
|
case NGUIText.Alignment.Center:
|
|
result.size = vector;
|
|
break;
|
|
case NGUIText.Alignment.Right:
|
|
result.min = result.max - vector;
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
}
|