当前位置: 首页 > news >正文

重庆网站设计中心中国互联网排名

重庆网站设计中心,中国互联网排名,阜阳h5网站建设,网站开发职业生涯规划范文Horizontal Layout Group | Unity UI | 1.0.0 1. 什么是HorizontalLayoutGroup组件#xff1f; HorizontalLayoutGroup是Unity UGUI中的一种布局组件#xff0c;用于在水平方向上对子物体进行排列和布局。它可以根据一定的规则自动调整子物体的位置和大小#xff0c;使它…Horizontal Layout Group | Unity UI | 1.0.0  1. 什么是HorizontalLayoutGroup组件 HorizontalLayoutGroup是Unity UGUI中的一种布局组件用于在水平方向上对子物体进行排列和布局。它可以根据一定的规则自动调整子物体的位置和大小使它们在水平方向上均匀分布。 Property:Function:PaddingThe padding inside the edges of the layout group.SpacingThe spacing between the layout elements.Child AlignmentThe alignment to use for the child layout elements if they dont fill out all the available space.Control Child SizeWhether the Layout Group controls the width and height of its child layout elements.Use Child ScaleWhether the Layout Group considers the scale of its child layout elements when sizing and laying out elements.Width and Height correspond to the Scale X and Scale Y values in each child layout elements Rect Transform component. You cannot animate the Scale values using the Animator ControllerChild Force ExpandWhether to force the child layout elements to expand to fill additional available space. 2. HorizontalLayoutGroup的工作原理 HorizontalLayoutGroup组件通过以下步骤实现水平布局 获取所有子物体的RectTransform组件。根据子物体的大小和布局规则计算出每个子物体的位置和大小。调整子物体的位置和大小使它们在水平方向上均匀分布。 3. HorizontalLayoutGroup的常用属性 Spacing子物体之间的间距。ChildForceExpandWidth是否强制子物体扩展宽度以填充整个水平布局。ChildForceExpandHeight是否强制子物体扩展高度以填充整个水平布局。ChildControlWidth是否控制子物体的宽度。ChildControlHeight是否控制子物体的高度。 4. HorizontalLayoutGroup的常用函数 CalculateLayoutInputHorizontal()计算水平布局的输入。CalculateLayoutInputVertical()计算垂直布局的输入。SetLayoutHorizontal()设置水平布局。SetLayoutVertical()设置垂直布局。 5. 例子代码 例子1创建一个水平布局并添加三个子物体 using UnityEngine; using UnityEngine.UI;public class Example : MonoBehaviour {public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){for (int i 0; i 3; i){GameObject child Instantiate(childPrefab, layoutGroup.transform);child.GetComponentText().text Child (i 1);}} }操作步骤 创建一个空物体并添加HorizontalLayoutGroup组件。创建一个子物体预制体包含一个Text组件。将子物体预制体拖拽到layoutGroup的Child Prefab属性中。运行游戏可以看到三个子物体在水平方向上均匀分布。 例子2设置子物体之间的间距 using UnityEngine; using UnityEngine.UI;public class Example : MonoBehaviour {public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){layoutGroup.spacing 20f;for (int i 0; i 3; i){GameObject child Instantiate(childPrefab, layoutGroup.transform);child.GetComponentText().text Child (i 1);}} }操作步骤 创建一个空物体并添加HorizontalLayoutGroup组件。创建一个子物体预制体包含一个Text组件。将子物体预制体拖拽到layoutGroup的Child Prefab属性中。将layoutGroup的Spacing属性设置为20。运行游戏可以看到子物体之间的间距变为20。 例子3强制子物体扩展宽度以填充整个水平布局 using UnityEngine; using UnityEngine.UI;public class Example : MonoBehaviour {public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){layoutGroup.childForceExpandWidth true;for (int i 0; i 3; i){GameObject child Instantiate(childPrefab, layoutGroup.transform);child.GetComponentText().text Child (i 1);}} }操作步骤 创建一个空物体并添加HorizontalLayoutGroup组件。创建一个子物体预制体包含一个Text组件。将子物体预制体拖拽到layoutGroup的Child Prefab属性中。将layoutGroup的Child Force Expand Width属性设置为true。运行游戏可以看到子物体的宽度被扩展以填充整个水平布局。 例子4控制子物体的宽度和高度 using UnityEngine; using UnityEngine.UI;public class Example : MonoBehaviour {public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){layoutGroup.childControlWidth false;layoutGroup.childControlHeight false;for (int i 0; i 3; i){GameObject child Instantiate(childPrefab, layoutGroup.transform);child.GetComponentText().text Child (i 1);}} }操作步骤 创建一个空物体并添加HorizontalLayoutGroup组件。创建一个子物体预制体包含一个Text组件。将子物体预制体拖拽到layoutGroup的Child Prefab属性中。将layoutGroup的Child Control Width和Child Control Height属性都设置为false。运行游戏可以看到子物体的宽度和高度不受控制保持原始大小。 例子5自定义布局规则 using UnityEngine; using UnityEngine.UI;public class Example : MonoBehaviour {public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){layoutGroup.childAlignment TextAnchor.MiddleCenter;for (int i 0; i 3; i){GameObject child Instantiate(childPrefab, layoutGroup.transform);child.GetComponentText().text Child (i 1);}} }操作步骤 创建一个空物体并添加HorizontalLayoutGroup组件。创建一个子物体预制体包含一个Text组件。将子物体预制体拖拽到layoutGroup的Child Prefab属性中。将layoutGroup的Child Alignment属性设置为Middle Center。运行游戏可以看到子物体在水平方向上居中对齐。 注意事项 HorizontalLayoutGroup组件只能用于水平布局如果需要垂直布局可以使用VerticalLayoutGroup组件。子物体的RectTransform组件的锚点和位置会影响布局效果需要根据实际需求进行调整。 参考资料 Unity官方文档 - HorizontalLayoutGroup 作者AlianBlank 链接https://www.jianshu.com/p/c5cdb16a7562 来源简书 著作权归作者所有。商业转载请联系作者获得授权非商业转载请注明出处。
http://www.zqtcl.cn/news/696167/

