zoukankan      html  css  js  c++  java
  • Unity3d + NGUI 多分辨率适应

    更多型号适合的移动终端

    现在我们要介绍的《链战争》游戏改编方法,这种适应方法UI这是一个基本维度,背景是一个基本的尺寸。背景比UI没有实际影响某一部分的额外部分,这样就避免了适应iPhone5在这么小的屏幕微调。

    第一套UIRoot的Scaling Style属性,假设是电脑如今FixedSize,假设要打包到移动端选择FixedSizeOnMobiles.

    我这里是以960*640为UI基础尺寸所以这里填写640高。

    以下编写脚本BaseAspect.cs

    using UnityEngine;
    using System.Collections;
    
    [RequireComponent(typeof(UICamera))]
    public class BaseAspect : MonoBehaviour
    {
        float standard_width = 960f;        //初始宽度
        float standard_height = 640f;       //初始高度
        float device_width = 0f;                //当前设备宽度
        float device_height = 0f;               //当前设备高度
        public float adjustor = 0f;         //屏幕矫正比例
        void Awake()
        {
          
            //获取设备宽高
            device_width = Screen.width;
            device_height = Screen.height;
            //计算宽高比例
            float standard_aspect = Screen.width / standard_height;
            float device_aspect = device_width / device_height;
            //计算矫正比例
            if (device_aspect < standard_aspect)
            {
                adjustor = standard_aspect / device_aspect;
                //Debug.Log(standard_aspect);
            }
            Debug.Log("屏幕的比例" + adjustor);
            if (adjustor < 2 && adjustor > 0)
            {
                camera.orthographicSize = adjustor;
            }
          
        }
        // Use this for initialization
        void Start()
        {
    
        }
    
        // Update is called once per frame
        void Update()
        {
    
        }
    }


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


    这样就能够实现适配了。这样的适配的方式会有镶边的存在。

    蓝色是镶嵌边境的地方。

  • 相关阅读:
    三种方式循环打印1-100的值
    线程中put(None)和主函数中put(None)的区别和用法
    进程、线程这篇博客,让你傻傻的一次就能记清楚
    单生产者进程和单消费者进程
    队列
    初始线程
    常见面试题之*args
    常见面试题之*args 和 **kwargs 的使用
    闭包函数之函数加括号和不加括号的意义
    仓鼠找sugar II
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/5027468.html
Copyright © 2011-2022 走看看