- Home /
customization of variables in script for in Editor?
how can i make something like this work? (For, in Editor, customization options of variables of script in Editor)
var haveOption:boolean=false;//used to toggle option
if(haveOption==true){
var optionVariable:float=42;//if true make option available in editor and used by script
}
function Update(){
if(haveOption){
DoStuffWith(optionVariable);
}
}
I want this option to make available various customizable arrays for information input. For example, in the editor, being able to change a variables number, and have that amount of arrays with another variable for each to name each array variable. Plz comment on this concept! =D
-Tech
You question is fairly ambiguous. Consider rephrasing for clarity.
for posting on the forum also. Put your internet clutter where the sun don't shine!
Answer by skovacs1 · Oct 18, 2010 at 07:07 PM
To expose a custom class in the editor, you would use the Serializable and rarely the SerializeField attributes. Public primitive types and Unity classes will serialize automatically and types which are given the Serializable attribute as well as arrays of such types. The System.Object should have this attribute and therefore in javascript, extending the System.Object (or one of the other know serializable types) will give the Seraializable attribute.
Non-typed containers and containers of typed containers will not serialize in and of themselves. To serialize a container of a non-serializing type, you would need to make the type serializable:
public class TransformArray extends System.Object { var array : Transform[]; }
var array : Transform[][]; //Will not serialize; var array2 : TransformArray[]; //Will serialize;
To make a CustomEditor to edit a specific class is fairly simple (See the example in Editor).
Through the broken English, it almost reads as though you are suggesting dynamically building a class editor to create new struct classes. Is this what you are suggesting?
Answer by Cyb3rManiak · Oct 18, 2010 at 07:43 PM
I think he means exposing one variable in the inspector, that by changing it will show expose other fields in the inspector... Like several operation modes for one class, each exposing different variables that relate to that mode.
And if that's the case SerializedProperty is a good solution for that. The example shows you can expose one private variable of the transform class. You can expose pretty much whatever you want, based on whatever you want.