软件UI自适应,对于分辨率不固定的软件(大部分都是),我们需要设置软件的自适应。从两方面考虑:
1.object的大小:
image.GetComponent().sizeDelta = new Vector2(image.GetComponent().sizeDelta .x* (Screen.width/1920.0f), image.GetComponent().sizeDelta .y* (Screen.height / 1080.0f));
此处,以1920*1080的分辨率做好项目,进行适配。
2.object的定位:
image.GetComponent().position = new Vector3(image.GetComponent().position.x * (Screen.width / 1920.0f), (image.GetComponent().position.y - Screen.height )* (Screen.height / 1080.0f)+Screen.height, 0);
此处,以锚点在中心,定位在左上,1920*1080的分辨率,进行适配。