Forums › 💬 NodeCanvas › ⚙️ Support › Serializable class drawer › Reply To: Serializable class drawer
I seem to have fixed it but I’m kinda wondering why this wasn’t implemented already. Was there a reason why you chose to not show SerializeField fields?
In case you want to add it to the asset here’s the changed code in the EditorUtils_GUI class:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
public static void ShowAutoEditorGUI(object o) { if (o == null) { return; } foreach (var field in GetAllFields(o.GetType())) { if (field.IsPublic == true || Attribute.IsDefined(field, typeof(SerializeField)) == true) { field.SetValue(o, GenericField(field.Name, field.GetValue(o), field.FieldType, field, o)); GUI.backgroundColor = Color.white; } } GUI.enabled = Application.isPlaying; foreach (var prop in o.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { if (prop.CanRead && prop.CanWrite) { if (prop.DeclaringType.GetField("<" + prop.Name + ">k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance) != null) { GenericField(prop.Name, prop.GetValue(o, null), prop.PropertyType, prop, o); } } } GUI.enabled = true; } // Taken from https://stackoverflow.com/questions/1155529/not-getting-fields-from-gettype-getfields-with-bindingflag-default/1155549#1155549 private static IEnumerable<FieldInfo> GetAllFields(Type t) { if (t == null) return Enumerable.Empty<FieldInfo>(); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly; return t.GetFields(flags).Concat(GetAllFields(t.BaseType)); } |
