关于软件的UI自适应(1)

代码控制软件自适应的方法二:

public Image image;

// Use this for initialization

void Start ()

 {

 float a = Screen.width / 1920.0f;

 float b = Screen.height / 1080.0f;

 float x = image.GetComponent().localPosition.x; 

 float y = image.GetComponent().localPosition.y;

 float z = image.GetComponent().localPosition.z; 

 image.GetComponent().localScale = new Vector3(a,b,1); 

 image.GetComponent().localPosition = new Vector3(x*a,y*b,z);

}

上述方法也可以实现自适应,但是一般只能用于中心定位,且锚点也在中心。

你可能感兴趣的:(关于软件的UI自适应(1))