Unity UGUI のアンカーポイントが自動的に調整される

UI を選択し、UI アンカー ポイントをクリックして位置を合わせます。スクリプトはエディター ディレクトリに配置する必要があります。 

 

 

 

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