/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(GUIContent label) { var entry = this.ValueEntry; 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; } } SirenixEditorGUI.BeginHorizontalToolbar(); isVisible.Value = SirenixEditorGUI.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); SirenixEditorGUI.EndHorizontalToolbar(); if (SirenixEditorGUI.BeginFadeGroup(isVisible, isVisible.Value)) { GUIHelper.PushGUIEnabled(false); SirenixEditorGUI.BeginVerticalList(); { var elementLabel = new GUIContent(); for (int i = 0; i < maxCount; i++) { SirenixEditorGUI.BeginListItem(); elementLabel.text = "Item " + i; if (i < minCount) { property.Children[i].Draw(elementLabel); } else { EditorGUILayout.LabelField(elementLabel, SirenixEditorGUI.MixedValueDashChar); } SirenixEditorGUI.EndListItem(); } } SirenixEditorGUI.EndVerticalList(); GUIHelper.PopGUIEnabled(); } SirenixEditorGUI.EndFadeGroup(); }
void DrawListKeyValuePair <K, V>(List <KeyValuePair <K, V> > pairs, ref bool state, string label, Action <K> DrawItem) { #if UNITY_EDITOR SirenixEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding); { SirenixEditorGUI.BeginHorizontalToolbar(); { state = SirenixEditorGUI.Foldout(state, label); GUILayout.FlexibleSpace(); } SirenixEditorGUI.EndHorizontalToolbar(); if (state) { SirenixEditorGUI.BeginVerticalList(false); foreach (var item in pairs) { SirenixEditorGUI.BeginListItem(false); EditorGUILayout.BeginHorizontal(); DrawItem(item.Key); EditorGUILayout.EndHorizontal(); SirenixEditorGUI.EndListItem(); } SirenixEditorGUI.EndVerticalList(); } } SirenixEditorGUI.EndIndentedVertical(); #endif }
/// <summary> /// Not yet documented. /// </summary> protected override void DrawPropertyLayout(GUIContent label) { var entry = this.ValueEntry; var attribute = this.Attribute; var config = entry.Property.Context.Get(this, "Test", (CurrentContext)null); if (config.Value == null) { config.Value = new CurrentContext(); config.Value.Attribute = attribute; config.Value.Tags = attribute.Tags != null?attribute.Tags.Trim().Split(',').Select(i => i.Trim()).ToArray() : null; config.Value.LayerNames = attribute.LayerNames != null?attribute.LayerNames.Trim().Split(',').Select(i => i.Trim()).ToArray() : null; config.Value.Property = entry.Property; if (attribute.Path != null) { var path = attribute.Path.Trim('/', ' '); path = "Assets/" + path + "/"; path = Application.dataPath + "/" + path; config.Value.AssetsFolderLocation = new DirectoryInfo(path); path = attribute.Path.TrimStart('/').TrimEnd('/'); config.Value.PrettyPath = "/" + path.TrimStart('/'); } if (attribute.CustomFilterMethod != null) { MethodInfo methodInfo; string error; if (MemberFinder.Start(entry.ParentType) .IsMethod() .IsNamed(attribute.CustomFilterMethod) .HasReturnType <bool>() .HasParameters <TElement>() .TryGetMember <MethodInfo>(out methodInfo, out error)) { if (methodInfo.IsStatic) { config.Value.StaticCustomIncludeMethod = (Func <TElement, bool>)Delegate.CreateDelegate(typeof(Func <TElement, bool>), methodInfo, true); } else { config.Value.InstanceCustomIncludeMethod = EmitUtilities.CreateWeakInstanceMethodCaller <bool, TElement>(methodInfo); } } config.Value.ErrorMessage = error; } if (config.Value.ErrorMessage != null) { // We can get away with lag on load. config.Value.MaxSearchDurationPrFrameInMS = 20; config.Value.EnsureListPopulation(); config.Value.MaxSearchDurationPrFrameInMS = 1; } } var currentValue = (UnityEngine.Object)entry.WeakSmartValue; if (config.Value.ErrorMessage != null) { SirenixEditorGUI.ErrorMessageBox(config.Value.ErrorMessage); } else { config.Value.EnsureListPopulation(); } SirenixEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding); { SirenixEditorGUI.BeginHorizontalToolbar(); if (label != null) { GUILayout.Label(label); } GUILayout.FlexibleSpace(); if (config.Value.PrettyPath != null) { GUILayout.Label(config.Value.PrettyPath, SirenixGUIStyles.RightAlignedGreyMiniLabel); SirenixEditorGUI.VerticalLineSeparator(); } if (config.Value.IsPopulated) { GUILayout.Label(config.Value.AvailableAsset.Count + " items", SirenixGUIStyles.RightAlignedGreyMiniLabel); GUIHelper.PushGUIEnabled(GUI.enabled && (config.Value.AvailableAsset.Count > 0 && config.Value.ErrorMessage == null)); } else { GUILayout.Label("Scanning " + config.Value.CurrentSearchingIndex + " / " + config.Value.NumberOfResultsToSearch, SirenixGUIStyles.RightAlignedGreyMiniLabel); GUIHelper.PushGUIEnabled(false); } SirenixEditorGUI.VerticalLineSeparator(); bool drawConflict = entry.Property.ParentValues.Count > 1; if (drawConflict == false) { var index = config.Value.AvailableAsset.IndexOf(currentValue) + 1; if (index > 0) { GUILayout.Label(index.ToString(), SirenixGUIStyles.RightAlignedGreyMiniLabel); } else { drawConflict = true; } } if (drawConflict) { GUILayout.Label("-", SirenixGUIStyles.RightAlignedGreyMiniLabel); } if (SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleLeft) && config.Value.IsPopulated) { var index = config.Value.AvailableAsset.IndexOf(currentValue) - 1; index = index < 0 ? config.Value.AvailableAsset.Count - 1 : index; entry.WeakSmartValue = config.Value.AvailableAsset[index]; } if (SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleDown) && config.Value.IsPopulated) { GenericMenu m = new GenericMenu(); var selected = currentValue; int itemsPrPage = 40; bool showPages = config.Value.AvailableAsset.Count > 50; string page = ""; int selectedPage = (config.Value.AvailableAsset.IndexOf(entry.WeakSmartValue as UnityEngine.Object) / itemsPrPage); for (int i = 0; i < config.Value.AvailableAsset.Count; i++) { var obj = config.Value.AvailableAsset[i]; if (obj != null) { var path = AssetDatabase.GetAssetPath(obj); var name = string.IsNullOrEmpty(path) ? obj.name : path.Substring(7).Replace("/", "\\"); var localEntry = entry; if (showPages) { var p = (i / itemsPrPage); page = (p * itemsPrPage) + " - " + Mathf.Min(((p + 1) * itemsPrPage), config.Value.AvailableAsset.Count - 1); if (selectedPage == p) { page += " (contains selected)"; } page += "/"; } m.AddItem(new GUIContent(page + name), obj == selected, () => { localEntry.Property.Tree.DelayActionUntilRepaint(() => localEntry.WeakSmartValue = obj); }); } } m.ShowAsContext(); } if (SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleRight) && config.Value.IsPopulated) { var index = config.Value.AvailableAsset.IndexOf(currentValue) + 1; entry.WeakSmartValue = config.Value.AvailableAsset[index % config.Value.AvailableAsset.Count]; } GUIHelper.PopGUIEnabled(); SirenixEditorGUI.EndHorizontalToolbar(); SirenixEditorGUI.BeginVerticalList(); SirenixEditorGUI.BeginListItem(false, padding); this.CallNextDrawer(null); SirenixEditorGUI.EndListItem(); SirenixEditorGUI.EndVerticalList(); } SirenixEditorGUI.EndIndentedVertical(); }
public void DrawMenu() { if (this.GameObject == null) { return; } if (!this.IsIncluded) { return; } GUIHelper.PushGUIEnabled(GUI.enabled && this.ErrorCount + this.WarningCount > 0); var rect = SirenixEditorGUI.BeginListItem(true); { if (Event.current.rawType == EventType.MouseDown && rect.Contains(Event.current.mousePosition)) { if (this.IsSelected || this.Behaviour == null) { EditorGUIUtility.PingObject(this.GameObject); } this.Select(); GUIHelper.RequestRepaint(); } if (this.IsSelected) { GUIHelper.PushGUIEnabled(true); SirenixEditorGUI.DrawSolidRect(rect, SirenixGUIStyles.MenuButtonActiveBgColor); GUIHelper.PushLabelColor(Color.white); EditorGUILayout.LabelField(this.Name); GUIHelper.PopLabelColor(); GUIHelper.PopGUIEnabled(); } else { EditorGUILayout.LabelField(this.Name); } rect = new Rect(rect.position, new Vector2(20, 20)); rect.x += 6; const float offAlpha = 0.1f; var tmpColor = GUI.color; GUI.color = this.WarningCount > 0 ? Color.white : new Color(1, 1, 1, offAlpha); //GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; GUI.DrawTexture(rect, EditorIcons.UnityWarningIcon); rect.x += 20; GUI.color = this.ErrorCount > 0 ? Color.white : new Color(1, 1, 1, offAlpha); GUI.DrawTexture(rect, EditorIcons.UnityErrorIcon); if (this.IsIncluded && this.ErrorCount == 0 && this.WarningCount == 0) { rect.x -= 10; GUI.color = (this.ErrorCount + this.WarningCount) == 0 ? Color.green : new Color(0, 1, 0, offAlpha); GUI.DrawTexture(rect, EditorIcons.Checkmark.Highlighted); } //GL.sRGBWrite = false; GUI.color = tmpColor; } SirenixEditorGUI.EndListItem(); GUIHelper.PopGUIEnabled(); }
private Rect DrawItem(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.RemoveBtnRect = new Rect(listItemInfo.Value.DragHandleRect.x + rect.width - 22, listItemInfo.Value.DragHandleRect.y + 1, 14, 14); if (info.HideRemoveButton == false) { } if (info.Draggable) { GUI.Label(listItemInfo.Value.DragHandleRect, EditorIcons.List.Inactive, GUIStyle.none); } } 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); } itemProperty.Draw(label); if (info.OnEndListElementGUI != null) { info.OnEndListElementGUI(info.Property.ParentValues[0], index); } GUIHelper.PopHierarchyMode(); if (info.IsReadOnly == false && info.HideRemoveButton == false) { if (SirenixEditorGUI.IconButton(listItemInfo.Value.RemoveBtnRect, EditorIcons.X)) { if (info.OrderedCollectionResolver != null) { if (index >= 0) { info.RemoveAt = index; } } else { var values = new object[itemProperty.ValueEntry.ValueCount]; for (int i = 0; i < values.Length; i++) { values[i] = itemProperty.ValueEntry.WeakValues[i]; } info.RemoveValues = values; } } } } SirenixEditorGUI.EndListItem(); return(rect); }
private void DrawItems() { int from = 0; int to = info.Count; bool paging = info.CustomListDrawerOptions.PagingHasValue ? info.CustomListDrawerOptions.ShowPaging : true; if (paging && info.ShowAllWhilePaging == false) { from = Mathf.Clamp(info.StartIndex, 0, info.Count); to = Mathf.Clamp(info.EndIndex, 0, info.Count); } var drawEmptySpace = info.DropZone != null && info.DropZone.IsBeingHovered || info.IsDroppingUnityObjects; float height = drawEmptySpace ? info.IsDroppingUnityObjects ? 16 : (DragAndDropManager.CurrentDraggingHandle.Rect.height - 3) : 0; var rect = SirenixEditorGUI.BeginVerticalList(); { for (int i = 0, j = from, k = from; j < to; i++, j++) { var dragHandle = this.BeginDragHandle(j, i); { if (drawEmptySpace) { var topHalf = dragHandle.Rect; topHalf.height /= 2; if (topHalf.Contains(info.LayoutMousePosition) || topHalf.y > info.LayoutMousePosition.y && i == 0) { GUILayout.Space(height); drawEmptySpace = false; info.InsertAt = k; } } if (dragHandle.IsDragging == false) { k++; this.DrawItem(info.Property.Children[j], dragHandle, j); } else { GUILayout.Space(3); CollectionDrawerStaticInfo.DelayedGUIDrawer.Begin(dragHandle.Rect.width, dragHandle.Rect.height, dragHandle.CurrentMethod != DragAndDropMethods.Move); DragAndDropManager.AllowDrop = false; this.DrawItem(info.Property.Children[j], dragHandle, j); DragAndDropManager.AllowDrop = true; CollectionDrawerStaticInfo.DelayedGUIDrawer.End(); if (dragHandle.CurrentMethod != DragAndDropMethods.Move) { GUILayout.Space(3); } } if (drawEmptySpace) { var bottomHalf = dragHandle.Rect; bottomHalf.height /= 2; bottomHalf.y += bottomHalf.height; if (bottomHalf.Contains(info.LayoutMousePosition) || bottomHalf.yMax < info.LayoutMousePosition.y && j + 1 == to) { GUILayout.Space(height); drawEmptySpace = false; info.InsertAt = Mathf.Min(k, to); } } } this.EndDragHandle(i); } if (drawEmptySpace) { GUILayout.Space(height); info.InsertAt = Event.current.mousePosition.y > rect.center.y ? to : from; } if (to == info.Property.Children.Count && info.Property.ValueEntry.ValueState == PropertyValueState.CollectionLengthConflict) { SirenixEditorGUI.BeginListItem(false); GUILayout.Label(GUIHelper.TempContent("------"), EditorStyles.centeredGreyMiniLabel); SirenixEditorGUI.EndListItem(); } } SirenixEditorGUI.EndVerticalList(); if (Event.current.type == EventType.Repaint) { info.LayoutMousePosition = Event.current.mousePosition; } }
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); }
private void DrawElements(IPropertyValueEntry <TDictionary> entry, GUIContent label) { for (int i = this.paging.StartIndex; i < this.paging.EndIndex; i++) { var keyValuePairProperty = entry.Property.Children[i]; var keyValuePairValue = (keyValuePairProperty.ValueEntry as IPropertyValueEntry <EditableKeyValuePair <TKey, TValue> >).SmartValue; Rect rect = SirenixEditorGUI.BeginListItem(false, listItemStyle); { if (this.attrSettings.DisplayMode != DictionaryDisplayOptions.OneLine) { bool defaultExpanded; switch (this.attrSettings.DisplayMode) { case DictionaryDisplayOptions.CollapsedFoldout: defaultExpanded = false; break; case DictionaryDisplayOptions.ExpandedFoldout: defaultExpanded = true; break; default: defaultExpanded = SirenixEditorGUI.ExpandFoldoutByDefault; break; } var isExpanded = keyValuePairProperty.Context.GetPersistent(this, "Expanded", defaultExpanded); SirenixEditorGUI.BeginBox(); SirenixEditorGUI.BeginToolbarBoxHeader(); { if (keyValuePairValue.IsInvalidKey) { GUIHelper.PushColor(Color.red); } var btnRect = GUIHelper.GetCurrentLayoutRect().AlignLeft(HeaderMargin.margin.left); btnRect.y += 1; GUILayout.BeginVertical(HeaderMargin); GUIHelper.PushIsDrawingDictionaryKey(true); GUIHelper.PushLabelWidth(this.keyLabelWidth); var keyProperty = keyValuePairProperty.Children[0]; var keyLabel = GUIHelper.TempContent(" "); DrawKeyProperty(keyProperty, keyLabel); GUIHelper.PopLabelWidth(); GUIHelper.PopIsDrawingDictionaryKey(); GUILayout.EndVertical(); if (keyValuePairValue.IsInvalidKey) { GUIHelper.PopColor(); } isExpanded.Value = SirenixEditorGUI.Foldout(btnRect, isExpanded.Value, this.keyLabel); } SirenixEditorGUI.EndToolbarBoxHeader(); if (SirenixEditorGUI.BeginFadeGroup(isExpanded, isExpanded.Value)) { keyValuePairProperty.Children[1].Draw(null); } SirenixEditorGUI.EndFadeGroup(); SirenixEditorGUI.EndToolbarBox(); } else { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayoutOptions.Width(this.keyWidthOffset)); { var keyProperty = keyValuePairProperty.Children[0]; if (keyValuePairValue.IsInvalidKey) { GUIHelper.PushColor(Color.red); } if (this.attrSettings.IsReadOnly) { GUIHelper.PushGUIEnabled(false); } GUIHelper.PushIsDrawingDictionaryKey(true); GUIHelper.PushLabelWidth(10); DrawKeyProperty(keyProperty, null); GUIHelper.PopLabelWidth(); GUIHelper.PopIsDrawingDictionaryKey(); if (this.attrSettings.IsReadOnly) { GUIHelper.PopGUIEnabled(); } if (keyValuePairValue.IsInvalidKey) { GUIHelper.PopColor(); } } GUILayout.EndVertical(); GUILayout.BeginVertical(OneLineMargin); { GUIHelper.PushHierarchyMode(false); var valueEntry = keyValuePairProperty.Children[1]; var tmp = GUIHelper.ActualLabelWidth; GUIHelper.BetterLabelWidth = 150; valueEntry.Draw(null); GUIHelper.BetterLabelWidth = tmp; GUIHelper.PopHierarchyMode(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } if (entry.IsEditable && !this.attrSettings.IsReadOnly && SirenixEditorGUI.IconButton(new Rect(rect.xMax - 24 + 5, rect.y + 4 + ((int)rect.height - 23) / 2, 14, 14), EditorIcons.X)) { this.dictionaryResolver.QueueRemoveKey(Enumerable.Range(0, entry.ValueCount).Select(n => this.dictionaryResolver.GetKey(n, i)).ToArray()); EditorApplication.delayCall += () => this.newKeyIsValid = null; GUIHelper.RequestRepaint(); } } SirenixEditorGUI.EndListItem(); } if (this.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(GUIContent label) { var entry = this.ValueEntry; this.dictionaryResolver = entry.Property.ChildResolver as StrongDictionaryPropertyResolver <TDictionary, TKey, TValue>; this.config = GeneralDrawerConfig.Instance; this.paging.NumberOfItemsPerPage = this.config.NumberOfItemsPrPage; listItemStyle.padding.right = !entry.IsEditable || this.attrSettings.IsReadOnly ? 4 : 20; SirenixEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding); { this.paging.Update(elementCount: entry.Property.Children.Count); this.DrawToolbar(entry); this.paging.Update(elementCount: entry.Property.Children.Count); if (!this.disableAddKey && this.attrSettings.IsReadOnly == false) { this.DrawAddKey(entry); } float t; GUIHelper.BeginLayoutMeasuring(); if (SirenixEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry.Property, this), this.toggled.Value, out t)) { var rect = SirenixEditorGUI.BeginVerticalList(false); if (this.attrSettings.DisplayMode == DictionaryDisplayOptions.OneLine) { var maxWidth = rect.width - 90; rect.xMin = this.keyWidthOffset + 22; rect.xMax = rect.xMin + 10; this.keyWidthOffset = this.keyWidthOffset + SirenixEditorGUI.SlideRect(rect).x; if (Event.current.type == EventType.Repaint) { this.keyWidthOffset = Mathf.Clamp(this.keyWidthOffset, 90, maxWidth); } if (this.paging.ElementCount != 0) { var headerRect = SirenixEditorGUI.BeginListItem(false); { GUILayout.Space(14); if (Event.current.type == EventType.Repaint) { GUI.Label(headerRect.SetWidth(this.keyWidthOffset), this.keyLabel, SirenixGUIStyles.LabelCentered); GUI.Label(headerRect.AddXMin(this.keyWidthOffset), this.valueLabel, SirenixGUIStyles.LabelCentered); SirenixEditorGUI.DrawSolidRect(headerRect.AlignBottom(1), SirenixGUIStyles.BorderColor); } } SirenixEditorGUI.EndListItem(); } } GUIHelper.PushHierarchyMode(false); this.DrawElements(entry, label); GUIHelper.PopHierarchyMode(); SirenixEditorGUI.EndVerticalList(); } SirenixEditorGUI.EndFadeGroup(); // Draw borders var outerRect = GUIHelper.EndLayoutMeasuring(); if (t > 0.01f && Event.current.type == EventType.Repaint) { Color col = SirenixGUIStyles.BorderColor; outerRect.yMin -= 1; SirenixEditorGUI.DrawBorders(outerRect, 1, col); col.a *= t; if (this.attrSettings.DisplayMode == DictionaryDisplayOptions.OneLine) { // Draw Slide Rect Border outerRect.width = 1; outerRect.x += this.keyWidthOffset + 13; SirenixEditorGUI.DrawSolidRect(outerRect, col); } } } SirenixEditorGUI.EndIndentedVertical(); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <TDictionary> entry, GUIContent label) { var context = entry.Property.Context.Get(this, "context", (Context)null); if (context.Value == null) { context.Value = new Context(); context.Value.Toggled = entry.Context.GetPersistent(this, "Toggled", GeneralDrawerConfig.Instance.OpenListsByDefault); context.Value.KeyWidthOffset = 130; context.Value.Label = label ?? new GUIContent(typeof(TDictionary).GetNiceName()); context.Value.AttrSettings = entry.Property.Info.GetAttribute <DictionaryDrawerSettings>() ?? new DictionaryDrawerSettings(); context.Value.DisableAddKey = entry.Property.Tree.HasPrefabs && !entry.GetDictionaryHandler().SupportsPrefabModifications; if (!context.Value.DisableAddKey) { context.Value.TempKeyValue = new TempKeyValue(); var tree = PropertyTree.Create(context.Value.TempKeyValue); tree.UpdateTree(); context.Value.TempKeyEntry = (IPropertyValueEntry <TKey>)tree.GetPropertyAtPath("Key").ValueEntry; context.Value.TempValueEntry = (IPropertyValueEntry <TValue>)tree.GetPropertyAtPath("Value").ValueEntry; } } context.Value.DictionaryHandler = (DictionaryHandler <TDictionary, TKey, TValue>)entry.GetDictionaryHandler(); context.Value.Config = GeneralDrawerConfig.Instance; context.Value.Paging.NumberOfItemsPerPage = context.Value.Config.NumberOfItemsPrPage; context.Value.ListItemStyle.padding.right = !entry.IsEditable || context.Value.AttrSettings.IsReadOnly ? 4 : 20; //if (!IsSupportedKeyType) //{ // var message = entry.Property.Context.Get(this, "error_message", (string)null); // var detailedMessage = entry.Property.Context.Get(this, "error_message_detailed", (string)null); // var folded = entry.Property.Context.Get(this, "error_message_folded", true); // if (message.Value == null) // { // string str = ""; // if (label != null) // { // str += label.text + "\n\n"; // } // str += "The dictionary key type '" + typeof(TKey).GetNiceFullName() + "' is not supported in prefab instances. Expand this box to see which key types are supported."; // message.Value = str; // } // if (detailedMessage.Value == null) // { // var sb = new StringBuilder("The following key types are supported:"); // sb.AppendLine() // .AppendLine(); // foreach (var type in DictionaryKeyUtility.GetPersistentPathKeyTypes()) // { // sb.AppendLine(type.GetNiceName()); // } // sb.AppendLine("Enums of any type"); // detailedMessage.Value = sb.ToString(); // } // folded.Value = SirenixEditorGUI.DetailedMessageBox(message.Value, detailedMessage.Value, MessageType.Error, folded.Value); // return; //} SirenixEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding); { context.Value.Paging.Update(elementCount: entry.Property.Children.Count); this.DrawToolbar(entry, context.Value); context.Value.Paging.Update(elementCount: entry.Property.Children.Count); if (!context.Value.DisableAddKey && context.Value.AttrSettings.IsReadOnly == false) { this.DrawAddKey(entry, context.Value); } float t; GUIHelper.BeginLayoutMeasuring(); if (SirenixEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry.Property, this), context.Value.Toggled.Value, out t)) { var rect = SirenixEditorGUI.BeginVerticalList(false); if (context.Value.AttrSettings.DisplayMode == DictionaryDisplayOptions.OneLine) { var maxWidth = rect.width - 90; rect.xMin = context.Value.KeyWidthOffset + 22; rect.xMax = rect.xMin + 10; context.Value.KeyWidthOffset = context.Value.KeyWidthOffset + SirenixEditorGUI.SlideRect(rect).x; if (Event.current.type == EventType.Repaint) { context.Value.KeyWidthOffset = Mathf.Clamp(context.Value.KeyWidthOffset, 90, maxWidth); } if (context.Value.Paging.ElementCount != 0) { var headerRect = SirenixEditorGUI.BeginListItem(false); { GUILayout.Space(14); if (Event.current.type == EventType.Repaint) { GUI.Label(headerRect.SetWidth(context.Value.KeyWidthOffset), context.Value.AttrSettings.KeyLabel, SirenixGUIStyles.LabelCentered); GUI.Label(headerRect.AddXMin(context.Value.KeyWidthOffset), context.Value.AttrSettings.ValueLabel, SirenixGUIStyles.LabelCentered); SirenixEditorGUI.DrawSolidRect(headerRect.AlignBottom(1), SirenixGUIStyles.BorderColor); } } SirenixEditorGUI.EndListItem(); } } this.DrawElements(entry, label, context.Value); SirenixEditorGUI.EndVerticalList(); } SirenixEditorGUI.EndFadeGroup(); // Draw borders var outerRect = GUIHelper.EndLayoutMeasuring(); if (t > 0.01f && Event.current.type == EventType.Repaint) { Color col = SirenixGUIStyles.BorderColor; outerRect.yMin -= 1; SirenixEditorGUI.DrawBorders(outerRect, 1, col); col.a *= t; if (context.Value.AttrSettings.DisplayMode == DictionaryDisplayOptions.OneLine) { // Draw Slide Rect Border outerRect.width = 1; outerRect.x += context.Value.KeyWidthOffset + 13; SirenixEditorGUI.DrawSolidRect(outerRect, col); } } } SirenixEditorGUI.EndIndentedVertical(); }
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(); } }
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; SirenixEditorGUI.BeginListItem(); { SirenixEditorGUI.BeginIndentedHorizontal(); SirenixEditorGUI.IconButton(EditorIcons.Transparent, IconStyle, 16); if (typeToDraw.PreExistingEditorType != null) { SirenixEditorGUI.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!"); } } SirenixEditorGUI.EndIndentedHorizontal(); EditorGUI.showMixedValue = false; } SirenixEditorGUI.EndListItem(); }
private void DrawTypeGroup(TypeGroup typeGroup, IPropertyValueEntry <InspectorTypeDrawingConfig> entry, string searchText) { if (!typeGroup.IsSearchVisible) { return; } bool useToggle = true; var rect = SirenixEditorGUI.BeginListItem(); { bool toggleExpansion = false; SirenixEditorGUI.BeginIndentedHorizontal(); { EditorIcon icon = (typeGroup.IsExpanded || !searchText.IsNullOrWhitespace()) ? EditorIcons.TriangleDown : EditorIcons.TriangleRight; toggleExpansion = SirenixEditorGUI.IconButton(icon, IconStyle, 16); if (!typeGroup.HasEligibleTypes) { toggleExpansion |= SirenixEditorGUI.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); } SirenixEditorGUI.EndIndentedHorizontal(); if (toggleExpansion || (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))) { typeGroup.IsExpanded = !typeGroup.IsExpanded; Event.current.Use(); } } SirenixEditorGUI.EndListItem(); if (SirenixEditorGUI.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--; } SirenixEditorGUI.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) { SirenixEditorGUI.BeginListItem(); { SirenixEditorGUI.BeginIndentedHorizontal(); { GUIHelper.PushGUIEnabled(false); { SirenixEditorGUI.IconButton(EditorIcons.TriangleRight, IconStyle, 16); GUILayoutUtility.GetRect(16, 16, EditorStyles.toggle, GUILayoutOptions.ExpandWidth(false).Width(16)); GUILayout.Label(typeGroup.Name); } GUIHelper.PopGUIEnabled(); } SirenixEditorGUI.EndIndentedHorizontal(); } SirenixEditorGUI.EndListItem(); } else { bool useToggle = true; var rect = SirenixEditorGUI.BeginListItem(); { bool toggleExpansion = false; SirenixEditorGUI.BeginIndentedHorizontal(); { EditorIcon icon = (typeGroup.IsExpanded || !searchText.IsNullOrWhitespace()) ? EditorIcons.TriangleDown : EditorIcons.TriangleRight; toggleExpansion = SirenixEditorGUI.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); } SirenixEditorGUI.EndIndentedHorizontal(); if (toggleExpansion || (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))) { typeGroup.IsExpanded = !typeGroup.IsExpanded; Event.current.Use(); } } SirenixEditorGUI.EndListItem(); if (SirenixEditorGUI.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--; } SirenixEditorGUI.EndFadeGroup(); } }