ugui在运行时改变RectTransform的大小
2017-11-13 01:05
363 查看
http://blog.csdn.net/BeiFuDeNvWang/article/details/50838266
在代码中动态改变RectTransform大小的方法如下所示:
1:直接对sizeDelta属性进行赋值,其中X和Y可以对应理解成width和height。sizeDelta的具体含义:若achors是一个点的话则代表宽高,否则为到锚点的距离
[html] view plain copy print?
var rt = gameObject.GetComponent<RectTransform>();
rt.sizeDelta = new Vector2(100, 30);
2:使用SetSizeWithCurrentAnchors函数来进行设定,其中Horizontal和Vertical分别对应宽和高。此函数受当前锚点和中心点的影响。
[html] view plain copy print?
var rt = gameObject.GetComponent<RectTransform>();
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 30);
3:使用SetInsetAndSizeFromParentEdge函数来进行设定。此函数不受锚点和中心的影响,其中第一个参数代表对齐方式,第二个参数为距离边界的距离,第三个参数为宽度。
[html] view plain copy print?
var rt = gameObject.GetComponent<RectTransform>();
rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, 100);
rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, 30);
在确定使用绝对位置的时候,推荐使用第三种方法。
参考文章:http://www.manew.com/thread-41633-1-1.html
在代码中动态改变RectTransform大小的方法如下所示:
1:直接对sizeDelta属性进行赋值,其中X和Y可以对应理解成width和height。sizeDelta的具体含义:若achors是一个点的话则代表宽高,否则为到锚点的距离
[html] view plain copy print?
var rt = gameObject.GetComponent<RectTransform>();
rt.sizeDelta = new Vector2(100, 30);
2:使用SetSizeWithCurrentAnchors函数来进行设定,其中Horizontal和Vertical分别对应宽和高。此函数受当前锚点和中心点的影响。
[html] view plain copy print?
var rt = gameObject.GetComponent<RectTransform>();
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 30);
3:使用SetInsetAndSizeFromParentEdge函数来进行设定。此函数不受锚点和中心的影响,其中第一个参数代表对齐方式,第二个参数为距离边界的距离,第三个参数为宽度。
[html] view plain copy print?
var rt = gameObject.GetComponent<RectTransform>();
rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, 100);
rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, 30);
在确定使用绝对位置的时候,推荐使用第三种方法。
参考文章:http://www.manew.com/thread-41633-1-1.html
相关文章推荐
- ugui在运行时改变RectTransform的大小
- ugui在运行时改变RectTransform的大小和获取宽高
- ugui在运行时改变RectTransform的大小
- UGUI在运行的时候改变RectTransform的大小和获得宽高
- Delphi中运行时改变panel的位置及大小(通过wm_SysCommand来实现)
- Delphi中运行时改变panel的位置及大小
- C# 在运行中改变控件大小的类 并获取最后控件的大小
- Delphi实现运行时控件的拖动、改变大小等,并且做到与控件类型的解耦
- 在运行时使用鼠标移动控件和改变控件的大小
- 运行时改变控件大小
- 【UGUI】Canvas和Rect Transform
- transform改变图片大小以及位置
- [VB.NET]改变窗体的width或height属性,程序运行后窗体的大小却不发生变化
- [置顶] 【UGUI】UGUI RectTransform
- (转)C#如何在运行时通过鼠标拖动改变控件的大小
- Unity UGUI 原理篇(三):RectTransform
- U3D UGUI学习2 - RectTransform
- ugui学习——可动态改变Content大小的ScrollView
- 通过transform属性改变图片的位置大小等信息
- uGUI知识点剖析之RectTransform