public static GUIContent BeginProperty(Rect totalPosition, GUIContent label, RuntimeSerializedProperty property) { Highlighter.HighlightIdentifier(totalPosition, property.PropertyPath); if (s_PendingPropertyKeyboardHandling != null) { DoPropertyFieldKeyboardHandling(s_PendingPropertyKeyboardHandling); } // Properties can be nested, so A BeginProperty may not be followed by its corresponding EndProperty // before there have been one or more pairs of BeginProperty/EndProperty in between. // The keyboard handling for a property (that handles duplicate and delete commands for array items) // uses EditorGUI.lastControlID so it has to be executed for a property before any possible child // properties are handled. However, it can't be done in it's own BeginProperty, because the controlID // for the property is not yet known at that point. For that reason we mark the keyboard handling as // pending and handle it either the next BeginProperty call (for the first child property) or if there's // no child properties, then in the matching EndProperty call. s_PendingPropertyKeyboardHandling = property; if (property == null) { string error = ((label != null) ? (label.text + ": ") : EmptyStr) + "RuntimeSerializedProperty is null"; EditorGUI.HelpBox(totalPosition, "null", MessageType.Error); throw new System.NullReferenceException(error); } s_PropertyFieldTempContent.text = LocalizationDatabaseHelper.GetLocalizedString((label != null) ? label.text : property.DisplayName); // no necessary to be translated. s_PropertyFieldTempContent.tooltip = EasyGUI.IsCollectingTooltips ? ((label == null) ? property.Tooltip : label.tooltip) : null; string attributeTooltip = RuntimeScriptAttributeUtility.GetHandler(property, null).Tooltip; if (attributeTooltip != null) { s_PropertyFieldTempContent.tooltip = attributeTooltip; } s_PropertyFieldTempContent.image = label != null ? label.image : null; // In inspector debug mode & when holding down alt. Show the property path of the property. if (Event.current.alt && property.RuntimeSerializedObject.SerializedObject.InspectorMode() != InspectorMode.Normal) { s_PropertyFieldTempContent.tooltip = s_PropertyFieldTempContent.text = property.PropertyPath; } bool wasBoldDefaultFont = EditorGUIUtilityHelper.GetBoldDefaultFont(); if (property.RuntimeSerializedObject.SerializedObject.targetObjects.Length == 1 && property.IsInstantiatedPrefab) { EditorGUIUtilityHelper.SetBoldDefaultFont(property.PrefabOverride); } s_PropertyStack.Push(new RuntimePropertyGUIData(property, totalPosition, wasBoldDefaultFont, GUI.enabled, GUI.backgroundColor)); GUI.enabled &= property.Editable; return(s_PropertyFieldTempContent); }
public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren) { float height = 0f; if (DecoratorDrawers != null && !IsCurrentlyNested) { foreach (var drawer in DecoratorDrawers) { height += drawer.GetHeight(); } } if (PropertyDrawer != null) { height += PropertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtilityHelper.TempContent(property.displayName)); } else if (!includeChildren) { height += EasyGUI.GetSinglePropertyHeight(property, label); } else { property = property.Copy(); // First property with custom label height += EasyGUI.GetSinglePropertyHeight(property, label); bool childrenAreExpanded = property.isExpanded && EasyGUI.HasVisibleChildFields(property); // Loop through all child properties var tc = EditorGUIUtilityHelper.TempContent(property.displayName); if (childrenAreExpanded) { SerializedProperty endProperty = property.GetEndProperty(); while (property.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(property, endProperty)) { height += ScriptAttributeUtility.GetHandler(property, null).GetHeight(property, tc, true); childrenAreExpanded = false; height += EasyGUI.kControlVerticalSpacing; } } } return(height); }
public static void EndProperty() { EditorGUI.showMixedValue = false; RuntimePropertyGUIData data = s_PropertyStack.Pop(); // Context menu // Handle context menu in EndProperty instead of BeginProperty. This ensures that child properties // get the event rather than parent properties when clicking inside the child property rects, but the menu can // still be invoked for the parent property by clicking inside the parent rect but outside the child rects. if (Event.current.type == EventType.ContextClick && data.TotalPosition.Contains(Event.current.mousePosition)) { DoPropertyContextMenu(data.Property); } EditorGUIUtilityHelper.SetBoldDefaultFont(data.WasBoldDefaultFont); GUI.enabled = data.WasEnabled; GUI.backgroundColor = data.Color; if (s_PendingPropertyKeyboardHandling != null) { DoPropertyFieldKeyboardHandling(s_PendingPropertyKeyboardHandling); } // Wait with deleting the property until the property stack is empty in order to avoid // deleting a property in the middle of GUI calls that's dependent on it existing. if (s_PendingPropertyDelete != null && s_PropertyStack.Count == 0) { // For SerializedProperty iteration reasons, if the property we delete is the current property, // we have to delete on the actual iterator property rather than a copy of it, // otherwise we get an error next time we call NextVisible on the iterator property. if (s_PendingPropertyDelete.PropertyPath == data.Property.PropertyPath) { data.Property.DeleteCommand(); } else { s_PendingPropertyDelete.DeleteCommand(); } s_PendingPropertyDelete = null; } }
public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea) { float oldLabelWidth, oldFieldWidth; float propHeight = position.height; position.height = 0; if (DecoratorDrawers != null && !IsCurrentlyNested) { foreach (var decorator in DecoratorDrawers) { position.height = decorator.GetHeight(); oldLabelWidth = EditorGUIUtility.labelWidth; oldFieldWidth = EditorGUIUtility.fieldWidth; decorator.OnGUI(position); EditorGUIUtility.labelWidth = oldLabelWidth; EditorGUIUtility.fieldWidth = oldFieldWidth; position.y += position.height; propHeight -= position.height; } } position.height = propHeight; if (PropertyDrawer != null) { // Remember widths oldLabelWidth = EditorGUIUtility.labelWidth; oldFieldWidth = EditorGUIUtility.fieldWidth; // Draw with custom drawer PropertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtilityHelper.TempContent(property.displayName)); // Restore widths EditorGUIUtility.labelWidth = oldLabelWidth; EditorGUIUtility.fieldWidth = oldFieldWidth; return(false); } else { if (!includeChildren) { return(EasyGUI.DefaultPropertyField(position, property, label)); } // Remember state Vector2 oldIconSize = EditorGUIUtility.GetIconSize(); bool wasEnabled = GUI.enabled; int origIndent = EditorGUI.indentLevel; int relIndent = origIndent - property.depth; SerializedProperty prop = property.Copy(); position.height = EasyGUI.GetSinglePropertyHeight(prop, label); // First property with custom label EditorGUI.indentLevel = prop.depth + relIndent; bool childrenAreExpanded = EasyGUI.DefaultPropertyField(position, prop, label) && EasyGUI.HasVisibleChildFields(prop); position.y += position.height + EasyGUI.kControlVerticalSpacing; // Loop through all child properties if (childrenAreExpanded) { SerializedProperty endProperty = prop.GetEndProperty(); while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty)) { var handler = ScriptAttributeUtility.GetHandler(prop, null); EditorGUI.indentLevel = prop.depth + relIndent; position.height = handler.GetHeight(prop, null, false); if (position.Overlaps(visibleArea)) { EditorGUI.BeginChangeCheck(); childrenAreExpanded = handler.OnGUI(position, prop, null, false) && EasyGUI.HasVisibleChildFields(prop); // Changing child properties (like array size) may invalidate the iterator, // so stop now, or we may get errors. if (EditorGUI.EndChangeCheck()) { break; } } position.y += position.height + EasyGUI.kControlVerticalSpacing; } } // Restore state GUI.enabled = wasEnabled; EditorGUIUtility.SetIconSize(oldIconSize); EditorGUI.indentLevel = origIndent; return(false); } }
// draw the default element public void DrawElement(Rect rect, RuntimeSerializedProperty element, System.Object listItem, bool selected, bool focused, bool draggable) { EditorGUI.LabelField(rect, EditorGUIUtilityHelper.TempContent((element != null) ? element.DisplayName : listItem.ToString())); }
// draw the default header public void DrawHeader(Rect headerRect, SerializedObject serializedObject, RuntimeSerializedProperty element, IList elementList) { EditorGUI.LabelField(headerRect, EditorGUIUtilityHelper.TempContent((element != null) ? "Runtime Serialized Property" : "IList")); }
public virtual void OnGUI(Rect position, RuntimeSerializedProperty property, GUIContent label) { RuntimeEasyGUI.DefaultPropertyField(position, property, label); EditorGUI.LabelField(position, label, EditorGUIUtilityHelper.TempContent("No GUI Implemented")); }
public virtual void OnGUI(Rect position, InspectableProperty property, GUIContent label) { EasyGUI.DefaultPropertyField(position, property, label); EditorGUI.LabelField(position, label, EditorGUIUtilityHelper.TempContent("No GUI Implemented")); }