相关文章:

  • 做seo网站图片怎么优化地坪漆东莞网站建设技术支持
  • wordpress theme forest济南优化网站排名
  • 简述网站的制作步骤合肥网站建设需
  • 网站备案的程序哪里能买精准客户电话
  • 白云网站建设网站版式
  • 做美食有哪些网站科技公司介绍
  • 网站后台被百度蜘蛛抓取哪个做网站比较好
  • 企业建设网站的需求分析百度免费发布信息平台
  • 网站建设交易中心上海装修公司排行榜
  • 桂林论坛网站有哪些在线设计平台用户分析
  • wap网站的开发去加网 wordpress
  • 博客网站建设设计论文总结php mysql做网站登录
  • 海南智能网站建设公司wordpress 如何使用php版本号
  • 河南网站开发培训app 软件开发
  • 购物网站功能介绍一流的高密网站建设
  • 电影网站怎么做优化wordpress 去掉w
  • 永久网站空间标书制作员工资很低吗
  • 做网站用到ps么淘宝优惠网站怎么做
  • jsp 淘宝网站验证码 设计搜索引擎排名
  • pdf怎么做电子书下载网站北京成立公司
  • 网站后台附件无法上传阿克苏建设网站
  • 网站和网址有什么不同佛山狮山网站建设
  • 有免费的微网站是什么可以做长图的网站
  • 南昌手机建站模板18种禁用软件黄app
  • 备案的域名做电影网站wordpress伪静态cdn配置
  • 国家城乡住房建设部网站百度关键词首页排名
  • 安卓软件开发需要学什么软件北京百度推广优化公司
  • 用asp.net 做网站wordpress网址缩短
  • 中国工程建设交易信息网站仿蘑菇街wordpress主题
  • 网站需要怎么做做普通网站公司吗