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

UGUI的UI自动填充整个屏幕的脚本

2017-05-02 09:26 225 查看
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UIself : MonoBehaviour
{

[SerializeField]
Vector2 sizeDelta;
float W;
float H;

float sW;
float sH;

RectTransform rt;

// Use this for initialization
void Start()
{
rt = this.GetComponent<RectTransform>();
sW = Screen.width;
sH = Screen.height;
SetPos(sizeDelta);
}

void SetPos(Vector2 v2)
{
rt.sizeDelta = v2 * 9 * Screen.width / (16 * Screen.height);
}
// Update is called once per frame
void Update()
{
if (sW != Screen.width || sH != Screen.height)
{
SetPos(sizeDelta);
sW = Screen.width;
sH = Screen.height;
}
}
}
注意:rt.sizeDelta = v2 * 9 * Screen.width / (16 * Screen.height); 这一句是屏幕宽高比为9:16时做的操作,如果宽高比不是9:16,就得自己改
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: