zoukankan      html  css  js  c++  java
  • UGUI RectTransform 矩形变换

    UGUI游戏对象基本都有这个组件。

    float radius;
    radius = GetComponent<RectTransform>().sizeDelta.x;
    radius = (transform as RectTransform).sizeDelta.xf;

    上面两个给radius赋值的方式是一样的.

    UGUI游戏对象的 RectTransform.position  与 transform.position ,RectTransform.localPosition  与 transform.localPosition ,它们是一样的。

    下面是RectTransform的一些变量,可以Unity圣典里面查看:

    Variables 变量:

    anchoredPosition The position of the pivot of this RectTransform relative to the anchor reference point.
    该矩形变换相对于锚点参考点的中心点位置。
    anchoredPosition3D The 3D position of the pivot of this RectTransform relative to the anchor reference point.
    该矩阵变换相对于锚点参考点的中心点的3D位置。
    anchorMax The normalized position in the parent RectTransform that the upper right corner is anchored to.
    该锚点在父矩阵变换中归一化位置,右上角是锚点。
    anchorMin The normalized position in the parent RectTransform that the lower left corner is anchored to.
    在父矩阵变换上归一化位置,该锚点在左下角。
    offsetMax The offset of the upper right corner of the rectangle relative to the upper right anchor.
    矩形右上角相对于右上角锚点的偏移量。
    offsetMin The offset of the lower left corner of the rectangle relative to the lower left anchor.
    矩形左下角相对于左下角锚点的偏移量。
    pivot The normalized position in this RectTransform that it rotates around.
    在该矩阵变换的归一化位置,围绕该中心点旋转。
    rect The calculated rectangle in the local space of the Transform.
    计算矩形自身空间的变换。
    sizeDelta The size of this RectTransform relative to the distances between the anchors.
    矩阵变换的大小相对于锚点之间的距离。

    用代码去更改:

    1.改变RectTransform的top

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

    2.改变RectTransform的bottom

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

    3.改变RectTransform的width,height

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

    4.改变RectTransform的pos

    GetComponent<RectTransform>().anchoredPosition3D = new Vector3(posx,posy,posz);

    GetComponent<RectTransform>().anchoredPosition = new Vector2(posx,posy);

  • 相关阅读:
    Bootstrap 3 How-To #1 下载与配置
    一致性哈希算法及其在分布式系统中的应用
    哈希(Hash)与加密(Encrypt)的基本原理、区别及工程应用
    ASP.NET MVC3 系列教程
    浏览器对象模型BOM小结
    使用JS实现图片展示瀑布流效果
    利用JS实现购物网站商品放大镜效果
    js事件机制——事件冒泡和捕获
    js入门篇之正则表达式基础
    随机得到1-20之间的10个不相同的随机数
  • 原文地址:https://www.cnblogs.com/Peng18233754457/p/8151273.html
Copyright © 2011-2022 走看看