zoukankan      html  css  js  c++  java
  • unity中UI的屏幕自适应代码

    public void ScreenUISelfAdptation(Transform scaleUI)
    {
      float widthrate = UnityEngine.Screen.width / 1920.0f;
      float heightrate = UnityEngine.Screen.height / 1080.0f;
      float postion_x = scaleUI.GetComponent<RectTransform>().anchoredPosition.x * widthrate;
      float postion_y = scaleUI.GetComponent<RectTransform>().anchoredPosition.y * heightrate;
      scaleUI.localScale = new Vector3(widthrate, heightrate, 1);

      scaleUI.GetComponent<RectTransform>().anchoredPosition = new Vector2(postion_x, postion_y);
    }

    UnityEngine.Screen.width和UnityEngine.Screen.height是你要发布的屏幕分辨率大小。

    1920.0f; x 1080.0f;是你制作UI时Game视图中的分辨率大小。

  • 相关阅读:
    Oracle
    注解
    java 算法实现
    ConcurrentHashMap
    hashMap 1.8
    hashmap 1.7
    MySQL优化
    Mysql面试题
    tmux
    mysql 复制表结构、表数据的方法
  • 原文地址:https://www.cnblogs.com/Study088/p/7570708.html
Copyright © 2011-2022 走看看