Example #1
0
        void ReadGUITable(VBHeader header)
        {
            if (header == null || header.GUITables == null || header.GUITables.Length <= 0)
            {
                return;
            }

            KernelWin.WriteLine("正在处理界面 {0}", typeof(GUITable).Name);

            UInt32 address = (UInt32)header.GUITable;

            for (int i = 0; i < header.GUITables.Length; i++)
            {
                GUITable item = header.GUITables[i];

                String name = "GUITable_" + i.ToString("X2");
                //if(item.FormPointer2!=null&&item.FormPointer2.

                KernelWin.WriteLine("界面 {0}", name);

                UInt32 addr = (UInt32)(item.Address + ImageBase);
                VBStruct.Make <GUITable>(item, address, true);
                Bytes.MakeNameAnyway(addr, name);
            }
        }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        SerializedObject serializedObject = new SerializedObject(LogoTable.Instance);

        List <TableColumn> columns = new List <TableColumn>()
        {
            new TableColumn("G", 28f),
            new TableColumn("U", 22f),
            new TableColumn("I     ", 35f),
        };

        List <List <TableEntry> > rows = new List <List <TableEntry> >();

        LogoTable targetObject = LogoTable.Instance;

        for (int i = 0; i < targetObject.logoLines.Count; i++)
        {
            rows.Add(new List <TableEntry>()
            {
                new PropertyEntry(serializedObject, string.Format("logoLines.Array.data[{0}].letter1", i)),
                new PropertyEntry(serializedObject, string.Format("logoLines.Array.data[{0}].letter2", i)),
                new PropertyEntry(serializedObject, string.Format("logoLines.Array.data[{0}].color", i)),
            });
        }

        tableState = GUITable.DrawTable(columns, rows, tableState);
    }
Example #3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //Check that it is a collection
        Match match = Regex.Match(property.propertyPath, "^([a-zA-Z0-9_]*).Array.data\\[([0-9]*)\\]$");

        if (!match.Success)
        {
            EditorGUI.LabelField(position, label.text, "Use the Table attribute with a collection.");
            return;
        }

        string collectionPath = match.Groups[1].Value;

        // Check that it's the first element
        string index = match.Groups[2].Value;

        if (index != "0")
        {
            return;
        }

        if (GUILayoutUtility.GetLastRect().width > 1f)
        {
            lastRect = GUILayoutUtility.GetLastRect();
        }
        Rect r = new Rect(lastRect.x + 15f, lastRect.y + 35f, lastRect.width, lastRect.height);

        GUILayout.BeginArea(r);
        EditorGUI.indentLevel = 0;
        tableState            = GUITable.DrawTable(property.serializedObject.FindProperty(collectionPath), tableState);
        GUILayout.EndArea();
        GUILayout.Space(30f);
    }
Example #4
0
    void DrawCustomEntries()
    {
        SerializedObject serializedObject = new SerializedObject(SimpleExample.Instance);

        List <TableColumn> columns = new List <TableColumn>()
        {
            new TableColumn("String", 60f),
            new TableColumn("Float", 50f),
            new TableColumn("Object", 110f),
            new TableColumn("", 100f)
            {
                enabledTitle = false
            },
        };

        List <List <TableEntry> > rows = new List <List <TableEntry> >();

        SimpleExample targetObject = (SimpleExample)serializedObject.targetObject;

        for (int i = 0; i < targetObject.simpleObjects.Count; i++)
        {
            SimpleExample.SimpleObject entry = targetObject.simpleObjects[i];
            rows.Add(new List <TableEntry>()
            {
                new LabelEntry(entry.stringProperty),
                new PropertyEntry(serializedObject, string.Format("simpleObjects.Array.data[{0}].floatProperty", i)),
                new PropertyEntry(serializedObject, string.Format("simpleObjects.Array.data[{0}].objectProperty", i)),
                new ActionEntry("Reset", () => entry.Reset()),
            });
        }

        tableState = GUITable.DrawTable(columns, rows, tableState);
    }
Example #5
0
 public static void ShowWindow()
 {
     // Reference to new Window
     window = GetWindow <GUITable>();
     // Set Title & Size
     window.titleContent = new GUIContent("CSV Tool");
     window.minSize      = new Vector2(744, 120);
 }
