通俗理解: sizeDelta = 元素自己寬高 - 錨點矩形寬高 當錨點四個手柄在一塊兒時,錨點矩形寬高爲0,這時獲得的sizeDelta就是元素自己寬高。c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class printpositon : MonoBehaviour
{
private Transform image2;
private void Start()
{
image2 = GameObject.Find("Image2").transform;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("----------UpdateCanvas----------------");
RectTransform rect = image2.gameObject.GetComponent<RectTransform>();
Debug.Log("sizeDelta:" + rect.sizeDelta); --方法一
Debug.Log("rect.width:" + rect.rect.width); --方法二
Debug.Log("rect.height:" + rect.rect.height);
Debug.Log("rect.size:" + rect.rect.size); --方法三
}
}
}
複製代碼