public static void DrawAllField(object obj) { FieldInfo[] fields = obj.GetType().GetFields(); foreach (var field in fields) { string name = field.Name; dynamic val = field.GetValue(obj); DrawAttribute attr = field.GetCustomAttribute <DrawAttribute>(); if (attr == null) { field.SetValue(obj, DrawField(name, val)); } else { field.SetValue(obj, DrawAttrField(val, attr)); } } }
public static object DrawAttrField(object value, DrawAttribute attr) { dynamic val = value; switch (attr.DrawAttributeTypes) { case DrawAttributeTypes.IdPopup: return(DrawIDPopup(attr.Label, val)); case DrawAttributeTypes.ObjectSellectionField: return(DrawObjectField(attr.Label, val)); case DrawAttributeTypes.ScriptableSelectionWindow: return(DrawScriptableSelectionWindow(attr.Label, val)); case DrawAttributeTypes.NotForDraw: return(val); default: return(DrawField(attr.Label, val)); } }
public static object Draw(object obj, FieldInfo field) { if (!field.IsPublic) { return(obj); } DrawAttribute drawType = field.GetCustomAttribute <DrawAttribute>(); dynamic value = obj; if (drawType == null) { if (obj is IGUIDrawable) { return(ScriptableGUIUtils.DrawField(field.Name, value as IGUIDrawable)); } else { return(ScriptableGUIUtils.DrawField(field.Name, value)); } } else if (drawType.DrawAttributeTypes == DrawAttributeTypes.IdPopup) { return(ScriptableGUIUtils.DrawIDPopup(drawType.Label, value)); } else if (drawType.DrawAttributeTypes == DrawAttributeTypes.ObjectSellectionField) { return(ScriptableGUIUtils.DrawObjectField(drawType.Label, value)); } else if (drawType.DrawAttributeTypes == DrawAttributeTypes.ScriptableSelectionWindow) { return(ScriptableGUIUtils.DrawScriptableSelectionWindow(drawType.Label, value)); } return(value); }