protected override void OnGUIInternal()
        {
            var prefsList = PrefsList.Where(prefs => !prefs.IsDefault).ToList();

            prefsList.Where(prefs => !checkedList.ContainsKey(prefs.key)).Select(prefs => prefs.key).ToList().ForEach(key => checkedList[key] = true);


            EditorGUILayout.HelpBox("\nSelect Prefs to change Default.\n", MessageType.None);

            if (checkAll != GUILayout.Toggle(checkAll, ""))
            {
                checkAll = !checkAll;
                prefsList.ForEach(prefs => checkedList[prefs.key] = checkAll);
            }

            using (var sc = new GUILayout.ScrollViewScope(scrollPosition))
            {
                scrollPosition = sc.scrollPosition;
                prefsList.ForEach(prefs =>
                {
                    var key    = prefs.key;
                    bool check = checkedList[key];

                    using (var h0 = new GUILayout.HorizontalScope())
                    {
                        if (check != GUILayout.Toggle(check, "", GUILayout.Width(20f)))
                        {
                            checkedList[key] = !check;
                        }
                        GUI.enabled = false;
                        prefs.OnGUI();
                        GUI.enabled = true;
                    }
                });
            }


            var checkPrefsList = prefsList.Where(prefs => checkedList[prefs.key]).ToList();

            GUILayout.Space(8f);

            GUI.enabled = checkPrefsList.Any();
            if (GUILayout.Button("SetCurrentToDefault"))
            {
                checkPrefsList.ForEach(prefs =>
                {
                    prefs.SetCurrentToDefault();
                });

                Close();
                parentWindow.Repaint();
            }
            GUI.enabled = true;
        }
Esempio n. 2
0
        protected override void OnGUIInternal()
        {
            using (var h0 = new GUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Save"))
                {
                    Prefs.Save();
                }
                if (GUILayout.Button("Load"))
                {
                    Prefs.Load();
                }
                if (GUILayout.Button("DeleteAll"))
                {
                    if (EditorUtility.DisplayDialog("DeleteAll", "Are you sure to delete all current prefs parameters?", "DeleteAll", "Don't Delete"))
                    {
                        Prefs.DeleteAll();
                    }
                }
            }

            var currentToDefaultEnable = !Application.isPlaying && PrefsList.Any(prefs => !prefs.IsDefault);

            GUI.enabled = currentToDefaultEnable;
            if (GUILayout.Button("Open Current To Default Window"))
            {
                if (setCurrentToDefaultWindow == null)
                {
                    setCurrentToDefaultWindow = CreateInstance <SetCurrentToDefaultWindow>();
                }
                setCurrentToDefaultWindow.parentWindow = this;
                setCurrentToDefaultWindow.ShowUtility();
            }
            GUI.enabled = true;

            GUILayout.Space(8f);

            using (var sc = new GUILayout.ScrollViewScope(scrollPosition))
            {
                scrollPosition = sc.scrollPosition;

                var sync = FindObjectOfType <PrefsGUISync>();
                if (sync != null)
                {
                    GUILayout.Label("sync");
                }

                PrefsList.ToList().ForEach(prefs =>
                {
                    using (var h = new GUILayout.HorizontalScope())
                    {
                        if (sync != null)
                        {
                            var key    = prefs.key;
                            var isSync = !sync._ignoreKeys.Contains(key);

                            if (isSync != GUILayout.Toggle(isSync, "", GUILayout.Width(16f)))
                            {
                                Undo.RecordObject(sync, "Change PrefsGUI sync flag");

                                if (isSync)
                                {
                                    sync._ignoreKeys.Add(key);
                                }
                                else
                                {
                                    sync._ignoreKeys.Remove(key);
                                }
                            }
                        }

                        prefs.OnGUI();
                    }
                });
            }

            if ((setCurrentToDefaultWindow != null) && Event.current.type == EventType.repaint)
            {
                setCurrentToDefaultWindow.Repaint();
            }
        }
