Exemple #1
0
        /// <summary>
        /// It is currently active only when Notch Simulator tab is present.
        /// </summary>
        void OnGUI()
        {
            win = this;
            //Sometimes even with flag I can see it in hierarchy until I move a mouse over it??
            EditorApplication.RepaintHierarchyWindow();

            bool enableSimulation = NotchSimulatorUtility.enableSimulation;

            EditorGUI.BeginChangeCheck();

            string shortcut = ShortcutManager.instance.GetShortcutBinding(NotchSolutionShortcuts.toggleSimulationShortcut).ToString();

            if (string.IsNullOrEmpty(shortcut))
            {
                shortcut = "None";
            }
            NotchSimulatorUtility.enableSimulation = EditorGUILayout.BeginToggleGroup($"Simulate ({shortcut})", NotchSimulatorUtility.enableSimulation);
            EditorGUI.indentLevel++;

            NotchSimulatorUtility.selectedDevice  = (SimulationDevice)EditorGUILayout.EnumPopup(NotchSimulatorUtility.selectedDevice);
            NotchSimulatorUtility.flipOrientation = EditorGUILayout.Toggle("Flip Orientation", NotchSimulatorUtility.flipOrientation);

            var simulationDevice = SimulationDatabase.db[NotchSimulatorUtility.selectedDevice];

            //Draw warning about wrong aspect ratio
            if (enableSimulation)
            {
                ScreenOrientation gameViewOrientation = NotchSimulatorUtility.GetGameViewOrientation();

                Vector2 simSize = gameViewOrientation == ScreenOrientation.Portrait ?
                                  simulationDevice.screenSize : new Vector2(simulationDevice.screenSize.y, simulationDevice.screenSize.x);

                Vector2 gameViewSize = NotchSimulatorUtility.GetMainGameViewSize();
                if (gameViewOrientation == ScreenOrientation.Landscape)
                {
                    var flip = gameViewSize.x;
                    gameViewSize.x = gameViewSize.y;
                    gameViewSize.y = flip;
                }

                var simAspect      = NotchSolutionUtility.ScreenRatio(simulationDevice.screenSize);
                var gameViewAspect = NotchSolutionUtility.ScreenRatio(gameViewSize);
                var aspectDiff     = Math.Abs((simAspect.x / simAspect.y) - (gameViewAspect.x / gameViewAspect.y));
                if (aspectDiff > 0.01f)
                {
                    EditorGUILayout.HelpBox($"The selected simulation device has an aspect ratio of {simAspect.y}:{simAspect.x} ({simulationDevice.screenSize.y}x{simulationDevice.screenSize.x}) but your game view is currently in aspect {gameViewAspect.y}:{gameViewAspect.x} ({gameViewSize.y}x{gameViewSize.x}). The overlay mockup will be stretched from its intended ratio.", MessageType.Warning);
                }
            }

            EditorGUI.indentLevel--;
            EditorGUILayout.EndToggleGroup();
            bool changed = EditorGUI.EndChangeCheck();

            if (changed)
            {
                UpdateAllMockups();
            }

            UpdateSimulatorTargets();
        }
Exemple #2
0
 static void ToggleSimulation()
 {
     NotchSimulatorUtility.enableSimulation = !NotchSimulatorUtility.enableSimulation;
     NotchSimulator.UpdateAllMockups();
     NotchSimulator.UpdateSimulatorTargets();
     NotchSimulator.win?.Repaint();
 }
Exemple #3
0
        static void ToggleSimulation()
        {
            var settings = Settings.Instance;

            settings.EnableSimulation = !settings.EnableSimulation;
            settings.Save();
            NotchSimulator.UpdateAllMockups();
            NotchSimulator.UpdateSimulatorTargets();
            NotchSimulator.Redraw();
        }
