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);

UGUI RectTransform 矩形变换的更多相关文章

  1. Unity UGUI RectTransform图解

    UGUI RectTransform.Unity RectTransform详解 The first:look look API. http://docs.unity3d.com/ScriptRefe ...

  2. matlab练习程序(矩形变换为单连通形状)

    变换使用的模板必须是单连通的,而且模板中心必须在模板内,如果在模板中打个结或是月牙形,这里的程序就处理不了了. 虽然非单连通模板也有办法处理,不过不是这里要讨论的. 这里用到的方法和矩形变换为圆那片文 ...

  3. UGUI RectTransform

    RectTransform解析 当 Anchor 在同一点时,显示的是物体的座标与大小Pos X.Pos Y.Width.Height ,当 Anchor 不在同一点时(此时会形成矩形),显示的会是 ...

  4. Unity 屏幕坐标到UGUI RectTransform本地坐标的转换

    public static bool ScreenPointToLocalPointInRectangle(RectTransform rect, Vector2 screenPoint, Camer ...

  5. unity,set ugui rectTransform anchor by script

    如果想用代码实现与下面面板相同的功能 试验可知改变上面选项下面四个值也随之变化: 所以说明二者是一回事儿. 因此,只要通过代码修改RectTransform的anchorMax和anchorMin成员 ...

  6. matlab练习程序(矩形变换为圆)

    最近对图像坐标的变换很感兴趣啊,这次是将一张图像变换为圆形. 变换原理就是按变换前后像素到圆心的距离按比例缩减就行了. 改变x,y方向上的系数,应该还可以变换为椭圆,不过我还没有尝试. 注意我这里相当 ...

  7. unity获取ugui上鼠标位置

    public class GetMousePos : MonoBehaviour { public Canvas canvas;//画布 private RectTransform rectTrans ...

  8. Unity UGUI基础之Text

    Text作为UGUI最基础的控件以及最常用的控件,它在项目中的应用绝对可以算是最多的,任何一个UI界面可以说都离不开它,它的基本属性如下: 一.rect transform组件: rect trans ...

  9. 【转】(三)unity4.6Ugui中文教程文档-------概要-UGUI Basic Layout

    原创至上,移步请戳:(三)unity4.6Ugui中文教程文档-------概要-UGUI Basic Layout 2. BasicLayout 在这一节我们会看到UI元素相对于画布的位置是怎样的. ...

随机推荐

  1. Umbraco中获取UmbracoContext

    在Umbraco项目中,获取当前的UmbracoContext几乎是都需要用到的,我们一般通过一个静态方法来获取,代码如下 public class ContextHelpers { public s ...

  2. Dojo Javascript 编程规范(转)

    前言 相当不错的 Javascript 编程风格规范,建议大家采用此规范编写 Javascript.原文链接: http://dojotoolkit.org/developer/StyleGuide ...

  3. 对bookinfo.dat的说明

    作者:马健邮箱:stronghorse_mj@hotmail.com发布:2008.08.03 现在论坛推出的下载工具五花八门,但是有不少都忽视了bookinfo.dat的生成,因此有必要说明一下这个 ...

  4. GetResponse() 基础连接已经关闭:服务器关闭了本应保持活动状态的连接

    1.原因: (1)KeepAlive默认为true,与internet保持持续连接 ,服务器关闭了连接,使用HttpWebResponse.GetResponse()出错 (2)HttpWebRequ ...

  5. GPU,CUDA,cuDNN的理解

    最近用到这方面的知识,感觉这篇文章写的很好,为了方便自己查阅,就搬运了过来,如果牵涉到侵权,请联系我,我会删除该博文!!! 我们知道做深度学习离不开GPU,不过一直以来对GPU和CPU的差别,CUDA ...

  6. Go语言资源教程:Redis介绍安装和使用

    Redis的操作和使用 在安装好redis以后,我们这里给大家讲一下redis操作的一些知识. Redis支持的数据类型:string,hash,list,set,sorted set 我们来练习一下 ...

  7. (multi)set的某些操作

    (multi)set的某些操作 我们可以把multiset当作平衡树用~ 注意,必须定义小于运算符. s.begin() 返回指向第一个元素的迭代器. s.end() 返回指向最后元素的后面那个虚拟元 ...

  8. jmeter-Http信息头管理器

    今天遇到的问题是:一个报名接口,用户先要登录后,再去报名.而登录页面:用户名.密码.动态图形验证码,所以不能直接使用jmeter参数传值方法. 测试的时候,需要先登录,获取ticket后,才能去请求下 ...

  9. P3943 星空 区间异或差分

    \(\color{#0066ff}{ 题目描述 }\) 逃不掉的那一天还是来了,小 F 看着夜空发呆. 天上空荡荡的,没有一颗星星--大概是因为天上吹不散的乌云吧. 心里吹不散的乌云,就让它在那里吧, ...

  10. P2488 [SDOI2011]工作安排 费用流

    \(\color{#0066ff}{ 题目描述 }\) 你的任务是制定出一个产品的分配方案,使得订单条件被满足,并且所有员工的愤怒值之和最小.由于我们并不想使用Special Judge,也为了使选手 ...