Is there a way to override just one (or several field (controls)) in a custom Editor for a MonoBehaviour or any other inspector editable entity? I know you can use DrawDefaultInspector();
to draw all that Inspector is drawing by default for any non custom inspectable obejct but I want to change one of them and leave alone the others.
The suggestion to just redefine all of them in Custom Editor is not good as you need not only to implement all default logic except for just one field but maintain that Editor later when you change MonoBehavior to add new fields to add respecting controls as well.
More specifically I need to add a callback for 1 field to resize another object in the scene when the field changes.
I tried adding a duplicate of the control and added code on changing this new control. It works fine when I change the new control but when I use old control to change the field Debug.Log() does not fire.
Here is my code so far:
[CustomEditor(typeof(Tetris))]
public class EdScrtiptTest : Editor
{
SerializedProperty startSpeedProp;
void OnEnable()
{
// Setup the SerializedProperties.
startSpeedProp = serializedObject.FindProperty("pieceStartSpeed");
}
public override void OnInspectorGUI()
{
var tetris = target as Tetris;
DrawDefaultInspector();
EditorGUI.BeginChangeCheck();
EditorGUILayout.Slider(startSpeedProp, 0, 100, "Start Speed");
serializedObject.ApplyModifiedProperties();
if (EditorGUI.EndChangeCheck())
{
Debug.Log("Changed");
}
}
}