Hopefully a simple question: I want to set the size of an array in code, but let another developer adjust the array contents in the Unity inspector; how can I hide the size field or at least make it unalterable while still making each array element alterable?
Abundant blessing on all thine house and thine camels!
I don’t know how you can hide the size parameter in the inspector, but you can force the size by copying the builtin array contents to a temporary array and then recreating the builtin array with your desired length.
var myExposedArray: float[];
private var myExposedArrayLength : int = 10;
function Start()
{
var temp = new Array();
for(i=0; i<myExposedArrayLength; i++)
{
if(i<myExposedArray.length) temp.Push(myExposedArray[i]);
else temp.Push(0);
}
myExposedArray = new float[myExposedArrayLength];
myExposedArray = temp.ToBuiltin(float);
}
I guess that’s the way it goes (I’m using Array.Copy to do pretty much the same thing). Was hopin to have something a little cleaner, but it’s done already anyway, so I guess it’s time to test and move on.