その後、どのようにRectTransformを使用することができ、それを変換キャンバスにUnityを設定して、ズーム制御、3Dオブジェクトの回転を移動することができます変換、それはトランスフォームから継承されました。
// RectTransform a = this.transform.GetComponent<RectTransform>();//通过获取组件,获取 RectTransform
RectTransform a = this.transform as RectTransform;//通过 as 关键字获得 RectTransform
可動要素の場所:直接設定することもできますが、どこのセットに行くことを知っていないa.position =新しいのVector3()を使用することはできません。以下のUI固有のパラメータ設定を使用します。
a.anchoredPosition=new Vector2(10,10);//设置 UI 元素的位置
a.anchoredPosition3D = new Vector3(10,10,10);//设置 UI 元素的位置,上面是2d,这个是3d 的。
UI要素は矩形で読み取り属性を取得します。このパラメータが読み取り専用パラメータを、設定することができません
Debug.Log("宽度:"+a.rect.width) ;
Debug.Log("高度:"+a.rect.height) ;
Debug.Log("方位:底部"+a.rect.bottom+" right:"+a.rect.right);
UI要素の幅と高さを設定します:
// a.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,300);//设置宽度
// a.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,100);//设置高度
ここで私がテストしたコードです。
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);
}
}