コード例 #1
0
 private static void RefreshMockupsInternal()
 {
     if (--mockupRefreshTime <= 0)
     {
         EditorApplication.update -= RefreshMockupsInternal;
         NotchSimulator.RespawnMockup();
     }
 }
コード例 #2
0
        private static void ToggleSimulation()
        {
            var settings = Settings.Instance;

            settings.EnableSimulation = !settings.EnableSimulation;
            settings.Save();
            NotchSimulator.UpdateAllMockups();
            NotchSimulator.UpdateSimulatorTargets();
            NotchSimulator.Redraw();
        }
コード例 #3
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();
        }
コード例 #4
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);
        }
コード例 #5
0
 public static void ShowWindow()
 {
     win = (NotchSimulator)EditorWindow.GetWindow(typeof(NotchSimulator));
     win.titleContent = new GUIContent("Notch Simulator");
 }
コード例 #6
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();
        }