- Home /
Manipulate arrays in Inspector with Editor Script?
Is it possible to write an Editor script that can manipulate the settings one finds in the Inspector window? More specifically, I have a script which contains an array of custom structures. I need to insert (rather than append) new items to that array, and doing this by hand is too tedious. I would like to have an 'insert into array' function I can call to open a space in the middle where needed. Is this even possible?
I tried (with JS) something like this:
var go = GameObject.Find("Scripts");
var ms : MyScript = go.GetComponent(MyScript);
ms.myArray.length++;
where MyScript contains:
var myArray : myStruct[];
But 'length' is read-only, and 'size' is not a member.
Answer by Anton Petrov · Nov 24, 2010 at 08:22 PM
You can use the List generic class which is easier to manage if you want to Insert and RemoveAt.
And then you can create custom Inspector editor to edit your list.
This is not very easy to do, but maybe this is important to you. So this is my idea.
Answer by DaveA · Nov 24, 2010 at 08:17 PM
In case anyone needs to know:
Apparently can't be done with JS? But in C#, this will 'insert at the beginning'
Array.Resize(ref ms.myArray, ms.myArray.Length+1);
int i;
for (i = ms.myArray.Length-1; i > 0; i--)
ms.myArray[i] = ms.myArray[i-1];
Your answer
Follow this Question
Related Questions
Can I get one array to manage both an object and its script simultaneously? 2 Answers
Is it possible to run a script in the editor so it doesnt have to run it again the runtime???? 2 Answers
Class Reference in Editor not working 1 Answer
How to display a list of methods and allow a choice of one of them 1 Answer
Assigning instances of the same script to a array-member in the Inspector 0 Answers