0

Please help me how to show UnityEvent variable in custom editor.

Script:

public class BTNPattern : MonoBehaviour {
    public UnityEvent testEvent;
}

Editor script:

[CustomEditor(typeof(BTNPattern))]
public class BTNPatternEditor : Editor {
    public override void OnInspectorGUI() {
        BTNPattern myTarget = (BTNPattern) target;
        // what to put here to show myTarget.testEvent ?
}
Menyus
  • 6,633
  • 4
  • 16
  • 36
user2698308
  • 145
  • 2
  • 12
  • It does show by default. No need for custom editor. – Everts Feb 13 '16 at 18:46
  • im using custom editor because of other variables and usefull way to work with its. Unity Event is just a problem, that appeared in my case – user2698308 Feb 14 '16 at 02:30
  • Possible duplicate of [Unable to change array size in Inspector variable in Unity?](http://stackoverflow.com/questions/35165995/unable-to-change-array-size-in-inspector-variable-in-unity) – Fattie Feb 15 '16 at 17:16
  • You can also draw the default inspector https://docs.unity3d.com/ScriptReference/Editor.DrawDefaultInspector.html – Menyus Jan 26 '21 at 10:07

1 Answers1

1

Ok, I found a way:

SerializedProperty sprop = serializedObject.FindProperty("testEvent");
EditorGUIUtility.LookLikeControls();
EditorGUILayout.PropertyField(sprop);
serializedObject.ApplyModifiedProperties();
Tatranskymedved
  • 4,194
  • 3
  • 21
  • 47
user2698308
  • 145
  • 2
  • 12
  • 1
    I've removed all code that wasn't related to the Q, because OP was mixing another Q in the topic & reanswering in next answer. – Tatranskymedved Jan 26 '21 at 09:10