Skip to content

Instantly share code, notes, and snippets.

@kraj0t
Last active November 9, 2023 16:29
Show Gist options
  • Save kraj0t/e4eca96eb7cca9cfc8bcdf638911e4e3 to your computer and use it in GitHub Desktop.
Save kraj0t/e4eca96eb7cca9cfc8bcdf638911e4e3 to your computer and use it in GitHub Desktop.
Extend ParticleSystem editor with custom inspector GUI
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