private void Draw(PrefsPair pair)
        {
            if (!string.IsNullOrEmpty(searchFilter) && !pair.key.Contains(searchFilter)) return;

            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            Field(pair);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();
        }
        private void Field(PrefsPair pair)
        {
            GUIStyle baseStyle = new GUIStyle(GUI.skin.textField);
            if (pair.IsDirty)
                baseStyle.fontStyle = FontStyle.Bold;

            GUIStyle typeStyle = new GUIStyle(GUI.skin.label);

            //EditorGUILayout.Space();
            string keyFocusName = "keyControlName";
            GUI.SetNextControlName(keyFocusName);
            pair.key = EditorGUILayout.TextField(pair.key, baseStyle, GUILayout.Width(250));
            EditorGUILayout.Space();

            if (pair.Type == typeof(int))
            {
                typeStyle.normal.textColor = Color.blue;
                GUILayout.Label("int", typeStyle, GUILayout.MaxWidth(45));
                pair.value = (int)EditorGUILayout.IntField(pair.Value<int>(), baseStyle, GUILayout.Width(150));
            }
            else if (pair.Type == typeof(float))
            {
                typeStyle.normal.textColor = Color.blue;
                GUILayout.Label("float", typeStyle, GUILayout.MaxWidth(45));
                pair.value = (float)EditorGUILayout.FloatField(pair.Value<float>(), baseStyle, GUILayout.Width(150));
            }
            else if (pair.Type == typeof(string))
            {
                typeStyle.normal.textColor = Color.red;
                GUILayout.Label("string", typeStyle, GUILayout.MaxWidth(45));
                pair.value = (string)EditorGUILayout.TextField(pair.Value<string>(), baseStyle, GUILayout.Width(150));
            }
            EditorGUILayout.Space();

            cachedContent = EditorGUIUtility.IconContent("Grid.EraserTool");
            cachedContent.tooltip = "Restore the default state";
            if (GUILayout.Button(cachedContent, GUILayout.Height(20), GUILayout.Width(35)))
            {
                pair.ResetToDiskState();
                GUI.FocusControl(null);
            }

            cachedContent = EditorGUIUtility.IconContent("SaveActive");
            cachedContent.tooltip = "Save this preference on disk";
            if (GUILayout.Button(cachedContent, GUILayout.Height(20), GUILayout.Width(35)))
            {
                GUI.FocusControl(null);
                pair.SaveOnPrefs(true, delegate { EditorUtility.DisplayDialog("ERROR", "Set a key for the selected value", "Continue"); EditorGUI.FocusTextInControl(keyFocusName); });
            }

            Color c = GUI.backgroundColor;
            GUI.backgroundColor = new Color(1f, 0, 0, 0.6f);
            cachedContent = EditorGUIUtility.IconContent("d_P4_DeletedLocal");
            cachedContent.tooltip = "Delete this preference from disk";
            if (GUILayout.Button(cachedContent, GUILayout.Height(20), GUILayout.Width(35)))
            {
                pair.DeleteFromPrefs();
                GUI.FocusControl(null);
                isCollectionDirty = true;
            }
            GUI.backgroundColor = c;
        }
示例#3
0
        public void AddPref(string key, object value)
        {
            PrefsPair newPref = new PrefsPair(key, value);

            loadedPrefs.Add(newPref);
        }