选中UI,点击UI锚点对齐即可,脚本需要放到 Editor目录下
using UnityEngine;
using UnityEditor;
public class MonkeyUITools
{
[MenuItem("Monkey/UI锚点对齐")]
static void Adjust()
{
foreach (GameObject gameObject in Selection.gameObjects)
{
adjustRectTransform(gameObject);
}
}
static void adjustRectTransform(GameObject gameObject)
{
RectTransform transform = gameObject.GetComponent<RectTransform>();
if (transform == null || transform.parent == null)
{
return;
}
Bounds parentBounds = RectTransformUtility.CalculateRelativeRectTransformBounds(transform.pare