Detect changes to array elements value in inspector

Hi Guys, simple question. I have a list (or it could also be an array) in my inspector.

public List<float> intList;

or

public float[] floatArray;

I can have as many elements in each list or array as I like, but the constraint is that the numeric sum of all element values in the array must always be 10.0

So lets say if my list (or array) had 3 elements, each with the values:

[0] = 3.0 
[1] = 5.0 
[3] = 2.0

If i adjust element [3] to have a value of 10.0, I need to do some calculation and reduce both [0] and [1] to value of 0.0… because the sum of all elements must always be equals to 10.0 ! (Sum of element values, not count of elements!!!)

The problem is not the calculation, but how do i detect that an element value was changed in order to run some custom code to repopulate the values in other elements?

Thanks
Kevin

Hi,
Unity has a really usefully callback for changes to the inspector (and upon exiting playmode) called OnValidate

So, in the script where the arrays are stored you can write something like :

private void OnValidate() 
{
     int sum; //You can use float instead of int if you're for sure just using floats
     foreach (T element in T[] array) //Here you can put float for T
               sum += element; 

     if (sum > desiredValue)
               //Maybe throw a warning to tell you you've passed the limit
                //You re-write the values of your elements here
}