Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Unity3d中重新计算或重新设置GridLayoutGroup中Child的大小_Unity3d - Fatal编程技术网

如何在Unity3d中重新计算或重新设置GridLayoutGroup中Child的大小

如何在Unity3d中重新计算或重新设置GridLayoutGroup中Child的大小,unity3d,Unity3d,在我的游戏中,我有一个GridLayoutGroup用户界面。出于某种原因,我需要删除GridLayoutGroup的childern并添加新的子项。我删除子项的代码是: private void RemoveAllCards(){ int childs = transform.childCount; for (int i = childs - 1; i > 0; i--) { GameObject.Destroy(transform.Get

在我的游戏中,我有一个GridLayoutGroup用户界面。出于某种原因,我需要删除GridLayoutGroup的childern并添加新的子项。我删除子项的代码是:

    private void RemoveAllCards(){
    int childs = transform.childCount;
    for (int i = childs - 1; i > 0; i--)
    {
        GameObject.Destroy(transform.GetChild(i).gameObject);
    }
}
但在我向GridLayoutGroup添加新项目后,项目的y位置从我删除的最后一个项目开始。
所以我的问题是如何在GridLayoutGroup中重新计算或重新定位我的新项目,您需要做的就是在层次结构中重新排列游戏对象。您可以使用以下方法执行此操作:

transform.SetAsLastSibling();
transform.SetAsFirstSibling();
transform.SetSiblingIndex();

谢谢,但它使孩子的z位置-11520?!另外,
SetSiblingIndex
需要将其设置为0但不改变的参数。您基本上是在寻找
ContentSizeFile
吗?