首页 > 编程语言 > 详细

unity中UI的屏幕自适应代码

时间:2017-09-21 20:00:28      阅读:482      评论:0      收藏:0      [点我收藏+]

public void ScreenUISelfAdptation(Transform scaleUI)
{
  float widthrate = UnityEngine.Screen.width / 1920.0f;
  float heightrate = UnityEngine.Screen.height / 1080.0f;
  float postion_x = scaleUI.GetComponent<RectTransform>().anchoredPosition.x * widthrate;
  float postion_y = scaleUI.GetComponent<RectTransform>().anchoredPosition.y * heightrate;
  scaleUI.localScale = new Vector3(widthrate, heightrate, 1);

  scaleUI.GetComponent<RectTransform>().anchoredPosition = new Vector2(postion_x, postion_y);
}

UnityEngine.Screen.widthUnityEngine.Screen.height是你要发布的屏幕分辨率大小。

1920.0f; x 1080.0f;是你制作UI时Gam e视图中的分辨率大小。

unity中UI的屏幕自适应代码

原文:http://www.cnblogs.com/Study088/p/7570708.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!