UGUI自动适屏功能
2016-12-27 14:46
239 查看
移动方位,需要自己调整到合适的位置。我设置的是Obj的正中心在屏幕左下角位置
public class test : MonoBehaviour { public RectTransform Obj; public float standard_width; //初始宽度 public float standard_height; //初始高度 private int _width; private int _hight; // Use this for initialization void Start () { _width = Screen.width; _hight = Screen.height; SetSize(); } // Update is called once per frame void Update () { } void SetSize() { float device_width = 0f; //当前设备宽度 float device_height = 0f; //当前设备高度 device_width = Screen.width; device_height = Screen.height; float S_x = device_width / standard_width; //宽度缩放比例 float S_y = device_height / standard_height; //高度缩放比例 //矫正比例 Obj.transform.localScale = new Vector3(Obj.transform.localScale.x * S_x, Obj.transform.localScale.y * S_y, Obj.transform.localScale.z); //移动方位,用的时候自己调整这里的位置 Obj.transform.localPosition = new Vector3(-_width / 2, -_hight / 2 - Obj.rect.height / 2 * Obj.transform.localScale.y, 0); } }
相关文章推荐
- 具有自动恢复功能的通知栏图标控件
- 为DataGrid添加自动编号功能
- 具有自动完成功能的ComboBox(源码、原创)
- VB.Net 开发的长内容自动分页功能
- 为DataGrid添加自动编号功能
- 用DBGrid控件配合数据集组件的Sort属性实现“点击标题栏自动排序功能”。
- 自动更新功能的实现尝试 之 更新
- 具有自动数据校验功能的struts标签
- Delphi中的代码自动填充功能
- 在应用程序中集成自动完成功能
- [导入]自己添加的一专业功能:插入法规,可自动格式化你所输入的法规!
- 写了一个将VxWorks的shell打印输出到指定内存中的接口,可广泛用于CLI下的调试函数显示以及故障自动捕获等功能,稍作修改可以适合其它嵌入式OS
- 使用Windows服务实现投票结果的自动发送功能
- (转)使用一个下拉框或文本框+列表框的方式实现类似IE地址栏自动完成的功能
- 在浏览器控件中启用自动完成功能
- 在ant中使用cvs功能自动完成每日构建。
- 为Zend Studio3.5添加PHP5 DOM代码的自动完成功能
- 为DataGrid添加自动编号功能
- 应用RMS实现用户自动登陆功能
- 在WEB自定义控件中实现自动回传功能