示例#1
0
        public static EditorFullscreenSettings LoadSettings()
        {
            if (!initialized)
            {
                Initialize();               //Make sure static settings are initialized.
            }
            string settingsData = EditorPrefs.GetString("EditorFullscreenWindowSettings_ALL");
            EditorFullscreenSettings loadedSettings = null;

            if (!string.IsNullOrEmpty(settingsData))
            {
                loadedSettings = SerializerUtility.Deserialize <EditorFullscreenSettings>(settingsData);
            }

            if (loadedSettings == null)
            {
                return(new EditorFullscreenSettings());
            }
            else
            {
                if (loadedSettings.gameWindow.gameViewOptions == null)
                {
                    loadedSettings.gameWindow.gameViewOptions = new GameViewOptions();                                                    //For backwards compatibility.
                }
                return(loadedSettings);
            }
        }
示例#2
0
        void OnEnable()
        {
            window       = this;
            this.minSize = new Vector2(540, 670);

            headerStyle.fontSize         = 18;
            headerStyle.fontStyle        = FontStyle.Bold;
            headerStyle.normal.textColor = EditorGUIUtility.isProSkin ? proHeadingColor : new Color(0.25f, 0.25f, 0.25f, 1f);
            headerStyle.margin.top       = 10;
            headerStyle.margin.bottom    = 5;

            subHeaderStyle.fontSize         = 14;
            subHeaderStyle.fontStyle        = FontStyle.Bold;
            subHeaderStyle.normal.textColor = EditorGUIUtility.isProSkin ? proHeadingColor : new Color(0.25f, 0.25f, 0.25f, 1f);

            subHeaderStyle.margin.top = 10;

            smallHeadingStyle.fontStyle   = FontStyle.Bold;
            smallHeadingStyle.margin.top  = 5;
            smallHeadingStyle.margin.left = 6;
            if (EditorGUIUtility.isProSkin)
            {
                smallHeadingStyle.normal.textColor = proHeadingColor;
            }

            _windowSettings = EditorFullscreenSettings.LoadSettings();
            EditorFullscreenState.TriggerFullscreenEvent(this, this.GetType(), Vector2.zero, false); //Notify everyone that the settings window was opened.
        }
示例#3
0
        private static void Initialize()
        {
            initialized = true;
            try
            {
                scriptFileSubPath = GetMenuItemScriptFileRelativePath();
                if (scriptFileSubPath == null)
                {
                    return;
                }
                scriptFilePath = Application.dataPath + scriptFileSubPath;

                _settings = LoadSettings();

                if (MenuItemScriptNeedsRefresh())
                {
                    _settings.SaveSettings(false);
                    _settings.UpdateMenuItems();
                }
            }
            catch (System.Exception e)
            {
                if (EWFDebugging.Enabled)
                {
                    Debug.LogError("Settings failed to load.");
                    Debug.LogException(e);
                    EWFDebugging.LogError("Settings failed to load. " + e.Message);
                }
            }
        }
示例#4
0
 void ResetSettingsToDefaults()
 {
     EditorFullscreenSettings.ResetToDefaults();
     hotkeysWereChanged = true;
     EditorFullscreenSettings.settings.SaveSettings(hotkeysWereChanged);
     _windowSettings    = EditorFullscreenSettings.LoadSettings();
     allowApplySettings = false;
     hotkeysWereChanged = false;
 }
