/// <summary> /// Ensures uniform scaling for a given transform, /// applying scaling to its colliders and resetting the scale of the transform itself if not uniform. /// </summary> static public void EnsureUniformScaling(Transform inTransform, bool inbForceIdentity = false) { Vector3 scale = inTransform.localScale; if (inbForceIdentity) { if (scale.x == 1 && scale.y == 1 && scale.z == 1) { return; } Undo.SetCurrentGroupName("Scale colliders for identity scaled transform"); } else { if (scale.x == scale.y && scale.y == scale.z) { return; } Undo.SetCurrentGroupName("Scale colliders for uniform scaled transform"); } Collider2D[] collider2ds = inTransform.GetComponents <Collider2D>(); foreach (var collider2d in collider2ds) { Undo.RecordObject(collider2d, "Scaling collider"); PhysicsUtils.ApplyScale(collider2d, scale); } Collider[] colliders = inTransform.GetComponents <Collider>(); foreach (var collider in colliders) { Undo.RecordObject(collider, "Scaling collider"); PhysicsUtils.ApplyScale(collider, scale); } Undo.RecordObject(inTransform, "Reset scale"); inTransform.localScale = Vector3.one; }