2.9 C
New York
Sunday, December 14, 2025

unity – Making use of localScale to components in a verticalLayoutGroup with a gridLayout subgroup


I’ve a couple of components inside a verticalLayoutGroup. To higher visualize which one is chosen, I want to scale all different components to 75% of their dimension and preserve the present one as it’s.

This works so long as the factor doesn’t comprise components on their very own. (The darker colour is about similtaneously the scaling and works, however I would favor to get the scaling working as properly)

When including components to the present chosen line, the whole lot remains to be alright.

enter image description here

However as quickly as one other line will get chosen and the scaling applies, the place for the previous chosen line is inaccurate.

enter image description here

If the road will get chosen once more, it seems to be appropriate once more. The difficulty I want to get fastened is when the it will get scaled down and it shouldn’t be moved to the correct when it has objects by itself.

Every line has this code on it and a button as a set off (mustn’t trigger a difficulty), the code is decreased to the naked minimal.

public class UIDecisionLine: MonoBehaviour {

    non-public Vector3 smallScale = new Vector3(0.75f, 0.75f, 0.75f);  

    public void SetSelected() {
        background.colour = Colour.burlywood;
        remodel.localScale = Vector3.one;
    }

    public void SetDeselected() {
        background.colour = Colour.white;
        remodel.localScale = smallScale;
    }
}

The code is known as from a father or mother means up that holds all strains. They get first all deactivated earlier than one will get activated.

public void SelectRuleLine(GameObject selectedLine) {     
    foreach (var tempGo in allRuleLines) {
        tempGo.GetComponent().SetDeselected();
    }
    currentlySelectedGO = selectedLine;
    UIDecisionLine uiDecisionLine = currentlySelectedGO.GetComponent();
    uiDecisionLine.SetSelected();           
}

It’s a fundamental setup (their is a father or mother scrollView which mustn’t trigger the difficulty)
enter image description here
enter image description here

Every of the choice strains has a gridLayout and people comprise the smaller icons afterwards.

enter image description here

The icons are fundamental photographs from a prefab and a button.

enter image description here

Attempting totally different mixtures within the verticalLayoutgroup both place the road extra to the left (off container), scale the scroll all the way in which to the correct or do nothing in any respect.

Calling LayoutRebuilder.ForceRebuildLayoutImmediate on Content material was not doing something. (After each choose/ deselect or solely after every one).

Altering childAlignment on Content material was not doing something to repair it.

The present Unity model is 6000.2.13f1

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles