Hi!
I'm trying to set class variables through getters & setters. I wrote a custom editor that exposes these methods. The code works just fine, that is if I change values while the game is in play mode, these values are passed to the respective variables. However if I set the values in edit mode, the values are lost as soon as I click on the Play button (values are actually set to the default). I've added the @script ExecuteInEditMode() but to no avail! How can persist the changes I've made in the custom editor while in edit mode?
Thanks!
Code for class SpriteController:
@script ExecuteInEditMode()
private var columns : int;
//Getters & setters
function SetColumns(value : int){
if(value < 0){
value = 0;
}
columns = value;
}
function GetColumns() : int{
return columns;
}
Code for SpriteControllerEditor:
@CustomEditor (SpriteController)
class SpriteControllerEditor extends Editor {
function OnInspectorGUI () {
target.SetColumns(EditorGUILayout.IntField("Columns", target.GetColumns()));
if (GUI.changed)
EditorUtility.SetDirty(target);
}
}