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/

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

  • 相关阅读:
    协议(五)-从电报机到智能手机
    协议(四)-通信发展史
    NDK历史版本
    android onKeyDown
    设计模式
    Android获取系统时间的多种方法
    USB 3.0规范中译本 第5章 机械结构
    ES6新特性
    08_SQLyog图形化工具介绍
    07_聚合函数,分组查询&limit关键字
  • 原文地址:https://www.cnblogs.com/Ligo-Z/p/11277783.html
Copyright © 2011-2022 走看看