private GUIContent CustomizeLabel(GUIContent defaultLabel) { InspectorAttribute attr = (InspectorAttribute)attribute; GUIContent label = new GUIContent(defaultLabel); if (attr.label != null) { label.text = attr.label; } if (attr.tooltip != null) { label.tooltip = attr.tooltip; } return(label); }
public HyperlinkDrawer(InspectorAttribute attribute) : base(attribute) { HAttribute = attribute as HyperlinkAttribute; MethodInfo[] methods = typeof(EditorGUILayout).GetMethods(BindingFlags.Static | BindingFlags.NonPublic); foreach (var method in methods) { if (method.Name == "LinkLabel") { ParameterInfo[] parameters = method.GetParameters(); if (parameters != null && parameters.Length > 0 && parameters[0].ParameterType == typeof(string)) { LinkLabel = method; break; } } } Parameter = new object[] { HAttribute.Name, new GUILayoutOption[0] }; }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { InspectorAttribute attr = (InspectorAttribute)attribute; SetupProperty(property); float height = 0; if (attr.visibleCheck == null || GetMemberBoolean(attr.visibleCheck)) { height = GetControlHeight(property, CustomizeLabel(label)); } else { height -= EditorGUIUtility.standardVerticalSpacing; } foreach (var drawer in DecorationAttributeDrawer.GetDecorationAttributeDrawers(fieldInfo, parentObjects)) { height += drawer.GetControlHeight() + EditorGUIUtility.standardVerticalSpacing; } return(height); }
private Rect OnMainGUI(Rect position, SerializedProperty property, GUIContent defaultLabel) { InspectorAttribute attr = (InspectorAttribute)attribute; if (attr.visibleCheck != null && !GetMemberBoolean(attr.visibleCheck)) { return(position); } // Create value getters and setters to handle both field and property backed controls Func <object, object> valueGetter = fieldInfo.GetValue; Action <object, object> valueSetter = fieldInfo.SetValue; if (attr.useProperty != null) { PropertyInfo pInfo = fieldInfo.DeclaringType.GetProperty(attr.useProperty, bindingFlags); if (pInfo == null) { throw new KeyNotFoundException(String.Format("Property '{0}' not found on object of type '{1}'.", attr.useProperty, fieldInfo.DeclaringType)); } else if (!fieldInfo.FieldType.IsAssignableFrom(pInfo.PropertyType)) { throw new InvalidCastException( String.Format("The requested property '{1}.{0}' needs to be castable to the source field.", attr.useProperty, fieldInfo.DeclaringType)); } if (pInfo.CanRead) { valueGetter = (o) => pInfo.GetValue(o, null); } if (pInfo.CanWrite) { valueSetter = (o, v) => pInfo.SetValue(o, v, null); } } EditorGUI.BeginProperty(position, defaultLabel, property); GUIContent label = CustomizeLabel(defaultLabel); object displayValue = valueGetter(parentObject); // Because we are bypassing properties, changes are not registered and we have to check for mixed values ourselves. EditorGUI.showMixedValue = false; for (int i = 1; i < parentObjects.Length; i++) { object value = valueGetter(parentObjects[i]); if (!System.Object.Equals(displayValue, value)) { EditorGUI.showMixedValue = true; break; } } // Do the actual drawing EditorGUI.BeginDisabledGroup(attr.enabledCheck != null && !GetMemberBoolean(attr.enabledCheck)); EditorGUI.indentLevel += attr.indentLevel; position.height = GetControlHeight(property, label); object newValue = DrawControl(position, property, label, displayValue); position.y += position.height + EditorGUIUtility.standardVerticalSpacing; EditorGUI.indentLevel -= attr.indentLevel; EditorGUI.EndDisabledGroup(); EditorGUI.EndProperty(); EditorGUI.showMixedValue = false; // React if the value changed if (!System.Object.Equals(displayValue, newValue)) { foreach (Object target in property.serializedObject.targetObjects) { Undo.RecordObject(target, label.text); EditorUtility.SetDirty(target); } foreach (object parent in parentObjects) { valueSetter(parent, newValue); } } return(position); }
public FolderPathDrawer(InspectorAttribute attribute) : base(attribute) { FAttribute = attribute as FolderPathAttribute; OpenGC = EditorGUIUtility.IconContent("Folder Icon"); }
public PasswordDrawer(InspectorAttribute attribute) : base(attribute) { PAttribute = attribute as PasswordAttribute; }
public ReorderableList(InspectorAttribute attribute) : base(attribute) { RAttribute = attribute as ReorderableListAttribute; }
public LayerDrawer(InspectorAttribute attribute) : base(attribute) { LAttribute = attribute as LayerAttribute; }
public DropdownDrawer(InspectorAttribute attribute) : base(attribute) { DAttribute = attribute as DropdownAttribute; }
public FieldDrawer(InspectorAttribute attribute) { IAttribute = attribute; }
public FieldPainter(InspectorAttribute attribute) { IAttribute = attribute; }