- Home /
How do you add an array to a Custom Editor in JavaScript?
There seems to only be examples for C#, but not for JavaScript. If anyone could supply a simple example it would be greatly appreciated. I'm sure others would also find it helpful.
Basically I'm just looking for an example of how to add an array to the Custom Editor. I'm not one to just ask for code, but there are literally no examples for JavaScript. I have searched the web all day. Something along the lines of what's below.
//RegularScript.js
var someArray : GameObject[];
//RegularScript_Editor.js
@CustomEditor (RegularScript)
class RegularScript_Editor extends Editor
{
//Need some help with this part
var someArray[] : boolean = !EditorUtility.IsPersistent (target);
target.someArray = EditorGUILayout.ObjectField ("Some Array", target.someArray, GameObject[], someArray);
}
I've been messing with the editor script to try and figure this out, but still no luck. This was able to compile, but it didn't do anything.
Any ideas?
//Script.js
public var objs : GameObject = null;
//EditorScript.js
for(var i = 0; i < target.objs.Length; i++)
if(target.objs[i])
{
var wayPoint : boolean = !EditorUtility.IsPersistent (target);
target.objs.length = EditorGUILayout.ObjectField ("Way Point", target.objs.length, GameObject, wayPoint);
}
Answer by BHS · Jul 16, 2014 at 11:47 PM
I ended up finding a solution.
Since it took me forever to figure this out, I'll post it as an answer to save others from wasting their time like I did.
//Script.js
var myArray : GameObject[];
//EditorScript.js
@CustomEditor (Script)
class EditorScript extends Editor {
EditorGUILayout.PropertyField(serializedObject.FindProperty("myArray"), true);
}
Thank you so much! You won't believe how many hours I spent trying to look for an actual answer to this question. Everybody usually directs the asker to some needlessly expansive guide, or starts lecturing the asker on how he should use some other method or whatnot.
Thank you for your direct, concise answer.
Your answer
