PC NGUI屏幕适配

2017-08-10  本文已影响23人  萧非子

using UnityEngine;
using System.Collections;
//此脚本挂载在UIRoot上
public class UIAdapter : MonoBehaviour
{

 public int ManualWidth = 1920;
 public int ManualHeight = 1080;

void Awake()
{
    AdaptiveUI();
}

 private void AdaptiveUI()
 {

     UIRoot uiRoot = GetComponent<UIRoot>();
     if (uiRoot != null)
     {
        if (System.Convert.ToSingle(Screen.height) / Screen.width > System.Convert.ToSingle(ManualHeight) / ManualWidth)
        {
            uiRoot.manualHeight = Mathf.RoundToInt(System.Convert.ToSingle(ManualWidth) / Screen.width * Screen.height);
        }
        else
        {
            uiRoot.manualHeight = ManualHeight;
        } 
     }
 }

}

上一篇 下一篇

猜你喜欢

热点阅读