Example #6
0
    void DrawCustomProperties()
    {
        SerializedObject serializedObject = new SerializedObject(SimpleExample.Instance);

        tableState = GUITable.DrawTable(serializedObject.FindProperty("simpleObjects"), new List <string>()
        {
            "floatProperty", "objectProperty"
        }, tableState);
    }
Example #7
0
    //[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);
    }
    void DrawCustomColumns()
    {
        SerializedObject      serializedObject = new SerializedObject(SimpleExample.Instance);
        List <PropertyColumn> propertyColumns  = new List <PropertyColumn>()
        {
            new PropertyColumn("stringProperty", "String", 60f),
            new PropertyColumn("floatProperty", "Float", 50f)
            {
                optional = true
            },
            new PropertyColumn("objectProperty", "Object", 110f)
            {
                enabledTitle = false, optional = true
            },
        };

        tableState = GUITable.DrawTable(serializedObject.FindProperty("simpleObjects"), propertyColumns, tableState);
    }
    void DrawCustomColumnsWithSelector()
    {
        SerializedObject serializedObject = new SerializedObject(SimpleExample.Instance);

        List <SelectorColumn> selectorColumns = new List <SelectorColumn>()
        {
            new SelectorColumn(prop => new LabelEntry(prop.stringValue), "stringProperty", "String", 60f),
            new SelectorColumn(prop => new LabelEntry(prop.floatValue.ToString()), "floatProperty", "Float", 50f)
            {
                optional = true
            },
            new SelectorColumn(prop => new LabelEntry(prop.objectReferenceValue.name), "objectProperty", "Object", 110f)
            {
                enabledTitle = false, optional = true
            },
        };

        tableState = GUITable.DrawTable(serializedObject.FindProperty("simpleObjects"), selectorColumns, tableState);
    }
        /// <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
            }
                                                            );
        }
 void DrawSimple()
 {
     tableState = GUITable.DrawTable(serializedObject.FindProperty("simpleObjects"), tableState);
 }
Example #13
0
            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);
                };
            }
    void DrawObjectsTable()
    {
        SerializedObject serializedObject = new SerializedObject(AdvancedExample.Instance);

        List <TableColumn> columns = new List <TableColumn>()
        {
            new TableColumn("Name", 60f),
            new TableColumn("Prefab", 50f)
            {
                enabledEntries = false, optional = true
            },
            new TableColumn("Type", 50f)
            {
                optional = true
            },
            new TableColumn("Health", 50f),
            new TableColumn("Speed", 50f),
            new TableColumn("Color", 50f)
            {
                optional = true
            },
            new TableColumn("Can Swim", 30f)
            {
                optional = true
            },
            new TableColumn("Spawners", 450f)
            {
                optional = true
            },
            new TableColumn("Intro (shared by type)", 110f)
            {
                optional = true
            },
            new TableColumn("Instantiation", 110f)
            {
                optional = true
            }
        };

        List <List <TableEntry> > rows = new List <List <TableEntry> >();

        AdvancedExample targetObject = (AdvancedExample)serializedObject.targetObject;

        for (int i = 0; i < targetObject.enemies.Count; i++)
        {
            Enemy enemy         = targetObject.enemies[i];
            int   sentenceIndex = targetObject.introSentences.FindIndex(s => s.enemyType == enemy.type);
            rows.Add(new List <TableEntry>()
            {
                new LabelEntry(enemy.name),
                new PropertyEntry(serializedObject, string.Format("enemies.Array.data[{0}]", i)),
                new PropertyEntry(new SerializedObject(enemy), "type"),
                new PropertyEntry(new SerializedObject(enemy), "health"),
                new PropertyEntry(new SerializedObject(enemy), "speed"),
                new PropertyEntry(new SerializedObject(enemy), "color"),
                new PropertyEntry(new SerializedObject(enemy), "canSwim"),
                new SpawnersEntry(new SerializedObject(enemy), "spawnersMask"),
                new PropertyEntry(serializedObject, string.Format("introSentences.Array.data[{0}].sentence", sentenceIndex)),
                new ActionEntry("Instantiate", () => enemy.Instantiate()),
            });
        }

        tableState = GUITable.DrawTable(columns, rows, tableState);
    }