Well… apparently, it works as it is.
To be honest with you I wrote this code without testing because before, and I’m sure of it, the variables won’t be assigned if not changed in the property values.
I don’t know if this is because it is a class I wrote and not a Unity object or if the guys at Unity Technology have simplified this process.
Anyway, feel free to post all your impressions and comments to this.
Usually with editor you simple just are writing it to override the MonoBehavior class.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ScriptToEdit : MonoBehaviour
{
[Serializable]
public class Limit {
public float Min;
public float Max;
}
public Limit myLimit = new Limit();
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
[CustomEditor(typeof(ScriptToEdit))]
public class ScriptToEdit_Editor : Editor
{
public override void OnInspectorGUI()
{
ScriptToEdit self = (ScriptToEdit)target;
//Simple use the editor to set the variables.
self.myLimit.Min = EditorGUILayout.FloatField("\tMin", self.myLimit.Min);
self.myLimit.Max = EditorGUILayout.FloatField("\tMax", self.myLimit.Max);
}
}
Well… my situation is a little bit more complicated: the Limit serialized class is used to define different variables into an Orbit class I’m writing. The inspector file is for the Orbit class.
I tried to change and assign the values of the Limit variables defined in the Orbit class, without having an inspector class written by purpose for the Limit class itself.
Do you think that this approach is wrong? I mean, I could also provide an editor script also for the Limit class but I thought that seen that it is basically a collection of 2 float, it was pointless to do that.