您的位置:首页 > 产品设计 > UI/UE

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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: