Skip to content

Instantly share code, notes, and snippets.

@KumoKairo
Created December 2, 2017 19:18
Show Gist options
  • Save KumoKairo/4b3ddb68ce584fc4949f35f7557e4436 to your computer and use it in GitHub Desktop.
Save KumoKairo/4b3ddb68ce584fc4949f35f7557e4436 to your computer and use it in GitHub Desktop.
using UnityEditor;
using UnityEngine;
public class MyWindow : EditorWindow
{
public MySO testNode;
[MenuItem("TEST/OPEN WINDOW")]
static void Init()
{
MyWindow window = (MyWindow)EditorWindow.GetWindow(typeof(MyWindow));
window.Show();
}
private SerializedObject _testNodeSo;
void OnGUI()
{
testNode = EditorGUILayout.ObjectField(testNode, typeof(MySO), false) as MySO;
if (testNode == null)
{
EditorGUILayout.LabelField("Please create a 'MySO' and assign it");
}
else
{
if (_testNodeSo == null)
{
_testNodeSo = new SerializedObject(testNode);
}
// Floats work as expected
EditorGUILayout.PropertyField(_testNodeSo.FindProperty("myFloat"));
// Events are wonky and do not update except on method change
EditorGUILayout.PropertyField(_testNodeSo.FindProperty("myEvent"));
if (GUI.changed)
{
_testNodeSo.ApplyModifiedProperties();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment