I often explore new ways to optimise my assets or to create quality-of-life improvements. An example of such an optimization is the Scalable Wrench.
A wrench of this type comes in a wide variety of sizes, but the main shape remains the same. After concluding this, I realised I could optimize this asset by removing the need of seperate sized versions and scale the default 10mm size wrench by the factor of the required size.
This, however, resulted in each wrench having the same number indication in the texture, which would prove to be an unwanted result as the details could be observed from up close. I solved this issue by creating a separate Detail Normal map, which included all the numbers, and an additional UV channel which only mapped the area where the number would be shown.
Through coding, the UV scale and offset change accordingly to the selected size as well as the scaling, resulting in a live update of the desired wrench size.
[ExecuteInEditMode]
...
void ChangeSize()
{
//Set scale from base 10 mm to sizefactor
float t_Scale = m_WrenchSize / 10.0f;
transform.localScale = new Vector3(t_Scale, t_Scale, t_Scale);
//Convert size to index in 4x4 array
int t_Index = 4 - (10 - m_WrenchSize);
float t_UVoffsetX = (1f / 4f) * t_Index;
float t_UVoffsetY = (1f / 4f) * Mathf.FloorToInt(t_Index / 4f);
//Apply offset to UV
GetComponent<Renderer>().sharedMaterial.SetTextureOffset(
"_DetailAlbedoMap", new Vector2(t_UVoffsetX, t_UVoffsetY));
}