コード例 #1
0
        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);
        }
コード例 #2
0
 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] };
 }
コード例 #3
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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public FolderPathDrawer(InspectorAttribute attribute) : base(attribute)
 {
     FAttribute = attribute as FolderPathAttribute;
     OpenGC     = EditorGUIUtility.IconContent("Folder Icon");
 }
コード例 #6
0
 public PasswordDrawer(InspectorAttribute attribute) : base(attribute)
 {
     PAttribute = attribute as PasswordAttribute;
 }
コード例 #7
0
 public ReorderableList(InspectorAttribute attribute) : base(attribute)
 {
     RAttribute = attribute as ReorderableListAttribute;
 }
コード例 #8
0
 public LayerDrawer(InspectorAttribute attribute) : base(attribute)
 {
     LAttribute = attribute as LayerAttribute;
 }
コード例 #9
0
 public DropdownDrawer(InspectorAttribute attribute) : base(attribute)
 {
     DAttribute = attribute as DropdownAttribute;
 }
コード例 #10
0
 public FieldDrawer(InspectorAttribute attribute)
 {
     IAttribute = attribute;
 }
コード例 #11
0
 public FieldPainter(InspectorAttribute attribute)
 {
     IAttribute = attribute;
 }