/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, ButtonGroupAttribute attribute, GUIContent label) { AllEditorGUI.BeginIndentedHorizontal(); PropertyContext <int> height; if (property.Context.Get(this, "ButtonHeight", out height)) { //height = new PropertyContext<int>(); height.Value = 0; for (int i = 0; i < property.Children.Count; i++) { var button = property.Children[i].Info.GetAttribute <ButtonAttribute>(); if (button != null && button.ButtonHeight > 0) { height.Value = button.ButtonHeight; } } } for (int i = 0; i < property.Children.Count; i++) { var style = (GUIStyle)null; if (property.Children.Count != 1) { if (i == 0) { style = SirenixGUIStyles.ButtonLeft; } else if (i == property.Children.Count - 1) { style = SirenixGUIStyles.ButtonRight; } else { style = SirenixGUIStyles.ButtonMid; } } property.Children[i].Context.GetGlobal("ButtonHeight", height.Value).Value = height.Value; property.Children[i].Context.GetGlobal("ButtonStyle", style).Value = style; InspectorUtilities.DrawProperty(property.Children[i]); } AllEditorGUI.EndIndentedHorizontal(); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <Vector3> entry, GUIContent label) { if (label == null) { AllEditorGUI.BeginIndentedHorizontal(EditorGUI.indentLevel == 0 ? GUIStyle.none : SirenixGUIStyles.PropertyMargin); } else { GUILayout.BeginHorizontal(); } if (label != null) { EditorGUI.BeginChangeCheck(); var value = SirenixEditorFields.VectorPrefixLabel(label, entry.SmartValue); if (EditorGUI.EndChangeCheck()) { entry.SmartValue = value; } } var r = GUIHelper.GetCurrentLayoutRect(); bool showLabels = !(SirenixEditorFields.ResponsiveVectorComponentFields && (label != null ? r.width - EditorGUIUtility.labelWidth : r.width) < 185); GUIHelper.PushLabelWidth(SirenixEditorFields.SingleLetterStructLabelWidth); GUIHelper.PushIndentLevel(0); entry.Property.Children[0].Draw(showLabels ? GUIHelper.TempContent("X") : null); entry.Property.Children[1].Draw(showLabels ? GUIHelper.TempContent("Y") : null); entry.Property.Children[2].Draw(showLabels ? GUIHelper.TempContent("Z") : null); GUIHelper.PopIndentLevel(); GUIHelper.PopLabelWidth(); if (label == null) { AllEditorGUI.EndIndentedHorizontal(); } else { GUILayout.EndHorizontal(); } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, HorizontalGroupAttribute attribute, GUIContent label) { var context = property.Context.Get(this, "Context", (Context)null); if (context.Value == null) { context.Value = new Context(); if (attribute.Title != null) { context.Value.TitleHelper = new StringMemberHelper(property.ParentType, attribute.Title); } context.Value.Widths = new float[property.Children.Count]; context.Value.MinWidths = new float[property.Children.Count]; context.Value.MaxWidths = new float[property.Children.Count]; context.Value.LabelWidths = new float[property.Children.Count]; context.Value.Margins = new Vector2[property.Children.Count]; context.Value.Paddings = new Vector2[property.Children.Count]; float percentageAllocated = 0; for (int i = 0; i < property.Children.Count; i++) { var child = property.Children[i]; var attr = child.Children.Recurse() .Append(child) .SelectMany(a => a.Info.GetAttributes <HorizontalGroupAttribute>()) .FirstOrDefault(x => x.GroupID == attribute.GroupID); if (attr == null) { context.Value.Widths[i] = -1; } else { context.Value.Widths[i] = attr.Width; context.Value.MinWidths[i] = attr.MinWidth; context.Value.MaxWidths[i] = attr.MaxWidth; context.Value.LabelWidths[i] = attr.LabelWidth; if (attr.Width > 0 && attr.Width < 1) { context.Value.ContainsPercentageWidth++; percentageAllocated += attr.Width; // If we allocate 100% there is no way to resize the window down. // In those cases, we convert the attribute to adjust itself automatically and Unity will ensure that // that it reaches the 100% for us. if (percentageAllocated >= 0.97) { percentageAllocated -= attr.Width; context.Value.Widths[i] = 0; attr.Width = 0; } } if (attr.MinWidth > 0 && attr.MinWidth <= 1) { context.Value.ContainsPercentageWidth++; percentageAllocated += attr.MinWidth; // Same thing for MinWidth. if (percentageAllocated >= 0.97) { percentageAllocated -= attr.MinWidth; context.Value.MinWidths[i] = 0; attr.MinWidth = 0; } } context.Value.Margins[i] = new Vector2(attr.MarginLeft, attr.MarginRight); context.Value.Paddings[i] = new Vector2(attr.PaddingLeft, attr.PaddingRight); } } } if (context.Value.TitleHelper != null) { if (context.Value.TitleHelper.ErrorMessage != null) { AllEditorGUI.ErrorMessageBox(context.Value.TitleHelper.ErrorMessage); } else { AllEditorGUI.Title(context.Value.TitleHelper.GetString(property), null, TextAlignment.Left, false); } } AllEditorGUI.BeginIndentedHorizontal(GUILayoutOptions.ExpandWidth(false)); { if (Event.current.type == EventType.Repaint) { var newWidth = GUIHelper.GetCurrentLayoutRect().width; if (context.Value.TotalWidth != newWidth) { GUIHelper.RequestRepaint(); } context.Value.TotalWidth = newWidth; } for (int i = 0; i < property.Children.Count; i++) { float width, minWidth, maxWidth; Vector2 padding, margin; if (context.Value.ContainsPercentageWidth > 1 && context.Value.TotalWidth == 0) { width = 20; // Start small and expand next frame. Instead of starting to big and slowly getting smaller. minWidth = 0; maxWidth = 0; padding = new Vector2(); margin = new Vector2(); } else { width = context.Value.Widths[i]; minWidth = context.Value.MinWidths[i]; maxWidth = context.Value.MaxWidths[i]; margin = context.Value.Margins[i]; padding = context.Value.Paddings[i]; if (padding.x > 0 && padding.x <= 1) { padding.x = padding.x * context.Value.TotalWidth; } if (padding.y > 0 && padding.y <= 1) { padding.y = padding.y * context.Value.TotalWidth; } if (margin.x > 0 && margin.x <= 1) { margin.x = margin.x * context.Value.TotalWidth; } if (margin.y > 0 && margin.y <= 1) { margin.y = margin.y * context.Value.TotalWidth; } if (width <= 1) { width = width * context.Value.TotalWidth; } width -= padding.x + padding.y; if (minWidth > 0) { if (minWidth <= 1) { minWidth = minWidth * context.Value.TotalWidth; } minWidth -= padding.x + padding.y; } if (maxWidth > 0) { if (maxWidth <= 1) { maxWidth = maxWidth * context.Value.TotalWidth; } maxWidth -= padding.x + padding.y; } } GUILayoutOptions.GUILayoutOptionsInstance options = null; if (minWidth > 0) { options = GUILayoutOptions.MinWidth(minWidth); } if (maxWidth > 0) { options = options == null?GUILayoutOptions.MaxWidth(maxWidth) : options.MaxWidth(maxWidth); } if (options == null) { options = GUILayoutOptions.Width(width < 0 ? 0 : width); } var prevFieldWidth = EditorGUIUtility.fieldWidth; EditorGUIUtility.fieldWidth = 40; GUILayout.Space(margin.x + padding.x); GUILayout.BeginVertical(options); GUILayout.Space(0); if (attribute.LabelWidth > 0) { GUIHelper.PushLabelWidth(attribute.LabelWidth); } InspectorUtilities.DrawProperty(property.Children[i], property.Children[i].Label); if (attribute.LabelWidth > 0) { GUIHelper.PopLabelWidth(); } GUILayout.Space(0); GUILayout.EndVertical(); EditorGUIUtility.fieldWidth = prevFieldWidth; GUILayout.Space(margin.y + padding.y); } } AllEditorGUI.EndIndentedHorizontal(); }
/// <summary> /// Not yet documented. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <Color> entry, ColorPaletteAttribute attribute, GUIContent label) { AllEditorGUI.BeginIndentedHorizontal(); { var hideLabel = label == null; if (hideLabel == false) { GUILayout.Label(label, GUILayoutOptions.Width(EditorGUIUtility.labelWidth - 4).ExpandWidth(false)); } else { GUILayout.Space(5); } PropertyContext <PaletteContext> contextBuffer; if (entry.Context.Get(this, "ColorPalette", out contextBuffer)) { contextBuffer.Value = new PaletteContext() { PaletteIndex = 0, CurrentName = attribute.PaletteName, ShowAlpha = attribute.ShowAlpha, Names = ColorPaletteManager.Instance.ColorPalettes.Select(x => x.Name).ToArray(), }; // Get persistent context value if (attribute.PaletteName == null) { contextBuffer.Value.PersistentName = entry.Context.GetPersistent <string>(this, "ColorPaletteName", null); var list = contextBuffer.Value.Names.ToList(); contextBuffer.Value.CurrentName = contextBuffer.Value.PersistentName.Value; if (contextBuffer.Value.CurrentName != null && list.Contains(contextBuffer.Value.CurrentName)) { contextBuffer.Value.PaletteIndex = list.IndexOf(contextBuffer.Value.CurrentName); } } else { contextBuffer.Value.NameGetter = new StringMemberHelper(entry.ParentType, attribute.PaletteName); } } var context = contextBuffer.Value; //var colorPaletDropDown = entry.Context.Get(this, "colorPalette", 0); //var currentName = entry.Context.Get(this, "currentName", attribute.PaletteName); //var showAlpha = entry.Context.Get(this, "showAlpha", attribute.ShowAlpha); //var names = ColorPaletteManager.Instance.GetColorPaletteNames(); ColorPalette colorPalette; var rect = EditorGUILayout.BeginHorizontal(); { rect.x -= 3; rect.width = 25; entry.SmartValue = AllEditorGUI.DrawColorField(rect, entry.SmartValue, false, context.ShowAlpha); bool openInEditorShown = false; GUILayout.Space(28); AllEditorGUI.BeginInlineBox(); { if (attribute.PaletteName == null || ColorPaletteManager.Instance.ShowPaletteName) { AllEditorGUI.BeginBoxHeader(); { if (attribute.PaletteName == null) { var newValue = EditorGUILayout.Popup(context.PaletteIndex, context.Names, GUILayoutOptions.ExpandWidth(true)); if (context.PaletteIndex != newValue) { context.PaletteIndex = newValue; context.CurrentName = context.Names[newValue]; context.PersistentName.Value = context.CurrentName; GUIHelper.RemoveFocusControl(); } } else { GUILayout.Label(context.CurrentName); GUILayout.FlexibleSpace(); } openInEditorShown = true; if (AllEditorGUI.IconButton(EditorIcons.SettingsCog)) { ColorPaletteManager.Instance.OpenInEditor(); } } AllEditorGUI.EndBoxHeader(); } if (attribute.PaletteName == null) { colorPalette = ColorPaletteManager.Instance.ColorPalettes.FirstOrDefault(x => x.Name == context.Names[context.PaletteIndex]); } else { colorPalette = ColorPaletteManager.Instance.ColorPalettes.FirstOrDefault(x => x.Name == context.NameGetter.GetString(entry)); } if (colorPalette == null) { GUILayout.BeginHorizontal(); { if (attribute.PaletteName != null) { if (GUILayout.Button("Create color palette: " + context.NameGetter.GetString(entry))) { ColorPaletteManager.Instance.ColorPalettes.Add(new ColorPalette() { Name = context.NameGetter.GetString(entry) }); ColorPaletteManager.Instance.OpenInEditor(); } } } GUILayout.EndHorizontal(); } else { context.CurrentName = colorPalette.Name; context.ShowAlpha = attribute.ShowAlpha && colorPalette.ShowAlpha; if (openInEditorShown == false) { GUILayout.BeginHorizontal(); } var color = entry.SmartValue; var stretch = ColorPaletteManager.Instance.StretchPalette; var size = ColorPaletteManager.Instance.SwatchSize; var margin = ColorPaletteManager.Instance.SwatchSpacing; if (DrawColorPaletteColorPicker(entry, colorPalette, ref color, colorPalette.ShowAlpha, stretch, size, 20, margin)) { entry.SmartValue = color; //entry.ApplyChanges(); } if (openInEditorShown == false) { GUILayout.Space(4); if (AllEditorGUI.IconButton(EditorIcons.SettingsCog)) { ColorPaletteManager.Instance.OpenInEditor(); } GUILayout.EndHorizontal(); } } } AllEditorGUI.EndInlineBox(); } EditorGUILayout.EndHorizontal(); } AllEditorGUI.EndIndentedHorizontal(); }
private void DrawType(TypeGroup.TypePair typeToDraw, IPropertyValueEntry <InspectorTypeDrawingConfig> entry) { Type currentEditorType = typeToDraw.PreExistingEditorType; bool conflict = false; if (currentEditorType == null) { for (int i = 0; i < entry.Values.Count; i++) { var type = entry.Values[i].GetEditorType(typeToDraw.DrawnType); if (i == 0) { currentEditorType = type; } else if (type != currentEditorType) { currentEditorType = null; conflict = true; break; } } } bool useToggle = true; AllEditorGUI.BeginListItem(); { AllEditorGUI.BeginIndentedHorizontal(); AllEditorGUI.IconButton(EditorIcons.Transparent, IconStyle, 16); if (typeToDraw.PreExistingEditorType != null) { AllEditorGUI.IconButton(EditorIcons.Transparent, IconStyle, 16); GUILayout.Label(typeToDraw.DrawnType.GetNiceName()); GUILayout.Label("Drawn by '" + typeToDraw.PreExistingEditorType + "'", SirenixGUIStyles.RightAlignedGreyMiniLabel); for (int i = 0; i < entry.Values.Count; i++) { if (entry.Values[i].HasEntryForType(typeToDraw.DrawnType)) { entry.Values[i].ClearEditorEntryForDrawnType(typeToDraw.DrawnType); } } } else { EditorGUI.showMixedValue = conflict; if (useToggle) { bool isToggled = currentEditorType == typeof(OdinEditor); GUI.changed = false; isToggled = EditorGUI.Toggle(GUILayoutUtility.GetRect(16, 16, EditorStyles.toggle, GUILayoutOptions.ExpandWidth(false).Width(16)), isToggled); if (GUI.changed) { for (int i = 0; i < entry.Values.Count; i++) { entry.Values[i].SetEditorType(typeToDraw.DrawnType, isToggled ? typeof(OdinEditor) : null); } UpdateRootGroupConflicts(); InspectorConfig.Instance.UpdateOdinEditors(); } GUILayout.Label(typeToDraw.DrawnType.GetNiceName()); } else { GUILayout.Label("TODO: DROPDOWN!"); } } AllEditorGUI.EndIndentedHorizontal(); EditorGUI.showMixedValue = false; } AllEditorGUI.EndListItem(); }
private void DrawTypeGroup(TypeGroup typeGroup, IPropertyValueEntry <InspectorTypeDrawingConfig> entry, string searchText) { if (!typeGroup.IsSearchVisible) { return; } bool useToggle = true; var rect = AllEditorGUI.BeginListItem(); { bool toggleExpansion = false; AllEditorGUI.BeginIndentedHorizontal(); { EditorIcon icon = (typeGroup.IsExpanded || !searchText.IsNullOrWhitespace()) ? EditorIcons.TriangleDown : EditorIcons.TriangleRight; toggleExpansion = AllEditorGUI.IconButton(icon, IconStyle, 16); if (!typeGroup.HasEligibleTypes) { toggleExpansion |= AllEditorGUI.IconButton(EditorIcons.Transparent, 20); } else { if (useToggle) { EditorGUI.showMixedValue = typeGroup.HasConflict; bool isToggled = typeGroup.HasConflict || typeGroup.GetSharedEditorType() == typeof(OdinEditor); GUI.changed = false; isToggled = EditorGUI.Toggle(GUILayoutUtility.GetRect(16, 16, EditorStyles.toggle, GUILayoutOptions.ExpandWidth(false).Width(16)), isToggled); if (GUI.changed) { typeGroup.SetSharedEditorType(isToggled ? typeof(OdinEditor) : null); UpdateRootGroupConflicts(); InspectorConfig.Instance.UpdateOdinEditors(); } EditorGUI.showMixedValue = false; } else { GUILayout.Label("TODO: DROPDOWN!"); } } GUILayout.Label(typeGroup.Name); } AllEditorGUI.EndIndentedHorizontal(); if (toggleExpansion || (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))) { typeGroup.IsExpanded = !typeGroup.IsExpanded; Event.current.Use(); } } AllEditorGUI.EndListItem(); if (AllEditorGUI.BeginFadeGroup(typeGroup, typeGroup.IsExpanded || !searchText.IsNullOrWhitespace())) { EditorGUI.indentLevel++; foreach (var subType in typeGroup.SubTypes) { if (typeGroup.IsTypeVisible(subType.DrawnType)) { this.DrawType(subType, entry); } } foreach (var subGroup in typeGroup.SubGroups) { this.DrawTypeGroup(subGroup, entry, searchText); } EditorGUI.indentLevel--; } AllEditorGUI.EndFadeGroup(); }
private void DrawRootTypeGroup(InspectorDefaultEditors editorCategory, IPropertyValueEntry <InspectorTypeDrawingConfig> entry, string searchText) { TypeGroup typeGroup; switch (editorCategory) { case InspectorDefaultEditors.UserTypes: typeGroup = UserTypesRootGroup; break; case InspectorDefaultEditors.PluginTypes: typeGroup = PluginTypesRootGroup; break; case InspectorDefaultEditors.UnityTypes: typeGroup = UnityTypesRootGroup; break; case InspectorDefaultEditors.OtherTypes: default: typeGroup = OtherTypesRootGroup; break; } if (typeGroup.SubTypes.Count == 0 && typeGroup.SubGroups.Count == 0) { AllEditorGUI.BeginListItem(); { AllEditorGUI.BeginIndentedHorizontal(); { GUIHelper.PushGUIEnabled(false); { AllEditorGUI.IconButton(EditorIcons.TriangleRight, IconStyle, 16); GUILayoutUtility.GetRect(16, 16, EditorStyles.toggle, GUILayoutOptions.ExpandWidth(false).Width(16)); GUILayout.Label(typeGroup.Name); } GUIHelper.PopGUIEnabled(); } AllEditorGUI.EndIndentedHorizontal(); } AllEditorGUI.EndListItem(); } else { bool useToggle = true; var rect = AllEditorGUI.BeginListItem(); { bool toggleExpansion = false; AllEditorGUI.BeginIndentedHorizontal(); { EditorIcon icon = (typeGroup.IsExpanded || !searchText.IsNullOrWhitespace()) ? EditorIcons.TriangleDown : EditorIcons.TriangleRight; toggleExpansion = AllEditorGUI.IconButton(icon, IconStyle, 16); if (useToggle) { EditorGUI.showMixedValue = typeGroup.HasConflict; bool isToggled = typeGroup.HasConflict || typeGroup.GetSharedEditorType() == typeof(OdinEditor); GUI.changed = false; isToggled = EditorGUI.Toggle(GUILayoutUtility.GetRect(16, 16, EditorStyles.toggle, GUILayoutOptions.ExpandWidth(false).Width(16)), isToggled); if (GUI.changed) { typeGroup.ClearEditorTypes(); if (isToggled) { // Add rule flag InspectorConfig.Instance.DefaultEditorBehaviour |= editorCategory; } else { // Remove rule flag InspectorConfig.Instance.DefaultEditorBehaviour = InspectorConfig.Instance.DefaultEditorBehaviour & ~editorCategory; } EditorUtility.SetDirty(InspectorConfig.Instance); InspectorConfig.Instance.UpdateOdinEditors(); } EditorGUI.showMixedValue = false; } else { GUILayout.Label("TODO: DROPDOWN!"); } GUILayout.Label(typeGroup.Name); } AllEditorGUI.EndIndentedHorizontal(); if (toggleExpansion || (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))) { typeGroup.IsExpanded = !typeGroup.IsExpanded; Event.current.Use(); } } AllEditorGUI.EndListItem(); if (AllEditorGUI.BeginFadeGroup(typeGroup, typeGroup.IsExpanded || !searchText.IsNullOrWhitespace())) { EditorGUI.indentLevel++; foreach (var subType in typeGroup.SubTypes) { if (typeGroup.IsTypeVisible(subType.DrawnType)) { this.DrawType(subType, entry); } } foreach (var subGroup in typeGroup.SubGroups) { this.DrawTypeGroup(subGroup, entry, searchText); } EditorGUI.indentLevel--; } AllEditorGUI.EndFadeGroup(); } }