Unity UGUI 锚点自动对齐

选中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

猜你喜欢

转载自blog.csdn.net/qq_39097425/article/details/127848883