Hi,
I have a large scene with several thousand GameObject that are arranged in a hierarchy (Region, etc.). Over time, with lots of changes and moving objects and groups of objects around, many levels of that hierarchy have been scaled. The numbers range from 0.00x to several hundred and they often alternate: Object has a scale (55, 200, 160), its child has a scale (0.01, 0.003, 0.004), and so on.
So my question is: is there an easy way (or a way at all) to clean that up?
Edit: thanks for the response NorthStar79, here is how I adapted it:
private void CleanUpScales()
{
foreach (Transform child in self.transform)
{
CleanUpScale(child, 1, 1, 1);
}
}
private void CleanUpScale(Transform transform, float multiplicationX,
float multiplicationY, float multiplicationZ)
{
var localScale = transform.localScale;
var localPosition = transform.localPosition;
transform.localPosition = new Vector3(
localPosition.x * multiplicationX,
localPosition.y * multiplicationY,
localPosition.z * multiplicationZ
);
multiplicationX *= localScale.x;
multiplicationY *= localScale.y;
multiplicationZ *= localScale.z;
if (transform.GetComponent<Renderer>() == null)
{
transform.localScale = new Vector3(1, 1, 1);
foreach (Transform child in transform)
{
CleanUpScale(child, multiplicationX,
multiplicationY, multiplicationZ);
}
}
else
{
transform.localScale = new Vector3(
multiplicationX,
multiplicationY,
multiplicationZ
);
}
}