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 SetVector(InspectorProperty property, Vector3Int value) { property.Tree.DelayActionUntilRepaint(() => { property.ValueEntry.WeakSmartValue = value; }); }
public override bool CanResolveForPropertyFilter(InspectorProperty property) { var type = property.ValueEntry.TypeOfValue; return(type.IsEnum || AtomHandlerLocator.IsMarkedAtomic(type)); }
private void DrawPageSlider(GUIContent label) { try { if (_slider == null) { _slider = new SlidePageNavigationHelper <InspectorProperty>(); _slider.PushPage(Property, Guid.NewGuid().ToString()); _page = _slider.EnumeratePages.Last(); _page.Name = GetLabelText(label); } _currentSlider = _slider; SirenixEditorGUI.BeginBox(); SirenixEditorGUI.BeginToolbarBoxHeader(); { var rect = GUILayoutUtility.GetRect(0, 20); rect.x -= 5; _slider.DrawPageNavigation(rect); } SirenixEditorGUI.EndToolbarBoxHeader(); { _slider.BeginGroup(); foreach (var p in _slider.EnumeratePages) { if (p.BeginPage()) { if (p.Value == Property) { CallNextDrawer(null); } else { _currentDrawingPageProperty = p.Value; if (p.Value.Tree != Property.Tree) { InspectorUtilities.BeginDrawPropertyTree(p.Value.Tree, true); } p.Value.Draw(null); if (p.Value.Tree != Property.Tree) { InspectorUtilities.EndDrawPropertyTree(p.Value.Tree); } _currentDrawingPageProperty = null; } } p.EndPage(); } _slider.EndGroup(); } SirenixEditorGUI.EndBox(); } finally { _currentSlider = null; } }
public override bool CanProcessForProperty(InspectorProperty property) { return(this.GetClassDefinedRequireComponent(property) != null); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(InspectorProperty property, IndentAttribute attribute, GUIContent label) { GUIHelper.PushIndentLevel(EditorGUI.indentLevel + attribute.IndentLevel); this.CallNextDrawer(property, label); GUIHelper.PopIndentLevel(); }
public ArrayIndexGetterSetter(InspectorProperty property, int index) { this.property = property; this.index = index; }
public override bool CanProcessSelfAttributes(InspectorProperty property) { return(false); }
protected override bool CanDrawAttributeProperty(InspectorProperty property) { Node node = property.Tree.WeakTargets[0] as Node; return(node != null); }
string GroupName(InspectorProperty property) => property.NiceName;
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(InspectorProperty property, DisableInEditorModeAttribute attribute, GUIContent label) { GUIHelper.PushGUIEnabled(Application.isPlaying && GUI.enabled); this.CallNextDrawer(property, label); GUIHelper.PopGUIEnabled(); }
virtual protected 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); }
protected override bool CanDrawValueProperty(InspectorProperty property) { return(property.ChildResolver is ICollectionResolver); }
public void ForgetDynamicPort(InspectorProperty property) { throw new System.NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="ListPropertyChildren"/> class. /// </summary> /// <param name="property">The property to handle children for.</param> protected ListPropertyChildren(InspectorProperty property) : base(property) { }
protected override bool CanDrawValueProperty(InspectorProperty property) { return(property.ChildResolver is StrongDictionaryPropertyResolver <TDictionary, TKey, TValue>); }
/// <summary> /// Creates a child property for the given index. /// </summary> /// <param name="index">The index to create a child for.</param> /// <returns> /// The created child. /// </returns> protected override InspectorProperty CreateChild(int index) { return(InspectorProperty.Create(this.Property.Tree, this.Property, null, index)); }
/// <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) { SirenixEditorGUI.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 (SirenixEditorGUI.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(); } SirenixEditorGUI.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(); } }
protected override bool CanDrawValueProperty(InspectorProperty property) { return(base.CanDrawValueProperty(property) && !property.Attributes.HasAttribute <DoNotDrawAsReferenceAttribute>()); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(InspectorProperty property, GUIColorAttribute attribute, GUIContent label) { GUIHelper.PushColor(attribute.Color); this.CallNextDrawer(property, label); GUIHelper.PopColor(); }
protected override bool CanDrawAttributeProperty(InspectorProperty property) { return(!(property.ChildResolver is ICollectionResolver)); }
// Remember to add the OdinDrawer to your custom drawer classes, or they will not be found by Odin. protected override void DrawPropertyGroupLayout(InspectorProperty property, PartyGroupAttribute attribute, GUIContent label) { GUILayout.Space(8f); // Changes the current GUI transform matrix, to make the inspector party. if (Event.current.rawType != EventType.Layout) { Vector3 offset = property.LastDrawnValueRect.position + new Vector2(property.LastDrawnValueRect.width, property.LastDrawnValueRect.height) * 0.5f; Matrix4x4 matrix = Matrix4x4.TRS(offset, Quaternion.identity, Vector3.one) * Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(Mathf.Sin((float)EditorApplication.timeSinceStartup * attribute.Speed) * attribute.Range, Vector3.forward), Vector3.one * (1f + MathUtilities.BounceEaseInFastOut(Mathf.Sin((float)UnityEditor.EditorApplication.timeSinceStartup * 2f)) * 0.1f)) * Matrix4x4.TRS(-offset + new Vector3(Mathf.Sin((float)EditorApplication.timeSinceStartup * 2f), 0f, 0f) * 100f, Quaternion.identity, Vector3.one) * GUI.matrix; GUIHelper.PushMatrix(matrix); } // Changes the party color. if (Event.current.rawType == EventType.Repaint) { var contextBuffer = property.Context.Get <PartyContext>(this, "Color", (PartyContext)null); var context = contextBuffer.Value; if (context == null) { context = new PartyContext() { Start = UnityEngine.Random.ColorHSV(0f, 1f, 0.8f, 1f, 1f, 1f), Target = UnityEngine.Random.ColorHSV(0f, 1f, 0.8f, 1f, 1f, 1f), }; contextBuffer.Value = context; } float t = MathUtilities.Bounce(Mathf.Sin((float)EditorApplication.timeSinceStartup * 2f)); if (t <= 0f) { context.Start = context.Target; context.Target = UnityEngine.Random.ColorHSV(0f, 1f, 0.8f, 1f, 1f, 1f); } GUIHelper.PushColor(Color.Lerp(context.Start, context.Target, t)); } // Draws all the child properties of the group. SirenixEditorGUI.BeginBox(); for (int i = 0; i < property.Children.Count; i++) { property.Children[i].Draw(); } SirenixEditorGUI.EndBox(); // Revert changes to GUI color and matrix. if (Event.current.rawType == EventType.Repaint) { GUIHelper.PopColor(); } if (Event.current.rawType != EventType.Layout) { GUIHelper.PopMatrix(); } // Request a repaint for fluid motion. GUIHelper.RequestRepaint(); GUILayout.Space(8f); }
void IDefinesGenericMenuItems.PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu) { PopulateGenericMenu((IPropertyValueEntry <Color>)property.ValueEntry, genericMenu); }
public void UpdateTable(InspectorProperty property, TableListAttribute attribute, string label) { if (this.Table == null) { this.update = true; } if (this.SwitchView && Event.current.type == EventType.Layout) { this.DrawList.Value = !this.DrawList.Value; this.SwitchView = false; if (!this.DrawList.Value) { this.update = true; } } if (this.Paging.ElementCount != property.Children.Count) { this.update = true; } this.Paging.Update(property.Children.Count); if (!this.update) { return; } this.update = false; this.WasUpdated = true; HashSet <string> seenColumns = new HashSet <string>(); List <InspectorProperty> columnProperties = new List <InspectorProperty>(); for (int i = this.Paging.StartIndex; i < this.Paging.EndIndex; i++) { var listItem = property.Children[i]; if (listItem.Children.Count != 0) { for (int j = 0; j < listItem.Children.Count; j++) { var child = listItem.Children[j]; if (seenColumns.Add(child.Name)) { columnProperties.Add(child); } } } } columnProperties.Sort((a, b) => (a.Info.Order + a.Index * 0.01f).CompareTo(b.Info.Order + b.Index * 0.01f)); var colCount = Mathf.Max(columnProperties.Count + (attribute.IsReadOnly ? 0 : 1), 1); GUITableColumn[] columns = new GUITableColumn[colCount]; for (int i = 0; i < columnProperties.Count; i++) { int columnIndex = i; var p = columnProperties[i]; TableColumnWidthAttribute attr = null; if (p.Info.PropertyType == PropertyType.Group) { attr = EnumerateGroupMembers(p) .Select(c => c.Info.GetAttribute <TableColumnWidthAttribute>()) .FirstOrDefault(x => x != null); } else { attr = p.Info.GetAttribute <TableColumnWidthAttribute>(); } float width = 0; if (attr != null) { width = attr.Width; } columns[i] = new GUITableColumn() { OnGUI = (rect, index) => { var listItem = property.Children[index + this.Paging.StartIndex]; var listItemElement = listItem.Children[p.Name]; if (listItemElement != null) { rect.x = (int)rect.x; // Fixes text flickering GUILayout.BeginArea(rect); var height = EditorGUILayout.BeginVertical(SirenixGUIStyles.OdinEditorWrapper).height + 3; var labelWidth = rect.width * 0.3f; GUIHelper.PushLabelWidth(labelWidth); listItemElement.Draw(null); GUIHelper.PopLabelWidth(); EditorGUILayout.EndVertical(); if (Event.current.type == EventType.Repaint) { var cell = this.Table[columnIndex, index + 2]; if (cell.Height != height) { cell.Height = height; this.Table.MarkDirty(); } } GUILayout.EndArea(); } }, Width = width, ColumnTitle = p.Label == null ? p.NiceName : p.Label.text }; } if (!attribute.IsReadOnly) { columns[columnProperties.Count] = new GUITableColumn() { OnGUI = (rect, index) => { if (Event.current.type == EventType.Repaint) { rect = rect.AlignCenter(14, 14); } if (SirenixEditorGUI.IconButton(rect, EditorIcons.X)) { this.ListChanger.RemoveListElementAt(this.Paging.StartIndex + index, CHANGE_ID); } }, ColumnTitle = "", Width = 20, Resizable = false }; } for (int i = 0; i < columns.Length; i++) { if (columns[i] == null) { columns[i] = new GUITableColumn(); } } this.Table = GUITable.Create(this.Paging.EndIndex - this.Paging.StartIndex, label, columns); this.Table[0, 0].OnGUI = rect => { var fullRect = rect; rect = rect.AlignRight(20); SirenixEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (!attribute.IsReadOnly) { if (SirenixEditorGUI.IconButton(rect.AlignCenter(19, 19), EditorIcons.Plus)) { if (this.ListChanger.ElementType.InheritsFrom <UnityEngine.Object>() && Event.current.modifiers == EventModifiers.Control) { this.ListChanger.AddListElement(new object[this.ListChanger.ValueCount], "Add Unity Null Value"); } else { this.ObjectPicker.ShowObjectPicker( property.Info.GetAttribute <AssetsOnlyAttribute>() == null, rect, property.ValueEntry.SerializationBackend == SerializationBackend.Unity); } } rect.x -= 24; rect.width = 24; SirenixEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (SirenixEditorGUI.IconButton(rect.AlignCenter(23, 23), EditorIcons.List)) { this.SwitchView = true; } rect.x -= 24; } rect.width = 24; SirenixEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (SirenixEditorGUI.IconButton(rect.AlignCenter(20, 20), EditorIcons.Refresh)) { this.update = true; } if (this.Paging.PageCount > 1) { rect.x -= 24; rect.width = 24; SirenixEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (this.Paging.IsOnLastPage) { GUIHelper.PushGUIEnabled(false); } if (SirenixEditorGUI.IconButton(rect.AlignCenter(20, 20), EditorIcons.TriangleRight)) { property.Tree.DelayActionUntilRepaint(() => { this.Paging.CurrentPage++; this.update = true; }); } if (this.Paging.IsOnLastPage) { GUIHelper.PopGUIEnabled(); } rect.x -= 27; rect.width = 27; SirenixEditorGUI.DrawBorders(rect, 1, 0, 0, 0); GUI.Label(rect.AlignMiddle(16), " / " + this.Paging.PageCount); rect.x -= 35; rect.width = 35; SirenixEditorGUI.DrawBorders(rect, 1, 0, 0, 0); EditorGUI.BeginChangeCheck(); this.Paging.CurrentPage = EditorGUI.IntField(rect.HorizontalPadding(4).AlignMiddle(16), this.Paging.CurrentPage + 1) - 1; if (EditorGUI.EndChangeCheck()) { this.update = true; } if (this.Paging.IsOnFirstPage) { GUIHelper.PushGUIEnabled(false); } rect.x -= 24; rect.width = 24; SirenixEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (SirenixEditorGUI.IconButton(rect.AlignCenter(20, 20), EditorIcons.TriangleLeft)) { property.Tree.DelayActionUntilRepaint(() => { this.Paging.CurrentPage--; this.update = true; }); } if (this.Paging.IsOnFirstPage) { GUIHelper.PopGUIEnabled(); } } fullRect.xMax = rect.xMin; GUI.Label(fullRect, this.Paging.ElementCount + " items", SirenixGUIStyles.RightAlignedGreyMiniLabel); GUI.Label(fullRect, label, SirenixGUIStyles.LabelCentered); }; }