示例#5
0
 private void AssignOptionID(EditorFullscreenSettings settings, bool addToOptionsDict)
 {
     optionID = settings.nextFullscreenOptionID;
     settings.nextFullscreenOptionID++;
     if (addToOptionsDict)
     {
         settings.fullscreenOptions[optionID] = this;
     }
 }
        public void LoadSettings()
        {
            string settingsData   = EditorPrefs.GetString("EditorFullscreenWindowSettings_ALL");
            var    loadedSettings = SerializerUtility.Deserialize <EditorFullscreenSettings>(settingsData);

            if (loadedSettings != null)
            {
                _settings = loadedSettings;
            }
        }
 public void SaveSettings(bool hotkeysWereChanged)
 {
     _settings = this;
     EditorPrefs.SetString("EditorFullscreenWindowSettings_VER", settingsSaveVersion);
     EditorPrefs.SetString("EditorFullscreenWindowSettings_ALL", SerializerUtility.Serialize(this));
     if (hotkeysWereChanged)
     {
         UpdateMenuItems();
     }
 }
        private static bool ToggleGameViewFullscreen(bool triggeredOnPlayStateChange)
        {
            EditorFullscreenSettings.FullscreenOption fullscreenOps;
            if (triggeredOnPlayStateChange)
            {
                fullscreenOps = EditorFullscreenSettings.settings.openFullscreenOnGameStart;
            }
            else
            {
                fullscreenOps = EditorFullscreenSettings.GetFullscreenOptionsForWindowType(EditorFullscreenState.gameViewType);
            }
            bool setFullscreen = !EditorFullscreenState.WindowTypeIsFullscreenAtOptionsSpecifiedPosition(EditorFullscreenState.gameViewType, fullscreenOps);

            EditorFullscreenState.RunOnLoad methodToRun;
            if (!triggeredOnPlayStateChange)
            {
                methodToRun = ToggleGameViewFullscreen;
            }
            else
            {
                methodToRun = ToggleGameViewFullscreenPlayStateWasChanged;
            }
            if (EditorFullscreenState.RunAfterInitialStateLoaded(methodToRun))
            {
                return(setFullscreen);
            }

            setFullscreen = EditorFullscreenState.ToggleFullscreenAtOptionsSpecifiedPosition(null, EditorFullscreenState.gameViewType, fullscreenOps, triggeredOnPlayStateChange);
            var focusedWindow = EditorWindow.focusedWindow;

            EditorMainWindow.Focus();
            if (focusedWindow != null)
            {
                focusedWindow.Focus();
            }

            if (!triggeredOnPlayStateChange)
            {
                bool isPlaying = EditorApplication.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode;
                if (settings.startGameWhenEnteringFullscreen && !isPlaying && setFullscreen)
                {
                    //Enter play mode
                    EditorApplication.ExecuteMenuItem("Edit/Play");
                }
                else if (settings.stopGameWhenExitingFullscreen != EditorFullscreenSettings.StopGameWhenExitingFullscreen.Never && isPlaying && !setFullscreen)
                {
                    if (settings.stopGameWhenExitingFullscreen == EditorFullscreenSettings.StopGameWhenExitingFullscreen.WhenAnyFullscreenGameViewIsExited || !WindowTypeIsFullscreen(EditorFullscreenState.gameViewType))
                    {
                        //Exit play mode
                        EditorApplication.ExecuteMenuItem("Edit/Play");
                    }
                }
            }
            return(setFullscreen);
        }
示例#9
0
 public FullscreenOption(EditorFullscreenSettings settings, KeyCode hotkey, EventModifiers modifiers, OpenFullscreenAtPosition openAtPosition, bool showToolbarByDefault, Vector2 position, string optionLabel, Type windowType, bool addToOptionsDict, bool isGameView)
 {
     this.hotkey                          = hotkey;
     this.modifiers                       = modifiers;
     this.openAtPosition                  = openAtPosition;
     this.showToolbarByDefault            = showToolbarByDefault;
     this.position                        = position;
     this.optionLabel                     = optionLabel;
     this.windowTypeAssemblyQualifiedName = windowType == null ? null : windowType.AssemblyQualifiedName;
     this.isGameView                      = isGameView;
     gameViewOptions                      = isGameView ? new GameViewOptions() : null;
     AssignOptionID(settings, addToOptionsDict);
 }
示例#10
0
        /// <summary>
        /// Returns true if a window type is fullscreen on the screen specified by the options for opening that window type.
        /// </summary>
        public static bool WindowTypeIsFullscreenAtOptionsSpecifiedPosition(Type windowType)
        {
            var fullscreenOptions = EditorFullscreenSettings.GetFullscreenOptionsForWindowType(windowType);

            //Main Window
            if (windowType == mainWindowType)
            {
                return(EditorMainWindow.IsFullscreenAtPosition(GetOptionsSpecifiedFullscreenOpenAtPosition(null, windowType, fullscreenOptions)));
            }

            //Any Other Editor Window
            return(WindowTypeIsFullscreenAtOptionsSpecifiedPosition(windowType, fullscreenOptions));
        }
示例#11
0
        private int AddFilteredEnumPopup(GUIContent label, System.Enum selectedValue, int[] displayedOptions)
        {
            var selectedVal    = System.Convert.ToInt32(selectedValue);
            var visibleOptions = new GUIContent[displayedOptions.Length];
            var optionValues   = new int[displayedOptions.Length];

            for (int i = 0; i < displayedOptions.Length; i++)
            {
                optionValues[i]        = displayedOptions[i];
                visibleOptions[i]      = new GUIContent();
                visibleOptions[i].text = System.Enum.GetName(selectedValue.GetType(), displayedOptions[i]);
                if (visibleOptions[i].text == null)
                {
                    visibleOptions[i].text = "Undefined";
                }
                else
                {
                    visibleOptions[i].text = EditorFullscreenSettings.FormatCamelCaseName(visibleOptions[i].text);
                }
            }

            return(EditorGUILayout.IntPopup(label, selectedVal, visibleOptions, optionValues, new GUILayoutOption[0]));
        }
示例#12
0
 public FullscreenOption(EditorFullscreenSettings settings, KeyCode hotkey, EventModifiers modifiers, OpenFullscreenAtPosition openAtPosition, bool showToolbarByDefault, Vector2 position, string optionLabel, Type windowType, bool addToOptionsDict)
     : this(settings, hotkey, modifiers, openAtPosition, showToolbarByDefault, position, optionLabel, windowType, addToOptionsDict, false)
 {
 }
示例#13
0
 public FullscreenOption(EditorFullscreenSettings settings, bool addToOptionsDict)
 {
     AssignOptionID(settings, addToOptionsDict);
 }
示例#14
0
 public FullscreenOption(EditorFullscreenSettings settings)
 {
     AssignOptionID(settings, false);
 }
示例#15
0
 public static void ResetToDefaults()
 {
     _settings = new EditorFullscreenSettings();
 }
