【发布时间】:2017-04-06 13:14:46
【问题描述】:
在之前的帖子中,我询问了如何调试规模问题:Debugging Scale
解决问题后,似乎还有另一个问题,我不明白。我正在尝试删除我的按钮列表并填充新的按钮列表(刷新)。
我打破了删除按钮然后将它们添加回来的功能。我正在使用设置原始按钮的相同脚本MakeAllButtons。
当我删除按钮列表并重新添加按钮列表时,它看起来像这样。比例缩小到 .3。
如果我添加另一个按钮列表(只需单击 Add 第二次),它看起来像这样:
按钮列表的比例回到了它应该在的位置。
添加按钮代码:
public void MakeAllButtons()
{
for (int i = 0; i < positionList.Count; i++)
{
Position position = positionList[i];
PlayerPrefs.SetInt("PositionUnlocked" + i, position.unlocked); //sets if the item is unlocked
GameObject newButton = buttonObjectPool.GetObject();
newButton.transform.SetParent(positionPanel, false); //this was the problem originally
ButtonDetails buttonDetails = newButton.GetComponent<ButtonDetails>();
buttonDetails.SetupPosition(position, this);
}
}
删除按钮代码
public void RemoveButtons()
{
while (positionPanel.childCount > 0)
{
GameObject toRemove = positionPanel.transform.GetChild(0).gameObject;
buttonObjectPool.ReturnObject(toRemove);
}
}
newButton 创建后,不知何故,newButton.localScale 被设置为 .3,但仅限于代码的第一次运行。
【问题讨论】: