Skip to content

Instantly share code, notes, and snippets.

@PrashantUnity
Last active August 29, 2022 06:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save PrashantUnity/432f0510f04848f256c517331bcf15a1 to your computer and use it in GitHub Desktop.
// 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.
// use these will be more performant
using UnityEditor;
[CustomEditor(typeof(MapGenerator))]
public class Edit : Editor
{
public override void OnInspectorGUI()
{
MapGenerator mapGenerator = (MapGenerator)target;
if(DrawDefaultInspector())
{
mapGenerator.Function();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment