Skip to content

Instantly share code, notes, and snippets.

@thelastpointer
Created December 10, 2018 12:41
Show Gist options
  • Save thelastpointer/7546c0a94390f489d398c912f7645895 to your computer and use it in GitHub Desktop.
Save thelastpointer/7546c0a94390f489d398c912f7645895 to your computer and use it in GitHub Desktop.
/*
Sample custom editor for a class in the same file.
I've yet to encounter errors with compilation order.
*/
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Project
{
public class ClassWithCustomEditor : MonoBehaviour
{
[SerializeField]
private Vector2 propertyInEditor;
//...
}
}
#if UNITY_EDITOR
namespace Project.Editors
{
[CustomEditor(typeof(ClassWithCustomEditor))]
public class ClassWithCustomEditorEditor : Editor
{
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.LabelField("Some customization here");
EditorGUILayout.PropertyField(serializedObject.FindProperty("propertyInEditor"));
serializedObject.ApplyModifiedProperties();
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment