/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <TList> entry, GUIContent label) { var property = entry.Property; int minCount = int.MaxValue; int maxCount = 0; PropertyContext <bool> isVisible; if (entry.Context.Get(this, "is_visible", out isVisible)) { isVisible.Value = GeneralDrawerConfig.Instance.OpenListsByDefault; } for (int i = 0; i < entry.ValueCount; i++) { if (entry.Values[i].Count > maxCount) { maxCount = entry.Values[i].Count; } if (entry.Values[i].Count < minCount) { minCount = entry.Values[i].Count; } } AllEditorGUI.BeginHorizontalToolbar(); isVisible.Value = AllEditorGUI.Foldout(isVisible.Value, GUIHelper.TempContent("SyncList " + label.text + " [" + typeof(TList).Name + "]")); EditorGUILayout.LabelField(GUIHelper.TempContent(minCount == maxCount ? (minCount == 0 ? "Empty" : minCount + " items") : minCount + " (" + maxCount + ") items"), SirenixGUIStyles.RightAlignedGreyMiniLabel); AllEditorGUI.EndHorizontalToolbar(); if (AllEditorGUI.BeginFadeGroup(isVisible, isVisible.Value)) { GUIHelper.PushGUIEnabled(false); AllEditorGUI.BeginVerticalList(); { var elementLabel = new GUIContent(); for (int i = 0; i < maxCount; i++) { AllEditorGUI.BeginListItem(); elementLabel.text = "Item " + i; if (i < minCount) { InspectorUtilities.DrawProperty(property.Children[i], elementLabel); } else { EditorGUILayout.LabelField(elementLabel, "—"); } AllEditorGUI.EndListItem(); } } AllEditorGUI.EndVerticalList(); GUIHelper.PopGUIEnabled(); } AllEditorGUI.EndFadeGroup(); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label) { if (entry.ValueState == PropertyValueState.Reference) { var isToggled = entry.Context.GetPersistent(this, "is_Toggled", false); var targetProp = entry.Property.Tree.GetPropertyAtPath(entry.TargetReferencePath); SirenixEditorGUI.BeginBox(); SirenixEditorGUI.BeginBoxHeader(); EditorGUILayout.BeginHorizontal(); isToggled.Value = label != null?SirenixEditorGUI.Foldout(isToggled.Value, label) : SirenixEditorGUI.Foldout(isToggled.Value, GUIHelper.TempContent("")); if (targetProp.Parent == null) { EditorGUILayout.LabelField("Reference to " + targetProp.Path, SirenixGUIStyles.RightAlignedGreyMiniLabel); } else { EditorGUILayout.LabelField("Reference to " + targetProp.Path, SirenixGUIStyles.RightAlignedGreyMiniLabel); } EditorGUILayout.EndHorizontal(); SirenixEditorGUI.EndBoxHeader(); if (SirenixEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry.Property, this), isToggled.Value)) { //EditorGUI.indentLevel++; //GUIHelper.PushGUIEnabled(true); var isInReference = targetProp.Context.GetGlobal("is_in_reference", false); bool previous = isInReference.Value; isInReference.Value = true; InspectorUtilities.DrawProperty(targetProp); isInReference.Value = previous; //GUIHelper.PopGUIEnabled(); //EditorGUI.indentLevel--; } SirenixEditorGUI.EndFadeGroup(); SirenixEditorGUI.EndBox(); } else { this.CallNextDrawer(entry.Property, label); } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, ButtonGroupAttribute attribute, GUIContent label) { SirenixEditorGUI.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]); } SirenixEditorGUI.EndIndentedHorizontal(); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, BoxGroupAttribute attribute, GUIContent label) { var labelGetter = property.Context.Get <StringMemberHelper>(this, "LabelContext", (StringMemberHelper)null); if (labelGetter.Value == null) { labelGetter.Value = new StringMemberHelper(property.ParentType, attribute.GroupName); } SirenixEditorGUI.BeginBox(attribute.ShowLabel ? labelGetter.Value.GetString(property) : null, attribute.CenterLabel); for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } SirenixEditorGUI.EndBox(); }
public static void DrawPropertyGroupLayout <T>(OdinGroupDrawer <T> ogd, InspectorProperty property, T attribute, GUIContent label, bool result) where T : CrossSceneSideAttribute { if (SirenixEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(property, ogd), result)) { var labelGetter = property.Context.Get <StringMemberHelper>(ogd, "LabelContext", (StringMemberHelper)null); if (labelGetter.Value == null) { labelGetter.Value = new StringMemberHelper(property.ParentType, attribute.GroupName); } SirenixEditorGUI.BeginBox(attribute.ShowLabel ? labelGetter.Value.GetString(property) : null, attribute.CenterLabel); for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i], property.Children[i].Label); } SirenixEditorGUI.EndBox(); } SirenixEditorGUI.EndFadeGroup(); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, FoldoutGroupAttribute attribute, GUIContent label) { var context = property.Context.Get <FoldoutGroupContext>(this, "FoldoutGroupContext", (FoldoutGroupContext)null); if (context.Value == null) { context.Value = new FoldoutGroupContext() { IsVisible = property.Context.GetPersistent <bool>(this, "IsVisible", attribute.HasDefinedExpanded ? attribute.Expanded : AllEditorGUI.ExpandFoldoutByDefault), TitleHelper = new StringMemberHelper(property.ParentType, attribute.GroupName) }; } if (context.Value.TitleHelper.ErrorMessage != null) { AllEditorGUI.ErrorMessageBox(context.Value.TitleHelper.ErrorMessage); } AllEditorGUI.BeginBox(); { AllEditorGUI.BeginBoxHeader(); var content = GUIHelper.TempContent(context.Value.TitleHelper.GetString(property)); var rect = GUILayoutUtility.GetRect(content, SirenixGUIStyles.Label); context.Value.IsVisible.Value = AllEditorGUI.Foldout(rect, context.Value.IsVisible.Value, content); AllEditorGUI.EndBoxHeader(); if (AllEditorGUI.BeginFadeGroup(context, context.Value.IsVisible.Value)) { for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } } AllEditorGUI.EndFadeGroup(); } AllEditorGUI.EndBox(); }
/// <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(); }
private Rect DrawItem(ListDrawerConfigInfo info, InspectorProperty itemProperty, DragHandle dragHandle, int index = -1) { var listItemInfo = itemProperty.Context.Get <ListItemInfo>(this, "listItemInfo"); Rect rect; rect = SirenixEditorGUI.BeginListItem(false, info.ListItemStyle, listItemOptions); { if (Event.current.type == EventType.Repaint && !info.IsReadOnly) { listItemInfo.Value.Width = rect.width; dragHandle.DragHandleRect = new Rect(rect.x + 4, rect.y, 20, rect.height); listItemInfo.Value.DragHandleRect = new Rect(rect.x + 4, rect.y + 2 + ((int)rect.height - 23) / 2, 20, 20); listItemInfo.Value.AddBtnRect = new Rect(listItemInfo.Value.DragHandleRect.x + rect.width - 22, listItemInfo.Value.DragHandleRect.y + 1, 14, 14); itemProperty.Context.GetGlobal <Rect?>("overrideRect").Value = rect; if (info.Draggable) { //GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; GUI.Label(listItemInfo.Value.DragHandleRect, EditorIcons.List.Inactive, GUIStyle.none); //GL.sRGBWrite = false; } } GUIHelper.PushHierarchyMode(false); GUIContent label = null; if (info.CustomListDrawerOptions.ShowIndexLabelsHasValue) { if (info.CustomListDrawerOptions.ShowIndexLabels) { label = new GUIContent(index.ToString()); } } else if (info.listConfig.ShowIndexLabels) { label = new GUIContent(index.ToString()); } if (info.GetListElementLabelText != null) { var value = itemProperty.ValueEntry.WeakSmartValue; if (object.ReferenceEquals(value, null)) { if (label == null) { label = new GUIContent("Null"); } else { label.text += " : Null"; } } else { label = label ?? new GUIContent(""); if (label.text != "") { label.text += " : "; } object text = info.GetListElementLabelText(value); label.text += (text == null ? "" : text.ToString()); } } if (info.OnBeginListElementGUI != null) { info.OnBeginListElementGUI(info.property.ParentValues[0], index); } InspectorUtilities.DrawProperty(itemProperty, label); if (info.OnEndListElementGUI != null) { info.OnEndListElementGUI(info.property.ParentValues[0], index); } GUIHelper.PopHierarchyMode(); if (info.IsReadOnly == false) { if (SirenixEditorGUI.IconButton(listItemInfo.Value.AddBtnRect, EditorIcons.X)) { if (index >= 0) { info.RemoveAt = index; } } } } SirenixEditorGUI.EndListItem(); return(rect); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, ToggleGroupAttribute attribute, GUIContent label) { var toggleProperty = property.Children.Get(attribute.ToggleMemberName); var context = property.Context.Get <ToggleGroupConfig>(this, "ToggleGroupConfig", (ToggleGroupConfig)null); if (context.Value == null) { context.Value = new ToggleGroupConfig(); context.Value.IsVisible = property.Context.GetPersistent <bool>(this, "IsVisible", false); if (toggleProperty == null) { context.Value.ErrorMessage = "No property or field named " + attribute.ToggleMemberName + " found. Make sure the property is part of the inspector and the group."; } else { context.Value.TitleHelper = new StringMemberHelper(property.ParentType, attribute.ToggleGroupTitle, ref context.Value.ErrorMessage); } } if (context.Value.ErrorMessage != null) { AllEditorGUI.ErrorMessageBox(context.Value.ErrorMessage); } else { PropertyContext <string> openGroup = null; if (attribute.CollapseOthersOnExpand) { if (property.Parent == null) { //openGroup = GUIHelper.GetTemporaryContext<PropertyContext<string>>(property.Tree); openGroup = property.Context.Get <string>(this, "OpenGroup", (string)null); } else { var parent = (property.Parent.ValueEntry == null || property.Parent.ValueEntry.ValueCategory == PropertyValueCategory.Member) ? property.Parent : property.Parent.Parent; openGroup = parent.Context.GetGlobal <string>("OpenFoldoutToggleGroup", (string)null); } if (openGroup.Value != null && openGroup.Value != property.Path) { context.Value.IsVisible.Value = false; } } bool isEnabled = (bool)toggleProperty.ValueEntry.WeakSmartValue; string title = context.Value.TitleHelper.GetString(property) ?? attribute.GroupName; bool prev = context.Value.IsVisible.Value; bool visibleBuffer = context.Value.IsVisible.Value; if (AllEditorGUI.BeginToggleGroup(UniqueDrawerKey.Create(property, this), ref isEnabled, ref visibleBuffer, title)) { for (int i = 0; i < property.Children.Count; i++) { var child = property.Children[i]; if (child != toggleProperty) { InspectorUtilities.DrawProperty(child); } } } else { // OnValueChanged is not fired if property is not drawn. GUIHelper.BeginDrawToNothing(); InspectorUtilities.DrawProperty(toggleProperty); GUIHelper.EndDrawToNothing(); } AllEditorGUI.EndToggleGroup(); context.Value.IsVisible.Value = visibleBuffer; if (openGroup != null && prev != context.Value.IsVisible.Value && context.Value.IsVisible.Value) { openGroup.Value = property.Path; } toggleProperty.ValueEntry.WeakSmartValue = isEnabled; // Why is this here? Commenting this out for now //toggleProperty.ValueEntry.ApplyChanges(); } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyImplementation(InspectorProperty property, GUIContent label) { if (label == null) { AllEditorGUI.BeginIndentedVertical(); for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } AllEditorGUI.EndIndentedVertical(); } else { Context context; if (property.Context.Get <Context>(this, "context", out context)) { context.IsVisisble = property.Context.GetPersistent(this, "IsVisible", AllEditorGUI.ExpandFoldoutByDefault); context.IsInlineProperty = property.ValueEntry.TypeOfValue.GetAttribute <InlinePropertyAttribute>() ?? property.Info.GetAttribute <InlinePropertyAttribute>(); } if (context.IsInlineProperty != null) { var outerRect = EditorGUILayout.BeginHorizontal(); { if (Event.current.type == EventType.Repaint) { outerRect.y += 1; EditorGUI.PrefixLabel(outerRect, label); } GUILayout.Space(EditorGUIUtility.labelWidth); GUILayout.BeginVertical(); { if (context.IsInlineProperty.LabelWidth > 0) { GUIHelper.PushLabelWidth(context.IsInlineProperty.LabelWidth); } GUIHelper.PushIndentLevel(0); for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } GUIHelper.PopIndentLevel(); if (context.IsInlineProperty.LabelWidth > 0) { GUIHelper.PopLabelWidth(); } } GUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); } else { context.IsVisisble.Value = AllEditorGUI.Foldout(context.IsVisisble.Value, label); if (AllEditorGUI.BeginFadeGroup(context, context.IsVisisble.Value)) { EditorGUI.indentLevel++; for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } EditorGUI.indentLevel--; } AllEditorGUI.EndFadeGroup(); } } }
private void DrawElements(IPropertyValueEntry <TDictionary> entry, GUIContent label, Context context) { for (int i = context.Paging.StartIndex; i < context.Paging.EndIndex; i++) { var keyValuePairProperty = entry.Property.Children[i]; var keyValuePairEntry = (PropertyDictionaryElementValueEntry <TDictionary, TKey, TValue>)keyValuePairProperty.BaseValueEntry; Rect rect = SirenixEditorGUI.BeginListItem(false, context.ListItemStyle); { if (context.AttrSettings.DisplayMode != DictionaryDisplayOptions.OneLine) { bool defaultExpanded; switch (context.AttrSettings.DisplayMode) { case DictionaryDisplayOptions.CollapsedFoldout: defaultExpanded = false; break; case DictionaryDisplayOptions.ExpandedFoldout: defaultExpanded = true; break; default: defaultExpanded = SirenixEditorGUI.ExpandFoldoutByDefault; break; } var isExpanded = keyValuePairProperty.Context.Get(this, "Expanded", defaultExpanded); SirenixEditorGUI.BeginBox(); SirenixEditorGUI.BeginBoxHeader(); { if (keyValuePairEntry.HasTempInvalidKey) { GUIHelper.PushColor(Color.red); } var btnRect = GUIHelper.GetCurrentLayoutRect().AlignLeft(HeaderMargin.margin.left); btnRect.y += 1; GUILayout.BeginVertical(HeaderMargin); GUIHelper.PushIsDrawingDictionaryKey(true); GUIHelper.PushLabelWidth(10); InspectorUtilities.DrawProperty(keyValuePairProperty.Children[0], null); GUIHelper.PopLabelWidth(); GUIHelper.PopIsDrawingDictionaryKey(); GUILayout.EndVertical(); if (keyValuePairEntry.HasTempInvalidKey) { GUIHelper.PopColor(); } isExpanded.Value = SirenixEditorGUI.Foldout(btnRect, isExpanded.Value, GUIHelper.TempContent("Key")); } SirenixEditorGUI.EndBoxHeader(); if (SirenixEditorGUI.BeginFadeGroup(isExpanded, isExpanded.Value)) { InspectorUtilities.DrawProperty(keyValuePairProperty.Children[1], null); } SirenixEditorGUI.EndFadeGroup(); SirenixEditorGUI.EndBox(); } else { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayoutOptions.Width(context.KeyWidthOffset)); { var keyProperty = keyValuePairProperty.Children[0]; if (keyValuePairEntry.HasTempInvalidKey) { GUIHelper.PushColor(Color.red); } if (context.AttrSettings.IsReadOnly) { GUIHelper.PushGUIEnabled(false); } GUIHelper.PushIsDrawingDictionaryKey(true); GUIHelper.PushLabelWidth(10); InspectorUtilities.DrawProperty(keyProperty, null); GUIHelper.PopLabelWidth(); GUIHelper.PopIsDrawingDictionaryKey(); if (context.AttrSettings.IsReadOnly) { GUIHelper.PopGUIEnabled(); } if (keyValuePairEntry.HasTempInvalidKey) { GUIHelper.PopColor(); } } GUILayout.EndVertical(); GUILayout.BeginVertical(OneLineMargin); { var valueEntry = keyValuePairProperty.Children[1]; var tmp = GUIHelper.ActualLabelWidth; EditorGUIUtility.labelWidth = 150; InspectorUtilities.DrawProperty(valueEntry, null); EditorGUIUtility.labelWidth = tmp; } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } if (entry.IsEditable && !context.AttrSettings.IsReadOnly && SirenixEditorGUI.IconButton(new Rect(rect.xMax - 24 + 5, rect.y + 2 + ((int)rect.height - 23) / 2, 14, 14), EditorIcons.X)) { context.DictionaryHandler.Remove(context.DictionaryHandler.GetKey(0, i)); EditorApplication.delayCall += () => context.NewKewIsValid = null; GUIHelper.RequestRepaint(); } } SirenixEditorGUI.EndListItem(); } if (context.Paging.IsOnLastPage && entry.ValueState == PropertyValueState.CollectionLengthConflict) { SirenixEditorGUI.BeginListItem(false); GUILayout.Label(GUIHelper.TempContent("------"), EditorStyles.centeredGreyMiniLabel); SirenixEditorGUI.EndListItem(); } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(InspectorProperty property, ToggleAttribute attribute, GUIContent label) { var toggleProperty = property.Children.Get(attribute.ToggleMemberName); if (toggleProperty == null) { AllEditorGUI.ErrorMessageBox(attribute.ToggleMemberName + " is not a member of " + property.Info.MemberInfo.GetNiceName() + "."); } else if (toggleProperty.ValueEntry.TypeOfValue != typeof(bool)) { AllEditorGUI.ErrorMessageBox(attribute.ToggleMemberName + " on " + property.Info.MemberInfo.GetNiceName() + " must be a boolean."); } else { bool isEnabled = (bool)toggleProperty.ValueEntry.WeakSmartValue; var isVisible = property.Context.GetPersistent(this, "isVisible", false); PropertyContext <string> openGroup = null; if (attribute.CollapseOthersOnExpand) { if (property.Parent == null) { //openGroup = GUIHelper.GetTemporaryContext<PropertyContext<string>>(property.Tree); openGroup = property.Context.Get <string>(this, "OpenGroup", (string)null); } else { var parent = (property.Parent.ValueEntry == null || property.Parent.ValueEntry.ValueCategory == PropertyValueCategory.Member) ? property.Parent : property.Parent.Parent; openGroup = parent.Context.GetGlobal <string>("OpenFoldoutToggleGroup", (string)null); } if (openGroup.Value != null && openGroup.Value != property.Path) { isVisible.Value = false; } } bool prev = isVisible.Value; bool visibleBuffer = isVisible.Value; if (AllEditorGUI.BeginToggleGroup(UniqueDrawerKey.Create(property, this), ref isEnabled, ref visibleBuffer, label != null ? label.text : property.Info.MemberInfo.GetNiceName())) { for (int i = 0; i < property.Children.Count; i++) { var child = property.Children[i]; if (child != toggleProperty) { InspectorUtilities.DrawProperty(child); } } } AllEditorGUI.EndToggleGroup(); isVisible.Value = visibleBuffer; if (openGroup != null && prev != isVisible.Value && isVisible.Value) { openGroup.Value = property.Path; } toggleProperty.ValueEntry.WeakSmartValue = isEnabled; } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, TabGroupAttribute attribute, GUIContent label) { var tabGroup = AllEditorGUI.CreateAnimatedTabGroup(property); tabGroup.AnimationSpeed = 1 / AllEditorGUI.TabPageSlideAnimationDuration; tabGroup.FixedHeight = attribute.UseFixedHeight; LocalPersistentContext <int> persistentPageContext = property.Context.GetPersistent(this, "CurrentPage", 0); bool setPersistentPage = false; PropertyContext <List <Tab> > tabs; if (property.Context.Get(this, "Tabs", out tabs)) { setPersistentPage = true; tabs.Value = new List <Tab>(); var addLastTabs = new List <Tab>(); for (int j = 0; j < property.Children.Count; j++) { var child = property.Children[j]; bool added = false; if (child.Info.PropertyType == PropertyType.Group) { var attrType = child.Info.GetAttribute <PropertyGroupAttribute>().GetType(); if (attrType.IsNested && attrType.DeclaringType == typeof(TabGroupAttribute)) { // This is a tab subgroup; add all its children to a tab for that subgroup Tab tab = new Tab(); tab.TabName = child.NiceName; tab.Title = new StringMemberHelper(property.ParentType, child.Name.TrimStart('#')); for (int i = 0; i < child.Children.Count; i++) { tab.InspectorProperties.Add(child.Children[i]); } tabs.Value.Add(tab); added = true; } } if (!added) { // This is a group member of the tab group itself, so it gets its own tab Tab tab = new Tab(); tab.TabName = child.NiceName; tab.Title = new StringMemberHelper(property.ParentType, child.Name.TrimStart('#')); tab.InspectorProperties.Add(child); addLastTabs.Add(tab); } } foreach (var tab in addLastTabs) { tabs.Value.Add(tab); } } for (int i = 0; i < tabs.Value.Count; i++) { tabGroup.RegisterTab(tabs.Value[i].TabName); } if (setPersistentPage) { if (persistentPageContext.Value >= tabs.Value.Count || persistentPageContext.Value < 0) { persistentPageContext.Value = 0; } tabGroup.SetCurrentPage(tabGroup.RegisterTab(tabs.Value[persistentPageContext.Value].TabName)); } AllEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding); tabGroup.BeginGroup(); for (int i = 0; i < tabs.Value.Count; i++) { var page = tabGroup.RegisterTab(tabs.Value[i].TabName); page.Title = tabs.Value[i].Title.GetString(property); if (page.BeginPage()) { persistentPageContext.Value = i; int pageCount = tabs.Value[i].InspectorProperties.Count; for (int j = 0; j < pageCount; j++) { InspectorUtilities.DrawProperty(tabs.Value[i].InspectorProperties[j]); } } page.EndPage(); } tabGroup.EndGroup(); AllEditorGUI.EndIndentedVertical(); }