using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(MyComponent))]
[CanEditMultipleObjects]
public class MyComponentEditor : Editor
{
public override void OnInspectorGUI()
{
MyComponent myComponent = (MyComponent)target;
DrawDefaultInspector();
if(GUILayout.Button("MyButton"))
{
myComponent.doSomething();
}
}
}
// MapGenerator is class on which this custom editor will be called
using UnityEditor;
[CustomEditor(typeof(MapGenerator))]
public class Edit : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
// if you remove |^|(base.OnInspectorGUI(); )
// variable in inspector may not show up properly
MapGenerator mapGenerator = (MapGenerator)target;
mapGenerator.Function();
}
}
// another approach it is called only if there is change in the value.
using UnityEditor;
[CustomEditor(typeof(MapGenerator))]
public class Edit : Editor
{
public override void OnInspectorGUI()
{
MapGenerator mapGenerator = (MapGenerator)target;
if(DrawDefaultInspector())
{
mapGenerator.Function();
}
}
}