简体   繁体   English

Unity3D:如何通过脚本修改网格布局组组件

[英]Unity3D: How to modify Grid Layout Group component by script

is there any way to change component setting of Constraint: "Fixed Row Count", by script, and then assigning constraint count to 1? 有没有办法改变约束的组件设置:“固定的行数”,由脚本,然后分配约束数到1?

在此处输入图片说明

Create a script, .eg test.cs, add/attach this script to the same game object as the GridLayoutGroup: 创建一个脚本,例如test.cs,将此脚本添加/附加到与GridLayoutGroup相同的游戏对象中:

在此处输入图片说明

public class test : MonoBehaviour {

    GridLayoutGroup glg;

    void Start () {        
        glg = gameObject.GetComponent<GridLayoutGroup>();
        Debug.Log(glg);
        glg.constraint = GridLayoutGroup.Constraint.FixedRowCount;  //**
        glg.constraintCount = 1;                                    //**
    }
}

Run the game, you will see this is automatically set to 1. 运行游戏,您会看到它自动设置为1。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM