您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页NGUI 自适应拓展

NGUI 自适应拓展

来源:伴沃教育
using UnityEngine;

using System.Collections;

 

 

//根据设备的宽高比,调整camera.orthographicSize. 以保证UI在不同分辨率(宽高比)下的自适应

//须与UIAnchor配合使用

//将该脚本添加到UICamera同一节点上

 

[RequireComponent(typeof(UICamera))]

public class UICameraAdjustor : MonoBehaviour

{

    float standard_width = 1136f;

    float standard_height = 640f;

    float device_width = 0f;

    float device_height = 0f;

 

     void Awake()

    {

         device_width = Screen.width;

         device_height = Screen.height;

 

        SetCameraSize();

    }

 

    private void SetCameraSize()

     {

        float adjustor = 0f;

         float standard_aspect = standard_width / standard_height;

         float device_aspect = device_width / device_height;

  

         if (device_aspect < standard_aspect)

        {

            adjustor = standard_aspect / device_aspect;

             camera.orthographicSize = adjustor;

        }

     }

 }

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务