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/

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

  • 相关阅读:
    D. Constructing the Array
    B. Navigation System
    B. Dreamoon Likes Sequences
    A. Linova and Kingdom
    G. Special Permutation
    B. Xenia and Colorful Gems
    Firetrucks Are Red
    java getInstance()的使用
    java 静态代理和动态代理
    java 类加载机制和反射机制
  • 原文地址:https://www.cnblogs.com/Ligo-Z/p/11277783.html
Copyright © 2011-2022 走看看