Transformar puede mover el control de zoom rotación de objetos 3D, a continuación, cómo configurar la unidad en el lienzo donde transformarla, puede utilizar RectTransform, que heredó de transformar.
// RectTransform a = this.transform.GetComponent<RectTransform>();//通过获取组件,获取 RectTransform
RectTransform a = this.transform as RectTransform;//通过 as 关键字获得 RectTransform
Localización del elemento móvil: no se puede utilizar directamente a.position = new Vector3 (), que también se puede ajustar, pero no saben dónde ir a conjunto. Utilice los siguientes parámetros de interfaz de usuario específicos.
a.anchoredPosition=new Vector2(10,10);//设置 UI 元素的位置
a.anchoredPosition3D = new Vector3(10,10,10);//设置 UI 元素的位置,上面是2d,这个是3d 的。
elementos de la interfaz obtienen atributos, leído por rect. Este parámetro es de sólo lectura de parámetros, no se puede establecer
Debug.Log("宽度:"+a.rect.width) ;
Debug.Log("高度:"+a.rect.height) ;
Debug.Log("方位:底部"+a.rect.bottom+" right:"+a.rect.right);
Ajuste de la anchura y la altura de los elementos de interfaz de usuario:
// a.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,300);//设置宽度
// a.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,100);//设置高度
Aquí está el código que probé.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonTransform : MonoBehaviour
{
// Start is called before the first frame update
private RectTransform a;
void Start()
{
// a = this.transform.GetComponent<RectTransform>();//获取
a = this.transform as RectTransform;
}
// Update is called once per frame
void Update()
{
// transform.Translate(Vector3.right*Time.deltaTime*50) ;
// a.anchoredPosition=new Vector2(10,10);
// a.anchoredPosition3D = new Vector3(10,10,10);
Debug.Log("宽度:"+a.rect.width) ;
Debug.Log("高度:"+a.rect.height) ;
Debug.Log("方位:底部"+a.rect.bottom+" right:"+a.rect.right);
Debug.Log(a.sizeDelta);
// a.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,300);
// a.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,100);
}
}