The question is simple, I need to know if there is a unity script variant of [Serializable ].
I tried @script System.Serializable and @System.Serializable. The first one gave no errors but still did not save my editor scripts values when deselecting or going into play mode and the second one did not work at all.
The only info I find on google are all in C# and obviously the C# variant [Serializable ] cannot be used with a unity script approach.
I am really stuck here, I have been debugging and searching the net for hours now.
Thx ahead.
Mark
EDIT: Ok so after debugging for a while I desicovered that the information actualy does get serialized, the problem what is happening is that it does not get loaded back in. So when I deselect an object or go into play mode, the script will go back to its original state and does not reload the saved values. Any ideas with this new info?
First all objects that are derived from UnityEngine.Object are serializable by default, even in C#.
In Unityscript (please don’t call it Java since that’s a totally different language) all custom classes (derived from System.Object) are also by default serializable. So you don’t need this attribute at all.
However the usual syntax for attributes is like you posted in your question:
@ATTRIBUTENAME
Thing_that_gets_the_attribute
Unity just has the @script ATTRIBUTENAME version for MonoBehaviours since you don’t have a class where you can put the attribute in front of.
After hourse of debugging and stumbling trough code, I finaly found the problem myself. The problem was that the booleans and float variables (inside the editor script)controlling
my external scripts where the problem. Instead of putting those booleans on my external booleans I just had to create a toggle-button
for the external boolenas.
At first I had a toggle controlling the editor booleans, wich on their turn would be applied to the external script and now it all refers directly to the external script so.
//this is the version that did not work because an editor script even tough tagged, will never
//serialize and always reset on play or deselect.
class GeneratorPreview extends Editor {
//apply only to this generator
var CurrentGenerator = Selection.activeGameObject;
function OnInspectorGUI() {
CurrentGenerator =GUILayout.Toggle(CurrentGenerator ,"Cylinder cast");
CurrentGenerator.GetComponent(LightShaftGenerator).CastCylinder=CurrentGenerator ;
//Altough this works, it will only work in the editor view as long
//the object is selected.
//As soon as the user selects something different or goes into play-mode
//the variable CastCylinder will reset and thus resetting the
//referenced component (LightShaftGenerator).CastCylinder.
}
}
//working version Here we access all Boolean's directly from its
//component source.
//This way none of the components will listen to anything
//from the editor script and get serialized as normally
//by its own script (in this case LightShaftGenerator).
//As long as you link the components variables directly to
//the button functions or toggles of the editor script everything
//will be linked nicely and serialized nicely.
}
class GeneratorPreview extends Editor {
//apply only to this generator
var CurrentGenerator = Selection.activeGameObject;
function OnInspectorGUI() {
CurrentGenerator.GetComponent(LightShaftGenerator).CastCylinder=GUILayout.Toggle(CurrentGenerator.GetComponent(LightShaftGenerator).CastCylinder,"Cylinder cast");
}
}