简体   繁体   English

如何防止秤改变尺寸?

[英]How to prevent Scale from changing Sizes?

In a previous post I asked about how to debug a scale issue: Debugging Scale 在上一篇文章中,我询问了如何调试秤的问题: 调试秤

After fixing the problem there seems to be another issue, which I don't understand. 解决问题后,似乎还有另一个我不了解的问题。 I am trying to delete my list of buttons and populate a new list of buttons (refresh). 我正在尝试删除按钮列表并填充新的按钮列表(刷新)。

I broke out the functions to delete the buttons and then to add them back. 我介绍了删除按钮然后再添加回来的功能。 I am using the same script that sets up the original buttons, MakeAllButtons . 我使用的是用于设置原始按钮的相同脚本MakeAllButtons

This is what it looks like when I populate the list of buttons 这是我填充按钮列表时的样子 在此处输入图片说明

When I remove the list of buttons and add back the list of buttons it looks like this. 当我删除按钮列表并重新添加按钮列表时,它看起来像这样。 A scale reduction to .3. 比例缩小到.3。

在此处输入图片说明

If I add another list of buttons (just clicking Add a second time) it looks like this: 如果我添加另一个按钮列表(只需再次单击“ Add ),它看起来像这样: 在此处输入图片说明

The scale for the list of buttons is back to where its suppose to be. 按钮列表的比例返回到其预期的位置。

ADD Button Code: 添加按钮代码:

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);
        }
}

REMOVE BUTTON CODE 删除按钮代码

public void RemoveButtons()
{
    while (positionPanel.childCount > 0)
    {
        GameObject toRemove = positionPanel.transform.GetChild(0).gameObject;
        buttonObjectPool.ReturnObject(toRemove);
    }
}

After the newButton is created, somehow the newButton.localScale is being set to .3, but only for the first run through of the code. 创建newButton后,以某种方式将newButton.localScale设置为.3,但仅适用于代码的首次运行。

It appears that when I removed the object it was storing the scale from the previous loading. 看来,当我删除对象时,它正在存储上一次加载的比例。

So I forced the new object to have the scale I want and it fixed the problem. 因此,我强制新对象具有所需的比例,从而解决了该问题。

        GameObject newButton = buttonObjectPool.GetObject();
        newButton.transform.localScale = new Vector3(1, 1, 1);
        newButton.transform.SetParent(positionPanel, false);

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

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