Link x,y,z values in Vector3 field

Hi,

I have a custom editor window where I display the selected GO’s localscale (like in the Transform component).
The user can change its scale by typing his own values or sliding over it.

What I’d like to do is link the 3 fields, so that when changing one of the Vector3’s values, the 2 others are modified accordingly. Another way to say it is that the GO would be homotheticaly transformed, its aspect ratio would be preserved.

An example : let’s consider a GO having a scale of (2, 2, 1).
If the user doubles the x value, I want the y and z value doubled too, so the resulting vector becomes (4, 4, 2). Without having to manually type them.

Thanx in advance

I believe you want to use this method Unity - Scripting API: MonoBehaviour.OnValidate()

I suppose if X and Y are always going to be the same and Z is X / 2 you could just do…

void OnValidate()
{
   someVector3 = new Vector3(someVector3.x, someVector3.x, someVector3.x/2);
}

then just only allow them to modify x.