Exemplo n.º 1
0
        private void DrawBody(Rect position, IEditorDictionary dict)
        {
            foreach (KeyValuePair <object, object> entry in dict.GetEntries().ToList())
            {
                position = position.ColumnNext();

                float buttonWidth = ButtonDrawers.ButtonSize.x;
                float columnSize  = (position.width - buttonWidth) / 2;

                Rect[] row = position.SplitRow(columnSize, columnSize, buttonWidth);

                object newKey   = Drawers.Draw(row[0], dict.KeyType, entry.Key);
                object newValue = Drawers.Draw(row[1], dict.ValueType, entry.Value);

                if (newKey != entry.Key || newValue != entry.Value)
                {
                    dict.RemoveEntry(entry.Key);
                    dict.AddEntry(newKey, newValue);
                }

                if (ButtonDrawers.Minus(row[2]))
                {
                    dict.RemoveEntry(newKey);
                }
            }
        }
Exemplo n.º 2
0
        private bool DrawFoldout(Rect position, GUIContent label, IEditorDictionary dict,
                                 object defaultKey, object defaultValue)
        {
            int fieldToken = fieldInfo.MetadataToken;

            if (!Foldouts.ContainsKey(fieldToken))
            {
                Foldouts[fieldToken] = false;
            }

            float buttonWidth = ButtonDrawers.ButtonSize.x;

            Rect[] rects = position.SplitRow(position.width - buttonWidth, buttonWidth);

            bool foldout = EditorGUI.Foldout(rects[0], Foldouts[fieldToken], label);

            if (ButtonDrawers.Plus(rects[1]))
            {
                defaultKey ??= CreateInstance(dict.KeyType);
                defaultValue ??= CreateInstance(dict.ValueType);
                dict.AddEntry(defaultKey, defaultValue);
            }

            return(Foldouts[fieldToken] = foldout);
        }