简体   繁体   中英

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 .

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.

在此处输入图片说明

If I add another list of buttons (just clicking Add a second time) it looks like this: 在此处输入图片说明

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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