zoukankan      html  css  js  c++  java
  • UnityC#中修改RectTransform

    1.改变RectTransform的Left和Buttom

    
    
    GetComponent<RectTransform>().offsetMax = new Vector2(left, top);
    

    offsetMax是一个Vector2类型

    offsetMax.x即为RectTransform中的Left

    offsetMax.y即为RectTransform中的Buttom

    2.改变RectTransform的Right和Top

    GetComponent<RectTransform>().offsetMin = new Vector2(right, bottom);
    

    offsetMin是一个Vector2类型

    offsetMin.x即为RectTransform中的Right

    offsetMin.y即为RectTransform中的Botttom

    3.改变RectTransform的width,height

    GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);
    

    sizeDelta是一个Vector2类型

    sizeDelta.x即为RectTransform中的width

    sizeDelta.y即为RectTransform中的height

    4.改变RectTransform的pos

    GetComponent<RectTransform>().anchoredPosition3D = new Vector3(posx,posy,posz);
    //修改位置
    GetComponent<RectTransform>().anchoredPosition = new Vector2(posx,posy);//修改Pivot位置
    

    anchoredPosition3D:

    anchoredPosition:

    5.改变RectTransform的锚点

    GetComponent<RectTransform>().anchorMin = new Vector2(0, 1);
    GetComponent<RectTransform>().anchorMax = new Vector2(0, 1);
    

    作者:Ligo丶

    出处:https://www.cnblogs.com/Ligo-Z/

    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。

  • 相关阅读:
    WAMP Apache 2.5 配置虚拟主机
    DOM对象
    BOM对象
    JS内置对象
    CSS定位
    CSS浮动和清除
    浏览器兼容性
    垂直居中
    水平居中总结
    长度值
  • 原文地址:https://www.cnblogs.com/Ligo-Z/p/11277783.html
Copyright © 2011-2022 走看看