zoukankan      html  css  js  c++  java
  • UGUI 的多分辨率适配

    1、Canvas的属性配置

    2、Canvas Scaler的属性配置

    3、根据不同的屏幕的比例动态修改缩放基准

     1 void Start ()   
     2     {  
     3         float standard_width = 960f;        //初始宽度  
     4         float standard_height = 640f;       //初始高度  
     5         float device_width = 0f;                //当前设备宽度  
     6         float device_height = 0f;               //当前设备高度  
     7         float adjustor = 0f;         //屏幕矫正比例  
     8         //获取设备宽高  
     9         device_width = Screen.width;  
    10         device_height = Screen.height;  
    11         //计算宽高比例  
    12         float standard_aspect = standard_width / standard_height;  
    13         float device_aspect = device_width / device_height;  
    14         //计算矫正比例  
    15         if (device_aspect < standard_aspect)  
    16         {  
    17             adjustor = standard_aspect / device_aspect;  
    18         }  
    19   
    20         CanvasScaler canvasScalerTemp = transform.GetComponent<CanvasScaler>();  
    21         if (adjustor == 0)  
    22         {  
    23             canvasScalerTemp.matchWidthOrHeight = 1;  
    24         }  
    25         else  
    26         {  
    27             canvasScalerTemp.matchWidthOrHeight = 0;  
    28         }  
    29     }  

    将脚本挂在画布控件上。

  • 相关阅读:
    异常处理
    弹出对话框
    ef——存储过程
    事务
    linq——常用方法
    Linq
    asp get与post获取的区别
    Web服务的调用
    AJAX控件——多层弹出Accordion
    数据绑定
  • 原文地址:https://www.cnblogs.com/AaronBlogs/p/6930848.html
Copyright © 2011-2022 走看看