Exemple #4
0
        internal static void SwitchConfiguration()
        {
            Settings.Instance.NextConfiguration();

            NotchSimulator.Redraw();
            NotchSimulator.UpdateAllMockups();
            NotchSimulator.UpdateSimulatorTargets();

            // Using shortcut to change aspect ratio actually will not proc the [ExecuteAlways] Update() of adaptation components, unlike using the drop down.
            // But it mostly do so because we always have some uGUI components which indirectly cause those updates on ratio change.
            // While the scene with no uGUI at all maybe rare, it never hurts to proc them manually.. just in case.

            EditorApplication.QueuePlayerLoopUpdate();
        }
        static void SwitchNarrowestWidest()
        {
            var gameView  = typeof(Editor).Assembly.GetType("UnityEditor.GameView");
            var sizeIndex = gameView.GetProperty("selectedSizeIndex",
                                                 BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            var window = EditorWindow.GetWindow(gameView);

            int currentIndex = (int)sizeIndex.GetValue(window);

            currentIndex = currentIndex == NotchSolutionUtility.NarrowestAspectIndex ? NotchSolutionUtility.WidestAspectIndex : NotchSolutionUtility.NarrowestAspectIndex;
            sizeIndex.SetValue(window, currentIndex, null);

            NotchSimulator.UpdateAllMockups();
            NotchSimulator.UpdateSimulatorTargets();
        }
Exemple #6
0
        public override void OnActivate(string searchContext, VisualElement root)
        {
            var padRect = new VisualElement();
            int padding = 10;

            padRect.style.paddingBottom = padding;
            padRect.style.paddingLeft   = padding;
            padRect.style.paddingRight  = padding;
            padRect.style.paddingTop    = padding - 5;
            root.Add(padRect);

            var title = new Label("Notch Solution");

            title.style.fontSize = 15;
            title.style.unityFontStyleAndWeight = FontStyle.Bold;
            padRect.Add(title);

            var repo = new Label("https://github.com/5argon/NotchSolution");

            repo.style.paddingBottom           = 15;
            repo.style.unityFontStyleAndWeight = FontStyle.Bold;
            repo.RegisterCallback((MouseDownEvent ev) =>
            {
                System.Diagnostics.Process.Start("https://github.com/5argon/NotchSolution");
            });
            padRect.Add(repo);

            var devicesPath = new TextField("Device Directory");

            devicesPath.SetEnabled(false);
            devicesPath.value = NotchSimulatorUtility.DevicesFolder;
            padRect.Add(devicesPath);

            var colorField = new ColorField("Prefab mode overlay color");

            colorField.value = Settings.Instance.PrefabModeOverlayColor;
            colorField.RegisterValueChangedCallback(ev =>
            {
                var settings = Settings.Instance;
                settings.PrefabModeOverlayColor = ev.newValue;
                settings.Save();
                NotchSimulator.UpdateAllMockups();
                NotchSimulator.UpdateSimulatorTargets();
            });
            padRect.Add(colorField);
        }
Exemple #7
0
        static void SwitchNarrowestWidest()
        {
            var gameView  = typeof(Editor).Assembly.GetType("UnityEditor.GameView");
            var sizeIndex = gameView.GetProperty("selectedSizeIndex",
                                                 BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            var window = EditorWindow.GetWindow(gameView);

            int currentIndex = (int)sizeIndex.GetValue(window);

            currentIndex = currentIndex == NotchSolutionUtility.NarrowestAspectIndex ? NotchSolutionUtility.WidestAspectIndex : NotchSolutionUtility.NarrowestAspectIndex;
            sizeIndex.SetValue(window, currentIndex, null);

            NotchSimulator.UpdateAllMockups();
            NotchSimulator.UpdateSimulatorTargets();

            // Using shortcut to change aspect ratio actually will not proc the [ExecuteAlways] Update() of adaptation components, unlike using the drop down.
            // But it mostly do so because we always have some uGUI components which indirectly cause those updates on ratio change.
            // While the scene with no uGUI at all maybe rare, it never hurts to proc them manually.. just in case.

            EditorApplication.QueuePlayerLoopUpdate();
        }
Exemple #8
0
        public override void OnActivate(string searchContext, VisualElement root)
        {
            var padRect = new VisualElement();
            int padding = 10;

            padRect.style.paddingBottom = padding;
            padRect.style.paddingLeft   = padding;
            padRect.style.paddingRight  = padding;
            padRect.style.paddingTop    = padding - 5;
            root.Add(padRect);

            var title = new Label("Notch Solution");

            title.style.fontSize = 15;
            title.style.unityFontStyleAndWeight = FontStyle.Bold;
            padRect.Add(title);

            var repo = new Label("https://github.com/5argon/NotchSolution");

            repo.style.paddingBottom           = 15;
            repo.style.unityFontStyleAndWeight = FontStyle.Bold;
            repo.RegisterCallback((MouseDownEvent ev) =>
            {
                System.Diagnostics.Process.Start("https://github.com/5argon/NotchSolution");
            });
            padRect.Add(repo);

            var colorField = new ColorField("Prefab mode overlay color");

            colorField.value = NotchSolutionUtility.PrefabModeOverlayColor;
            colorField.RegisterValueChangedCallback(ev =>
            {
                NotchSolutionUtility.PrefabModeOverlayColor = ev.newValue;
                NotchSimulator.UpdateAllMockups();
                NotchSimulator.UpdateSimulatorTargets();
            });
            padRect.Add(colorField);

            string shortcutString = ShortcutManager.instance.GetShortcutBinding(NotchSolutionShortcuts.switchNarrowestWidestShortcut).ToString();
            string text           = $"This feature allows you to press {shortcutString} to quick switch between 2 aspect ratio choices. Commonly I would often switch between the longest phone like LG G7 and widest device like an iPad as I design. The index is counted from the top choice where 0 equals Free Aspect.";

            var box     = new Box();
            var helpBox = new Label(text);

            helpBox.style.whiteSpace = WhiteSpace.Normal;
            box.style.paddingTop     = 5;
            box.style.paddingLeft    = 5;
            box.style.paddingRight   = 5;
            box.style.paddingBottom  = 2;
            box.style.marginTop      = 10;
            box.style.marginBottom   = 10;
            box.Add(helpBox);
            padRect.Add(box);

            //TODO : Reflect to `GameViewSizes.instance` and request all sizes to draw a nicer drop down menu instead of index number.

            var narrowest = new IntegerField("Narrowest aspect index");

            narrowest.value = NotchSolutionUtility.NarrowestAspectIndex;
            narrowest.RegisterValueChangedCallback(ev =>
            {
                narrowest.value = Mathf.Max(0, ev.newValue); //go to -1 and the game view crashes..
                NotchSolutionUtility.NarrowestAspectIndex = ev.newValue;
                NotchSimulator.UpdateAllMockups();
                NotchSimulator.UpdateSimulatorTargets();
            });
            padRect.Add(narrowest);

            var widest = new IntegerField("Widest aspect index");

            widest.value = NotchSolutionUtility.WidestAspectIndex;
            widest.RegisterValueChangedCallback(ev =>
            {
                widest.value = Mathf.Max(0, ev.newValue);
                NotchSolutionUtility.WidestAspectIndex = ev.newValue;
                NotchSimulator.UpdateAllMockups();
                NotchSimulator.UpdateSimulatorTargets();
            });
            padRect.Add(widest);
        }
Exemple #9
0
 public static void ShowWindow()
 {
     win = (NotchSimulator)EditorWindow.GetWindow(typeof(NotchSimulator));
     win.titleContent = new GUIContent("Notch Simulator");
 }
Exemple #10
0
        /// <summary>
        /// It is currently active only when Notch Simulator tab is present.
        /// </summary>
        void OnGUI()
        {
            win = this;

            //Sometimes even with flag I can see it in hierarchy until I move a mouse over it??
            EditorApplication.RepaintHierarchyWindow();

            EditorGUI.BeginChangeCheck();

            var settings = Settings.Instance;

            string switchConfigShortcut = ShortcutManager.instance.GetShortcutBinding(NotchSolutionShortcuts.switchConfigurationShortcut).ToString();

            if (string.IsNullOrEmpty(switchConfigShortcut))
            {
                switchConfigShortcut = "None";
            }
            string simulateShortcut = ShortcutManager.instance.GetShortcutBinding(NotchSolutionShortcuts.toggleSimulationShortcut).ToString();

            if (string.IsNullOrEmpty(simulateShortcut))
            {
                simulateShortcut = "None";
            }

            settings.EnableSimulation = EditorGUILayout.BeginToggleGroup($"Simulate ({simulateShortcut})", settings.EnableSimulation);

            int previousIndex = settings.ActiveConfiguration.DeviceIndex;
            int currentIndex  = Mathf.Clamp(settings.ActiveConfiguration.DeviceIndex, 0, SimulationDatabase.KeyList.Length - 1);

            int selectedIndex = EditorGUILayout.Popup(currentIndex, SimulationDatabase.KeyList);

            if (GUILayout.Button($"{settings.ActiveConfiguration.ConfigurationName} ({switchConfigShortcut})", EditorStyles.helpBox))
            {
                NotchSolutionShortcuts.SwitchConfiguration();
            }
            EditorGUILayout.EndToggleGroup();

            settings.ActiveConfiguration.DeviceIndex = selectedIndex;

            var simulationDevice = SimulationDatabase.Get(SimulationDatabase.KeyList[selectedIndex]);

            //Draw warning about wrong aspect ratio
            if (settings.EnableSimulation && simulationDevice != null)
            {
                ScreenOrientation gameViewOrientation = NotchSimulatorUtility.GetGameViewOrientation();

                Vector2 gameViewSize = NotchSimulatorUtility.GetMainGameViewSize();
                if (gameViewOrientation == ScreenOrientation.Landscape)
                {
                    var flip = gameViewSize.x;
                    gameViewSize.x = gameViewSize.y;
                    gameViewSize.y = flip;
                }

                var screen         = simulationDevice.Screens.FirstOrDefault();
                var simAspect      = NotchSolutionUtilityEditor.ScreenRatio(new Vector2(screen.width, screen.height));
                var gameViewAspect = NotchSolutionUtilityEditor.ScreenRatio(gameViewSize);
                var aspectDiff     = Math.Abs((simAspect.x / simAspect.y) - (gameViewAspect.x / gameViewAspect.y));
                if (aspectDiff > 0.01f)
                {
                    EditorGUILayout.HelpBox($"The selected simulation device has an aspect ratio of {simAspect.y}:{simAspect.x} ({screen.height}x{screen.width}) but your game view is currently in aspect {gameViewAspect.y}:{gameViewAspect.x} ({gameViewSize.y}x{gameViewSize.x}). The overlay mockup won't be displayed correctly.", MessageType.Warning);
                }
            }

            bool changed = EditorGUI.EndChangeCheck();

            if (changed)
            {
                UpdateAllMockups();
                settings.Save();
            }

            UpdateSimulatorTargets();
        }