/// <summary> /// Gets the height of the property. /// </summary> /// <returns>The property height.</returns> /// <param name="property">Property.</param> /// <param name="label">Label.</param> public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { // ensure property's decorator height is registered if (!decoratorHeights.ContainsKey(property.propertyPath)) { decoratorHeights.Add(property.propertyPath, 0f); } decoratorHeights[property.propertyPath] = 0f; if (DrawerToUse != null) { return(DrawerToUse.GetPropertyHeight(property, label)); } else { float result = EditorGUI.GetPropertyHeight(property, label, true); if (!property.IsArrayElement()) { foreach (PropertyAttribute attr in fieldInfo.GetCustomAttributes <PropertyAttribute>()) { GUIDrawer drawer = SerializedPropertyX.GetGUIDrawer(fieldInfo, attr); if (drawer is DecoratorDrawer) { float height = (drawer as DecoratorDrawer).GetHeight(); result -= height; decoratorHeights[property.propertyPath] += height; } } } return(result); } }
/// <summary> /// Gets the height of the property. /// </summary> /// <returns>The property height.</returns> /// <param name="property">Property.</param> /// <param name="label">Label.</param> public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { if (DrawerToUse != null) { return(DrawerToUse.GetPropertyHeight(property, label)); } else { return(property.GetDrawerHeight(label)); } }
/// <summary> /// Raises the GUI event. /// </summary> /// <param name="position">Position.</param> /// <param name="property">Property.</param> /// <param name="label">Label.</param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // TODO: this can be removed when Unity fixes bug 601339 if (property.isArray && property.propertyType != SerializedPropertyType.String) { return; } // clear all callbacks and cached values if the selection has changed if (!currentSelection.SetEquals(Selection.objects)) { propertySetterCallbacks.Clear(); valueCache.Clear(); currentSelection = new HashSet <Object>(Selection.objects); } // ensure all properties are registered foreach (Object target in property.serializedObject.targetObjects) { HashableSerializedProperty hashableProperty = new HashableSerializedProperty(property.propertyPath, target); // register property if needed RegisterPropertyIfNeeded( hashableProperty, hashableProperty, Attribute.Getter, Attribute.Setter, Attribute.PropertyType ); } // display field EditorGUI.BeginDisabledGroup(Attribute.Setter == null); { if (DrawerToUse == null) { EditorGUI.PropertyField(position, property, true); } else { DrawerToUse.OnGUI(position, property, label); } } EditorGUI.EndDisabledGroup(); }
/// <summary> /// Raises the GUI event. /// </summary> /// <param name="position">Position.</param> /// <param name="property">Property.</param> /// <param name="label">Label.</param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { #if UNITY_4_6 // bug 601339 if (property.isArray && property.propertyType != SerializedPropertyType.String) { return; } #endif // ensure property's decorator height is registered if (!decoratorHeights.ContainsKey(property.propertyPath)) { decoratorHeights.Add(property.propertyPath, 0f); } // clear all callbacks and cached values if the selection has changed if (!s_CurrentSelection.SetEquals(Selection.objects)) { s_PropertySetterCallbacks.Clear(); s_ValueCache.Clear(); s_CurrentSelection = new HashSet <Object>(Selection.objects); } // ensure all properties are registered foreach (Object target in property.serializedObject.targetObjects) { HashableSerializedProperty hashableProperty = new HashableSerializedProperty(property.propertyPath, target); // register property if needed if (hashableProperty.SerializedProperty != null) // newly added array elements might not yet exist { RegisterPropertyIfNeeded( hashableProperty, hashableProperty, Attribute.Getter, Attribute.Setter, Attribute.PropertyType ); } } // display field bool hasSetter = Attribute.Setter != null; EditorGUI.BeginDisabledGroup(!hasSetter); { if (!hasSetter) { position.width -= EditorGUIUtility.singleLineHeight; } if (DrawerToUse == null) { // for generic types, just back up and draw the decorator again if ( property.propertyType == SerializedPropertyType.Generic || property.propertyType == SerializedPropertyType.ObjectReference ) { position.y -= decoratorHeights[property.propertyPath]; EditorGUI.PropertyField(position, property, label, true); // TODO: did Unity 5.1.0b3 fix this? } // for other types, use the default property field else { s_DefaultPropertyField.Invoke(null, new object[] { position, property, label }); } } else { DrawerToUse.OnGUI(position, property, label); } } EditorGUI.EndDisabledGroup(); if (!hasSetter) { position.x += position.width; position.height = EditorGUIUtility.singleLineHeight; position.width = EditorGUIUtility.singleLineHeight; s_NoSetterStatusIcon.tooltip = string.Format("No setter found for {0}.", Attribute.PropertyName); GUI.Box(position, s_NoSetterStatusIcon, EditorStylesX.StatusIconStyle); } }