예제 #1
0
        protected virtual void DrawSettings(bool isBase)
        {
            List <QuickSetting> settings = isBase ? QuickPlayerPrefs.GetSettingsBase() : QuickPlayerPrefs.GetSettingsCustom();

            if (settings.Count == 0)
            {
                return;
            }

            EditorGUI.indentLevel++;

            //Draw the "Name Value" column
            GUILayout.BeginVertical();
            EditorGUILayout.LabelField("Name", "Value");
            foreach (QuickSetting s in settings)
            {
                GUILayout.BeginHorizontal();
                string key      = s.GetKey();
                string typeName = s.GetTypeName();
                QuickPlayerPrefs.SetValue(key, DrawPlayerPref(key, typeName));
                if (!isBase)
                {
                    if (QuickBaseEditor.DrawButton("-", GUILayout.Width(32)))
                    {
                        QuickPlayerPrefs.DeleteSetting(key);
                        break;
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();

            EditorGUI.indentLevel--;
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            QuickBaseEditor.DrawHorizontalLine();

            ScriptableObject obj = (ScriptableObject)target;

            if (QuickBaseEditor.DrawButton("Save To XML"))
            {
                obj.SaveToXml(EditorUtility.SaveFilePanel("Save Asset to XML", "", target.name + ".xml", "xml"));
            }
            if (QuickBaseEditor.DrawButton("Load From XML"))
            {
                obj.LoadFromXml(EditorUtility.OpenFilePanel("Load Asset from XML", "", "xml"));
            }
        }
예제 #3
0
        protected virtual void DrawNewSettingsArea(GUILayoutOption[] options)
        {
            _showNewSetting = EditorGUILayout.Foldout(_showNewSetting, "New Setting");
            if (_showNewSetting)
            {
                EditorGUI.indentLevel++;

                _newSettingKey  = EditorGUILayout.TextField("Key: ", _newSettingKey, options);
                _newSettingType = (PrefType)EditorGUILayout.EnumPopup("Type: ", _newSettingType, options);
                if (_newSettingType == PrefType.Enum)
                {
                    _newSettingTypeEnum = EditorGUILayout.TextField("Enum Type: ", _newSettingTypeEnum, options);
                }

                EditorGUI.indentLevel--;

                if (QuickBaseEditor.DrawButton("Create New Setting", options))
                {
                    object value = null;
                    if (_newSettingKey.Length == 0)
                    {
                        EditorUtility.DisplayDialog("New Setting Creation Error", "The Key string cannot be empty", "Ok");
                    }
                    else if (QuickPlayerPrefs.HasKey(_newSettingKey))
                    {
                        EditorUtility.DisplayDialog("New Setting Creation Error", "The Key " + _newSettingKey + " already exists", "Ok");
                    }
                    else if (CreateNewSetting(out value))
                    {
                        QuickPlayerPrefs.SetValue(_newSettingKey, value);
                        _newSettingKey  = _newSettingTypeEnum = "";
                        _newSettingType = PrefType.String;
                    }
                }
            }
        }
예제 #4
0
        protected virtual void OnGUI()
        {
            if (!QuickPlayerPrefs.GetSettingsAsset())
            {
                QuickPlayerPrefs.Init();
            }

            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);

            titleContent.text = "PlayerPrefs";

            GUILayoutOption[] options = { GUILayout.Width(256) };

            EditorGUILayout.BeginVertical("box");
            DrawNewSettingsArea(options);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("box");
            _showBaseSettings = EditorGUILayout.Foldout(_showBaseSettings, "Base Settings");
            if (_showBaseSettings)
            {
                DrawSettings(true);
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("box");
            _showCustomSettings = EditorGUILayout.Foldout(_showCustomSettings, "Custom Settings");
            if (_showCustomSettings)
            {
                DrawSettings(false);
            }
            EditorGUILayout.EndVertical();

            //if (QuickBaseEditor.DrawButton("Clear Custom Settings", options))
            //{
            //    if (EditorUtility.DisplayDialog("Clear Custom Settings", "This will remove all the defined Custom Settings. Are you sure?", "Yes", "No"))
            //    {
            //        QuickPlayerPrefs.ClearSettingsCustom();
            //    }
            //}

            //QuickBaseEditor.DrawHorizontalLine();

            EditorGUILayout.BeginVertical("box");
            _customSettingsScriptName = EditorGUILayout.TextField("Custom Settings Script: ", _customSettingsScriptName, options);
            List <QuickSetting> customSettings = QuickPlayerPrefs.GetSettingsCustom();
            List <string>       keys           = new List <string>();

            foreach (QuickSetting s in customSettings)
            {
                keys.Add(s.GetKey());
            }

            if (QuickBaseEditor.DrawButton("Create Custom Settings Script", options))
            {
                CreateSettingsScript(_customSettingsScriptName, keys);
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.EndScrollView();
        }