Last active
November 9, 2023 16:29
-
-
Save kraj0t/e4eca96eb7cca9cfc8bcdf638911e4e3 to your computer and use it in GitHub Desktop.
Extend ParticleSystem editor with custom inspector GUI
This file contains hidden or 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
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
[CustomEditor(typeof(ParticleSystem))] | |
public class CustomParticleSystemEditor : Editor | |
{ | |
private Editor _builtInEditor; | |
private void OnEnable() | |
{ | |
var builtInEditorType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.ParticleSystemInspector"); | |
_builtInEditor = Editor.CreateEditor(targets, builtInEditorType); | |
} | |
private void OnDisable() | |
{ | |
var disableMethod = _builtInEditor.GetType().GetMethod("OnDisable", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); | |
disableMethod!.Invoke(_builtInEditor, null); | |
DestroyImmediate(_builtInEditor); | |
} | |
public override void OnInspectorGUI() | |
{ | |
// Custom GUI | |
GUILayout.Button("my button"); | |
// Built-in GUI | |
_builtInEditor.OnInspectorGUI(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment