Exemplo n.º 1
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();
            strings.Clear();

            StringTable stringTable = InspectedObject as StringTable;

            if (stringTable == null)
            {
                return;
            }

            string[] identifiers = stringTable.Identifiers;
            foreach (var identifier in identifiers)
            {
                strings[identifier] = stringTable.GetString(identifier);
            }

            languageField = new GUIEnumField(typeof(Language));
            languageField.OnSelectionChanged += x =>
            {
                StringTables.ActiveLanguage = (Language)x;
                BuildGUI();
                Refresh();
            };

            Layout.AddElement(languageField);

            valuesField = GUIDictionaryField <string, string, StringTableEntry> .Create(
                new LocEdString("Strings"), strings, Layout);

            valuesField.IsExpanded = Persistent.GetBool("valuesField_Expanded");
            valuesField.OnExpand  += x => Persistent.SetBool("valuesField_Expanded", x);

            valuesField.OnChanged += x =>
            {
                if (x != null)
                {
                    foreach (var KVP in x)
                    {
                        if (stringTable.Contains(KVP.Key))
                        {
                            string oldValue = stringTable.GetString(KVP.Key);
                            if (oldValue != KVP.Value)
                            {
                                stringTable.SetString(KVP.Key, KVP.Value);
                            }
                        }
                        else
                        {
                            stringTable.SetString(KVP.Key, KVP.Value);
                        }
                    }

                    string[] oldIdentifiers = stringTable.Identifiers;
                    foreach (var identifier in oldIdentifiers)
                    {
                        if (!x.ContainsKey(identifier))
                        {
                            stringTable.RemoveString(identifier);
                        }
                    }

                    strings = x;
                }
                else
                {
                    foreach (var KVP in strings)
                    {
                        stringTable.RemoveString(KVP.Key);
                    }

                    strings.Clear();
                }

                EditorApplication.SetDirty(stringTable);
            };

            valuesField.OnValueChanged += x =>
            {
                stringTable.SetString(x, strings[x]);
                EditorApplication.SetDirty(stringTable);
            };

            valuesField.OnValueRemoved += x =>
            {
                stringTable.RemoveString(x);
                EditorApplication.SetDirty(stringTable);
            };

            Layout.AddSpace(10);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();
            styles.Clear();

            GUISkin guiSkin = InspectedObject as GUISkin;

            if (guiSkin == null)
            {
                return;
            }

            string[] styleNames = guiSkin.StyleNames;
            foreach (var styleName in styleNames)
            {
                styles[styleName] = guiSkin.GetStyle(styleName);
            }

            valuesField = GUIDictionaryField <string, GUIElementStyle, GUIElementStyleEntry> .Create
                              (new LocEdString("Styles"), styles, Layout);

            valuesField.IsExpanded = Persistent.GetBool("valuesField_Expanded");
            valuesField.OnExpand  += x => Persistent.SetBool("valuesField_Expanded", x);

            valuesField.OnChanged += x =>
            {
                if (x != null)
                {
                    foreach (var KVP in x)
                    {
                        if (guiSkin.HasStyle(KVP.Key))
                        {
                            GUIElementStyle oldValue = guiSkin.GetStyle(KVP.Key);
                            if (oldValue != KVP.Value)
                            {
                                guiSkin.SetStyle(KVP.Key, KVP.Value);
                            }
                        }
                        else
                        {
                            guiSkin.SetStyle(KVP.Key, KVP.Value);
                        }
                    }

                    string[] oldStyleNames = guiSkin.StyleNames;
                    foreach (var styleName in oldStyleNames)
                    {
                        if (!x.ContainsKey(styleName))
                        {
                            guiSkin.RemoveStyle(styleName);
                        }
                    }

                    styles = x;
                }
                else
                {
                    foreach (var KVP in styles)
                    {
                        guiSkin.RemoveStyle(KVP.Key);
                    }

                    styles.Clear();
                }

                EditorApplication.SetDirty(guiSkin);
            };

            valuesField.OnValueChanged += x =>
            {
                guiSkin.SetStyle(x, styles[x]);
                EditorApplication.SetDirty(guiSkin);
            };

            valuesField.OnValueRemoved += x =>
            {
                guiSkin.RemoveStyle(x);
                EditorApplication.SetDirty(guiSkin);
            };

            Layout.AddSpace(10);
        }