Last active
August 29, 2022 06:03
-
-
Save PrashantUnity/432f0510f04848f256c517331bcf15a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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