Hi guys,
so, I’m trying to make a script, an Editor, that will allow me to change a value - and see the result of the change immediately while in editor mode, e.g. not running the game.
I manage to this, it’s working fine - but I cannot escape the feeling that it may be there a more elegant or simpler solution than the one I’m using. I searched extensively the net, but couldn’t find a better solution. If I’m missing something, please help.
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(cardSuite);
serializedObject.ApplyModifiedProperties();
if (EditorGUI.EndChangeCheck())
{
_cardScript.ChangeSuite();
}
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(cardNumber);
serializedObject.ApplyModifiedProperties();
if (EditorGUI.EndChangeCheck())
{
_cardScript.ChangeNumber();
}
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(isFlipped);
serializedObject.ApplyModifiedProperties();
if (EditorGUI.EndChangeCheck())
{
_cardScript.Flip();
}
}
cardNumber
and cardSuite
are enums type, which will produce dropdown control in the Editor. isFliped
is a bool
ean value, which will produce a checkbox control in the Editor.
So, this is working fine - but is there a better solution?
I imagine this will become a huge mess if there are 10+ properties…