//[HorizontalGroup] //[Button(ButtonSizes.Large)] private void ShowEntities() { var entities = EntityController.EntitiesArray; _activeEntities.Clear(); foreach (Entity e in entities) { _activeEntities.Add(e); } //_entityTable = GUITable.Create<Entity>(_activeEntities, "Entities"); _entityTable = GUITable.Create(_rows.Length, entities.Max, DrawElement, "Entity Fields", ColumnLabels, "Entities", RowLabels, true); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <TArray> entry, GUIContent label) { TElement[,] value = entry.Values[0] as TElement[, ]; bool rowLengthConflic = false; bool colLengthConflic = false; int colCount = value.GetLength(0); int rowCount = value.GetLength(1); for (int i = 1; i < entry.Values.Count; i++) { var arr = entry.Values[i] as TElement[, ]; colLengthConflic = colLengthConflic || arr.GetLength(0) != colCount; rowLengthConflic = rowLengthConflic || arr.GetLength(1) != rowCount; colCount = Mathf.Min(colCount, arr.GetLength(0)); rowCount = Mathf.Min(rowCount, arr.GetLength(1)); } var context = entry.Context.Get(this, "context", (Context)null); if (context.Value == null || colCount != context.Value.ColCount || rowCount != context.Value.RowCount) { context.Value = new Context(); context.Value.Value = value; context.Value.ColCount = colCount; context.Value.RowCount = rowCount; context.Value.Attribute = entry.Property.Info.GetAttribute <TableMatrixAttribute>() ?? this.GetDefaultTableMatrixAttributeSettings(); if (context.Value.Attribute.DrawElementMethod != null) { string error; var drawElementMethod = entry.ParentType.FindMember() .IsMethod() .IsStatic() .HasReturnType <TElement>() .IsNamed(context.Value.Attribute.DrawElementMethod) .HasParameters <Rect, TElement>() .GetMember <MethodInfo>(out error); if (error != null) { context.Value.ErrorMessage += error + "\n\n"; } else { context.Value.DrawElement = (Func <Rect, TElement, TElement>)Delegate.CreateDelegate(typeof(Func <Rect, TElement, TElement>), drawElementMethod); } } context.Value.HorizontalTitleGetter = new StringMemberHelper(entry.ParentType, context.Value.Attribute.HorizontalTitle); context.Value.VerticalTitleGetter = new StringMemberHelper(entry.ParentType, context.Value.Attribute.VerticalTitle); context.Value.Table = GUITable.Create( Mathf.Max(colCount, 1) + (colLengthConflic ? 1 : 0), Mathf.Max(rowCount, 1) + (rowLengthConflic ? 1 : 0), (rect, x, y) => this.DrawElement(rect, entry, context.Value, x, y), context.Value.HorizontalTitleGetter.GetString(entry), context.Value.Attribute.HideColumnIndices ? (Action <Rect, int>)null : (rect, x) => this.DrawColumn(rect, entry, context.Value, x), context.Value.VerticalTitleGetter.GetString(entry), context.Value.Attribute.HideRowIndices ? (Action <Rect, int>)null : (rect, y) => this.DrawRows(rect, entry, context.Value, y), context.Value.Attribute.ResizableColumns ); if (context.Value.Attribute.RowHeight != 0) { for (int y = 0; y < context.Value.RowCount; y++) { int _y = context.Value.Table.RowCount - 1 - y; for (int x = 0; x < context.Value.Table.ColumnCount; x++) { var cell = context.Value.Table[x, _y]; if (cell != null) { cell.Height = context.Value.Attribute.RowHeight; } } } } if (colLengthConflic) { context.Value.Table[context.Value.Table.ColumnCount - 1, 1].Width = 15; } if (colLengthConflic) { for (int x = 0; x < context.Value.Table.ColumnCount; x++) { context.Value.Table[x, context.Value.Table.RowCount - 1].Height = 15; } } } if (context.Value.Attribute.SquareCells) { SetSquareRowHeights(context); } this.TableMatrixAttribute = context.Value.Attribute; context.Value.Value = value; var prev = EditorGUI.showMixedValue; this.OnBeforeDrawTable(entry, context.Value, label); if (context.Value.ErrorMessage != null) { SirenixEditorGUI.ErrorMessageBox(context.Value.ErrorMessage); } else { try { context.Value.Table.DrawTable(); GUILayout.Space(3); } catch (ExitGUIException ex) { throw ex; } catch (Exception ex) { Debug.LogException(ex); } } EditorGUI.showMixedValue = prev; }
private void RefreshDataTable(bool resetPaging = true) { if (resetPaging) { PagingTable.Collections = this.cachedPlayerEditorData; } var data = PagingTable.GetItems().ToList(); this.guiTablePlayerEditorData = GUITable.Create(data, string.Empty, new GUITableColumn() { ColumnTitle = "Save Key", OnGUI = (rect, i) => { DrawPlayerEditorDataKey(data[i], false, rect); }, }, new GUITableColumn() { ColumnTitle = "Save Data Type", OnGUI = (rect, i) => { DrawPlayerEditorDataBaseType(data[i], false, rect); }, }, new GUITableColumn() { ColumnTitle = "Key Type", OnGUI = (rect, i) => { DrawPlayerEditorDataKeyType(data[i], false, rect); }, }, new GUITableColumn() { ColumnTitle = "Value Type", OnGUI = (rect, i) => { DrawPlayerEditorDataValueType(data[i], false, rect); }, }, new GUITableColumn() { ColumnTitle = "Is Local Only", OnGUI = (rect, i) => { DrawPlayerEditorIsLocalOnly(data[i], false, EditorStyles.miniButtonMid, rect); }, Width = COLUMN_TOGGLE_WIDTH }, new GUITableColumn() { ColumnTitle = "Getter", OnGUI = (rect, i) => { DrawPlayerEditorShouldGenerateGetter(data[i], false, EditorStyles.miniButtonMid, rect); }, Width = COLUMN_TOGGLE_WIDTH }, new GUITableColumn() { ColumnTitle = "Mutator", OnGUI = (rect, i) => { DrawPlayerEditorShouldGenerateMutator(data[i], false, EditorStyles.miniButtonMid, rect); }, Width = COLUMN_TOGGLE_WIDTH }, new GUITableColumn() { ColumnTitle = "Subscribe", OnGUI = (rect, i) => { DrawPlayerEditorShouldGenerateSubscribe(data[i], false, EditorStyles.miniButtonMid, rect); }, Width = COLUMN_TOGGLE_WIDTH }, new GUITableColumn() { ColumnTitle = string.Empty, OnGUI = (rect, i) => { if (GUI.Button(rect, "X")) { cachedPlayerEditorData.RemoveAt(i); RefreshDataTable(false); } }, Width = COLUMN_REMOVE_WIDTH } ); }
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)); GUITableColumn[] columns = new GUITableColumn[columnProperties.Count + 1]; 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 }; } columns[columnProperties.Count] = new GUITableColumn() { OnGUI = (rect, index) => { if (Event.current.type == EventType.Repaint) { rect = rect.AlignCenter(14, 14); } if (AllEditorGUI.IconButton(rect, EditorIcons.X)) { this.ListChanger.RemoveListElementAt(this.Paging.StartIndex + index, CHANGE_ID); } }, ColumnTitle = "", Width = 20, Resizable = false }; 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); AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (AllEditorGUI.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; AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (AllEditorGUI.IconButton(rect.AlignCenter(23, 23), EditorIcons.List)) { this.SwitchView = true; } rect.x -= 24; rect.width = 24; AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (AllEditorGUI.IconButton(rect.AlignCenter(20, 20), EditorIcons.Refresh)) { this.update = true; } if (this.Paging.PageCount > 1) { rect.x -= 24; rect.width = 24; AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (this.Paging.IsOnLastPage) { GUIHelper.PushGUIEnabled(false); } if (AllEditorGUI.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; AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0); GUI.Label(rect.AlignMiddle(16), " / " + this.Paging.PageCount); rect.x -= 35; rect.width = 35; AllEditorGUI.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; AllEditorGUI.DrawBorders(rect, 1, 0, 0, 0); if (AllEditorGUI.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); }; }