I want to automate the process of setting the mesh’s Scale in Lightmap value. I don’t see that as a property of the Mesh class. How can I access this? Thanks.
It’s a property of a Renderer rather than a Mesh. You can access it using a SerializedObject:
public static void SetScaleInLightmap(Renderer renderer, float scaleInLightmap)
{
SerializedObject serializedObject = new SerializedObject(renderer);
SerializedProperty scaleInLightmapProperty = serializedObject.FindProperty("m_ScaleInLightmap");
scaleInLightmapProperty.floatValue = scaleInLightmap;
serializedObject.ApplyModifiedProperties();
}
Will ‘serializedObject.ApplyModifiedProperties();’ return false if the scale is greater than the max atlas size? Can I query the max atlas size from the Renderer first? Thank you for your time!
Nope, ApplyModifiedProperties will simply tell Unity which properties have changed so they can be serialized correctly.
I’m not sure how to get the max atlas size. You may have to implement your own checks.