Unity发布游戏到安卓时NGUI屏幕分辨率的调整

     一.unity发布到安卓的游戏的开发环境一般为480*800,横屏时大概是800*480就够了。

首先,在UIRoot下创建一个Widget作为容器,将所有ui作为容器的子控件,容器下的所有UI控件随着Container进行缩放,接着为container添加脚本:

</pre><div></div><pre class="csharp" name="code">

using UnityEngine;
using System.Collections;

public class AdjustUI : MonoBehaviour {
    public float stand_width=800;
    public float stand_height=480;
    float drivice_width;
    float drivice_height;
    float scale;
 // Use this for initialization
 void Start () {
        drivice_width = Screen.width;
        drivice_height = Screen.height;
        float dirvice_aspect = drivice_width / drivice_height;
        float stand_aspect = stand_width / stand_height;
        if (dirvice_aspect > stand_aspect)
        {
            scale = dirvice_aspect / stand_aspect;
            transform.localScale = new Vector3(scale, 1, 1);
        }
        else {
            scale = stand_aspect / dirvice_aspect;
            transform.localScale = new Vector3(1,scale,1);
        }
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }
}

 



将stand_width和stand_height设置为开发环境的宽高;
UIRoot的Scaling Style还需要设置一下
二.接着给摄像机添加脚本:
using UnityEngine;
using System.Collections;

public class AdjustCamera : MonoBehaviour {
    public float stand_width=800;
    public float stand_height=480;
    float dirvice_width;
    float dirvice_height;
   
 // Use this for initialization
 void Start () {
        float scale=0;
        dirvice_width = Screen.width;
        dirvice_height = Screen.height;
        float dirice_aspect = dirvice_width / dirvice_height;
        float stand_aspect = stand_width / stand_height;
        if (dirice_aspect < stand_aspect)
        {
            scale = stand_aspect / dirice_aspect;
            Camera.main.orthographicSize = scale;
        }
 }

}
三,这些完成后,发布游戏是需要修改一些设置:
将游戏改为左横屏,好了以上就是NGUI屏幕分辨率遇到的问题,不足之处还望指出,大家共同学习

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值