x


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

more ▼

asked Oct 18 '10 at 06:02 PM

Techsuport 1 gravatar image

Techsuport 1
1 1 1 3

You question is fairly ambiguous. Consider rephrasing for clarity.

Oct 18 '10 at 06:20 PM skovacs1

-1 for posting on the forum also. Put your internet clutter where the sun don't shine!

Oct 18 '10 at 10:05 PM Jessy
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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?

more ▼

answered Oct 18 '10 at 07:07 PM

skovacs1 gravatar image

skovacs1
10k 11 25 92

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Oct 18 '10 at 07:43 PM

Cyb3rManiak gravatar image

Cyb3rManiak
1.6k 1 4 17

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5273
x1729
x981
x850
x70

asked: Oct 18 '10 at 06:02 PM

Seen: 1759 times

Last Updated: Oct 18 '10 at 06:02 PM