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