示例#16
0
        void OnGUI()
        {
            hotkeyWasSet = false;
            var style       = new GUIStyle();
            var buttonStyle = new GUIStyle();
            var smallIndent = new GUIStyle();

            style.margin.left       = 20;
            style.margin.right      = 20;
            smallIndent.margin.left = 3;

            EditorGUILayout.BeginVertical(style);
            EditorGUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = 245f;
            GUILayout.Label("Fullscreen Window Settings", headerStyle, new GUILayoutOption[0]);

            //Reset to defaults button
            buttonStyle              = new GUIStyle(GUI.skin.button);
            buttonStyle.fontSize     = 10;
            buttonStyle.fontStyle    = FontStyle.Bold;
            buttonStyle.padding      = new RectOffset(0, 0, 5, 5);
            buttonStyle.margin.top   = 10;
            buttonStyle.margin.right = 24;
            if (GUILayout.Button(new GUIContent("Reset to Defaults", "Reset all settings to their default values."), buttonStyle, new GUILayoutOption[0]))
            {
                EditorFullscreenSettings.ResetToDefaults();
                settings           = EditorFullscreenSettings.settings;
                hotkeysWereChanged = true;
                settings.SaveSettings(hotkeysWereChanged);
                allowApplySettings = false;
                hotkeysWereChanged = false;
                Repaint();
                return;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginVertical(style);

            //Fullscreen Window Hotkeys
            EditorGUIUtility.labelWidth = 165f;
            GUILayout.Label("Fullscreen Window Hotkeys", subHeaderStyle, new GUILayoutOption[0]);
            EditorGUILayout.BeginVertical(smallIndent);
            AddFullscreenOption(ref settings.mainUnityWindow, "Main Unity Window", true, true);
            AddFullscreenOption(ref settings.sceneWindow, "Scene Window", true, true);
            AddFullscreenOption(ref settings.gameWindow, "Game Window", true, true);
            AddFullscreenOption(ref settings.currentlyFocusedWindow, "Currently Focused Window", true, true);
            AddFullscreenOption(ref settings.windowUnderCursor, "Window Under Cursor", true, true);
            EditorGUILayout.EndVertical();

            //Other Hotkeys
            GUILayout.Label("Other Hotkeys", subHeaderStyle, new GUILayoutOption[0]);
            EditorGUILayout.BeginVertical(smallIndent);
            AddFullscreenOption(ref settings.toggleTopToolbar, "Show/Hide Top Toolbar", false, false);
            EditorGUILayout.EndVertical();
            style            = new GUIStyle(smallIndent);
            style.margin.top = 8;
            EditorGUILayout.BeginVertical(style);
            AddFullscreenOption(ref settings.closeAllFullscreenWindows, "Close All Fullscreen Windows", false, false);
            EditorGUILayout.EndVertical();


            //Game Window Fullscreen Options
            EditorGUIUtility.labelWidth = 245f;
            GUILayout.Label("Game Window Options", subHeaderStyle, new GUILayoutOption[0]);
            EditorGUILayout.BeginVertical(smallIndent);

            var label = new GUIContent("Start the Game When Entering Fullscreen", "Start the game when entering a fullscreen game window.");

            settings.startGameWhenEnteringFullscreen = EditorGUILayout.Toggle(label, settings.startGameWhenEnteringFullscreen, new GUILayoutOption[0]);

            label = new GUIContent("Stop the Game When Exiting Fullscreen", "Stop the game when exiting fullscreen game window.");
            settings.stopGameWhenExitingFullscreen = (EditorFullscreenSettings.StopGameWhenExitingFullscreen)EditorGUILayout.EnumPopup(label, settings.stopGameWhenExitingFullscreen, new GUILayoutOption[0]);

            var ofsGroup = new GUIStyle();

            ofsGroup.margin.top    = 0;
            ofsGroup.margin.bottom = smallHeadingStyle.margin.top;
            EditorGUILayout.BeginVertical(ofsGroup);
            label = new GUIContent("Open Fullscreen On Game Start", "Open a fullscreen game window when the game starts.");
            AddFullscreenOption(ref settings.openFullscreenOnGameStart, label, true, true, false, new[] { 0, 1, 2, 3 });
            EditorGUILayout.EndVertical();

            label = new GUIContent("Close Fullscreen On Game Stop", "Close fullscreen game window/s when the game stops.");
            settings.closeFullscreenOnGameStop = (EditorFullscreenSettings.CloseFullscreenOnGameStop)EditorGUILayout.EnumPopup(label, settings.closeFullscreenOnGameStop, new GUILayoutOption[0]);

            EditorGUILayout.EndVertical();


            if (GUI.changed || hotkeyWasSet)
            {
                if (hotkeyWasSet)
                {
                    hotkeysWereChanged = true;
                }
                allowApplySettings = true;
            }

            EditorGUILayout.BeginVertical();
            EditorGUI.BeginDisabledGroup(!allowApplySettings);
            buttonStyle            = new GUIStyle(GUI.skin.button);
            buttonStyle.fontSize   = 15;
            buttonStyle.fontStyle  = FontStyle.Bold;
            buttonStyle.padding    = new RectOffset(0, 0, 10, 10);
            buttonStyle.margin.top = 12;
            if (GUILayout.Button(new GUIContent("Apply Settings", "Apply all changes."), buttonStyle, new GUILayoutOption[0]))
            {
                settings.SaveSettings(hotkeysWereChanged);
                allowApplySettings = false;
                hotkeysWereChanged = false;
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(true);
            style             = new GUIStyle();
            style.fontStyle   = FontStyle.Normal;
            style.fontSize    = 9;
            style.margin.left = 9;
            style.margin.top  = 6;
            if (EditorGUIUtility.isProSkin)
            {
                style.normal.textColor = new Color(0.75f, 0.75f, 0.75f, 1f);
            }

            GUILayout.Label("Current Mouse Position: " + EditorInput.MousePosition, style, new GUILayoutOption[0]);
            EditorGUI.EndDisabledGroup();

            //Set the focused control
            if (Event.current.type == EventType.Repaint)
            {
                focusedFieldName = GUI.GetNameOfFocusedControl();
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();
        }
示例#17
0
 public static void ReloadSettings()
 {
     _settings = LoadSettings();
 }
示例#18
0
 /// <summary>
 /// Toggle fullscreen at a position decided according to the current options.
 /// </summary>
 public static bool ToggleFullscreenAtOptionsSpecifiedPosition(Type windowType, bool triggeredOnPlayStateChange)
 {
     return(ToggleFullscreenAtOptionsSpecifiedPosition(null, windowType, EditorFullscreenSettings.GetFullscreenOptionsForWindowType(windowType), triggeredOnPlayStateChange));
 }