- Home /
Draw custom Property Field in Custom Editor
I've got custom property drawer for MyEnum. In CustomEditor I need to get new MyEnum value via this custom property drawer.
so, basically, I need something like this:
public override void OnInspectorGUI()
{
...
MyEnum myEnum = MyEnum.DefaultValue;
myEnum = EditorGUILayout.PropertyField(typeof(MyEnum), myEnum); // ?
if (myEnum != MyEnum.DefaultValie) { ... }
}
but I know how to draw default inspector only for Serialized Property of specific Serialized Object... Is it possible to draw default inspector for standaline value?
Thanks
Answer by Rarceth · May 03, 2017 at 07:51 AM
So, Im using this as my way atm. I am very new to editor scripting though, so there may be a better version.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor;
[CustomEditor(typeof(NPC))] public class NPCEditor : Editor {
public override void OnInspectorGUI () {
var npc = target as NPC;
npc.npc_type = (NPC.npcType)(EditorGUILayout.EnumPopup ("NPC Type", npc.npc_type));
if (npc.npc_type == NPC.npcType.Base) {
} else if (npc.npc_type == NPC.npcType.Advanced) {
} else if (npc.npc_type == NPC.npcType.Quest) {
}
}
}
Your answer
Follow this Question
Related Questions
Custom editor: How to initialise a new array element? 1 Answer
Get SerializedProperty from outside class for use in popup (PropertyDrawer) 1 Answer
Cannot convert serializedObject to float 1 Answer
objectReferenceValue in SerializedProperty 5 Answers
FindRelativeProperty never worked for me? how does it even work? 2 Answers