Exemplo n.º 1
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();
            }
        }
Exemplo 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 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();
            }
        }