Esempio n. 3
0
        protected override void OnGUIInternal()
        {
            var prefsList = PrefsList.Where(prefs => !prefs.IsDefault).ToList();

            prefsList.Where(prefs => !checkedList.ContainsKey(prefs.key)).Select(prefs => prefs.key).ToList().ForEach(key => checkedList[key] = true);


            EditorGUILayout.HelpBox("\nSelect Prefs to change Default.\n", MessageType.None);

            if (checkAll != GUILayout.Toggle(checkAll, ""))
            {
                checkAll = !checkAll;
                prefsList.ForEach(prefs => checkedList[prefs.key] = checkAll);
            }

            using (var sc = new GUILayout.ScrollViewScope(scrollPosition))
            {
                scrollPosition = sc.scrollPosition;
                prefsList.ForEach(prefs =>
                {
                    var key    = prefs.key;
                    bool check = checkedList[key];

                    using (var h0 = new GUILayout.HorizontalScope())
                    {
                        if (check != GUILayout.Toggle(check, "", GUILayout.Width(20f)))
                        {
                            checkedList[key] = !check;
                        }
                        prefs.OnGUI();
                    }
                });
            }


            var checkPrefsList = prefsList.Where(prefs => checkedList[prefs.key]).ToList();

            GUILayout.Space(8f);

            GUI.enabled = checkPrefsList.Any();
            if (GUILayout.Button("SetCurrentToDefault"))
            {
                // Search Objects to recoard that has PrefsParams
                var components = FindObjectsOfType <MonoBehaviour>()
                                 .Where(c =>
                {
                    var t = c.GetType();
                    return(Assembly.GetAssembly(t).GetName().Name.StartsWith("Assembly-CSharp") &&  // skip unity classes
                           IsContainPrefsParam(t));
                })
                                 .ToArray();

                Undo.RecordObjects(components, "Set PrefsGUI default value");


                // SetCurrent To Default
                checkPrefsList.ForEach(prefs =>
                {
                    prefs.SetCurrentToDefault();
                });

                Close();
                parentWindow.Repaint();
            }
            GUI.enabled = true;
        }
Esempio n. 4
0
        protected override void OnGUIInternal()
        {
            using (var h0 = new GUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Save"))
                {
                    Prefs.Save();
                }
                if (GUILayout.Button("Load"))
                {
                    Prefs.Load();
                }
                if (GUILayout.Button("DeleteAll"))
                {
                    if (EditorUtility.DisplayDialog("DeleteAll", "Are you sure to delete all current prefs parameters?", "DeleteAll", "Don't Delete"))
                    {
                        Prefs.DeleteAll();
                    }
                }
            }

            var currentToDefaultEnable = !Application.isPlaying && PrefsList.Any(prefs => !prefs.IsDefault);

            GUI.enabled = currentToDefaultEnable;
            if (GUILayout.Button("Open Current To Default Window"))
            {
                if (setCurrentToDefaultWindow == null)
                {
                    setCurrentToDefaultWindow = CreateInstance <SetCurrentToDefaultWindow>();
                }
                setCurrentToDefaultWindow.parentWindow = this;
                setCurrentToDefaultWindow.ShowUtility();
            }
            GUI.enabled = true;

            GUILayout.Space(8f);

            using (var h = new GUILayout.HorizontalScope())
            {
                GUILayout.Label("Order");
                _order = (Order)GUILayout.SelectionGrid((int)_order, System.Enum.GetNames(typeof(Order)), 5);
            }

            GUILayout.Space(8f);

            using (var sc = new GUILayout.ScrollViewScope(scrollPosition))
            {
                scrollPosition = sc.scrollPosition;

                var sync = FindObjectOfType <PrefsGUISync>();
                if (sync != null)
                {
                    GUILayout.Label("sync");
                }


                if (Order.GameObject == _order)
                {
                    _goParams.Where(dic => dic.Key != null).OrderBy(dic => dic.Key.name).ToList().ForEach(pair =>
                    {
                        var go        = pair.Key;
                        var prefsList = pair.Value;

                        LabelWithEditPrefix(sync, go.name, go, prefsList);

                        GUIUtil.Indent(() =>
                        {
                            prefsList.ForEach(prefs =>
                            {
                                using (var h = new GUILayout.HorizontalScope())
                                {
                                    SyncToggle(sync, prefs);
                                    prefs.OnGUI();
                                }
                            });
                        });
                    });
                }
                else
                {
                    PrefsList.ToList().ForEach(prefs =>
                    {
                        using (var h = new GUILayout.HorizontalScope())
                        {
                            if (sync != null)
                            {
                                var key    = prefs.key;
                                var isSync = !sync._ignoreKeys.Contains(key);

                                if (isSync != GUILayout.Toggle(isSync, "", GUILayout.Width(16f)))
                                {
                                    Undo.RecordObject(sync, "Change PrefsGUI sync flag");

                                    if (isSync)
                                    {
                                        sync._ignoreKeys.Add(key);
                                    }
                                    else
                                    {
                                        sync._ignoreKeys.Remove(key);
                                    }
                                }
                            }

                            prefs.OnGUI();
                        }
                    });
                }
            }

            if ((setCurrentToDefaultWindow != null) && Event.current.type == EventType.Repaint)
            {
                setCurrentToDefaultWindow.Repaint();
            }
        }