public object PropertyEditorColor(PropertyEditor propertyEditor, Color value) { if (!propertyEditor.canSet) { Editor.Label(propertyEditor.info.Name, value); return(null); } Editor.ColorField(propertyEditor.info.Name, value, c => propertyEditor.info.SetValue(target, c, null)); return(null); }
public object PropertyEditorColor(controlProperty property, Color value) { if (property.canSet == false) { Editor.Label(property.info.Name, value); return(null); } Editor.ColorField(property.info.Name, value, c => property.info.SetValue(target, c, null)); return(null); }
public object Draw(controlProperty p) { object controlToSet = null; if (p.info.CanRead == false) { return(null); } var val = p.info.GetValue(obj, null); Type type = null; if (val != null) { type = val.GetType(); } else { Editor.Label(p.info.Name, "null"); return(null); } // Array & List. if (val is string == false) { if (type.IsArray || val is IEnumerable) { Editor.BeginVertical(); p.expanded = Editor.Foldout(p.info.Name, p.expanded); if (p.expanded) { var vEnum = val as IEnumerable; var arrayIndex = 0; foreach (var e in vEnum) { var ec = e as Control; if (ec != null) { if (Editor.Button(ec.ToString())) { controlToSet = ec; } } else { if (arrayIndex >= p.arrayEditors.Count) { var aEditor = new objectEditor(e, arrayIndex.ToString()); aEditor.rgb = rgb - 25; if (aEditor.rgb < 128) { aEditor.rgb = 128; } p.arrayEditors.Add(aEditor); } p.arrayEditors[arrayIndex].Draw(); } arrayIndex++; } } Editor.EndVertical(); return(controlToSet); } } // If there is no Set() method then skip. var canSet = true; var pSetMethod = p.info.GetSetMethod(true); if (pSetMethod == null || pSetMethod.IsPrivate) { canSet = false; } // Other editors. if (val is bool) { if (canSet == false) { Editor.Label(p.info.Name, val); return(null); } var bVal = (bool)val; var ebVal = Editor.BooleanField(p.info.Name, bVal); if (ebVal.Changed) { p.info.SetValue(obj, ebVal.Value, null); } } else if (val is Control) { var cVal = val as Control; if (Editor.Button(p.info.Name, cVal.GetType().Name)) { controlToSet = cVal; } } else if (val is Color) { if (canSet == false) { Editor.Label(p.info.Name, val); return(null); } var colorVal = (Color)val; Editor.ColorField(p.info.Name, colorVal, c => p.info.SetValue(obj, c, null)); } else if (val is string) { if (canSet == false) { Editor.Label(p.info.Name, val); return(null); } var stringtVal = (string)val; var esVal = Editor.TextField(p.info.Name, stringtVal); if (esVal.Changed) { p.info.SetValue(obj, esVal.Value, null); } } else if (val is int) { if (canSet == false) { Editor.Label(p.info.Name, val); return(null); } var eiVal = Editor.IntField(p.info.Name, (int)val); if (eiVal.Changed) { p.info.SetValue(obj, eiVal.Value[0], null); } } else if (val is byte || val is sbyte || val is short || val is ushort || val is uint || val is long || val is ulong || val is float || val is double) { if (canSet == false) { Editor.Label(p.info.Name, val); return(null); } // TODO: editors for common types (like for int ^up there). Editor.Label(p.info.Name, val); } else if (val is Enum) { if (canSet == false) { Editor.Label(p.info.Name, val); return(null); } var enumHasFlagAttribute = val.GetType().GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0; var enumOptions = Enum.GetNames(val.GetType()); if (enumHasFlagAttribute) { // TODO: not gonna work with 'None' flag. // https://forum.unity3d.com/threads/editorguilayout-enummaskfield-doesnt-use-enums-values.233332/ var eeVal = Editor.MaskField(p.info.Name, Convert.ToInt32(val), enumOptions); if (eeVal.Changed) { p.info.SetValue(obj, eeVal.Value, null); } } else { var eeVal = Editor.EnumField(p.info.Name, (Enum)val); if (eeVal.Changed) { p.info.SetValue(obj, eeVal.Value, null); } } } else if (val != null) { if (p.editor == null) { p.editor = new objectEditor(val, p.info.Name); p.editor.rgb = rgb - 25; if (p.editor.rgb < 128) { p.editor.rgb = 128; } } p.editor.Draw(); } return(controlToSet); }