10using System.Reflection;
57 private Action<Rect,
UnityEngine.Object[]> _cachedDelegate;
59 public float GetHeight() {
63 public void Draw(Rect panelRect, SerializedProperty property) {
64 if (_cachedDelegate ==
null) {
65 Type type =
targets[0].GetType();
69 BindingFlags.NonPublic |
71 BindingFlags.Instance |
72 BindingFlags.FlattenHierarchy
76 Debug.LogWarning(
"Could not find method of the name " +
82 int paramCount = method.GetParameters().Length;
83 if (paramCount == 0) {
85 "Rect arg and Object[] arg to know the size of the panel to draw and " +
86 "which components are currently selected.");
93 else if (paramCount == 1 || paramCount == 2) {
94 _cachedDelegate = (rect,
targets) => {
95 if (!method.IsStatic) {
98 object[] argArray =
new object[1];
100 method.Invoke(
targets[0], argArray);
104 object[] argArray =
new object[2];
107 method.Invoke(
null, argArray);
112 " from TopButtonPanel because the method had more than 1 argument.");
116 _cachedDelegate.Invoke(panelRect,
targets);
EditorGUIPanelAttribute(string editorMethodName, int heightInLines=1)
Pass the name of a static method in your MonoBehaviour that accepts a Rect and Object[] targets,...
readonly string editorMethodName