Ejemplo n.º 1
0
        /// <summary>
        /// Get all <see cref="INotchSimulatorTarget"/> and update them.
        /// </summary>
        internal static void UpdateSimulatorTargets()
        {
            var enableSimulation = Settings.Instance.EnableSimulation;
            var selectedDevice   = SimulationDatabase.ByIndex(Settings.Instance.ActiveConfiguration.DeviceIndex);

            var simulatedRectRelative = enableSimulation && selectedDevice != null?NotchSimulatorUtility.CalculateSimulatorSafeAreaRelative(selectedDevice) : NotchSolutionUtility.defaultSafeArea;

            var simulatedCutoutsRelative = enableSimulation && selectedDevice != null?NotchSimulatorUtility.CalculateSimulatorCutoutsRelative(selectedDevice) : NotchSolutionUtility.defaultCutouts;

            var normalSceneSimTargets = GameObject.FindObjectsOfType <MonoBehaviour>().OfType <INotchSimulatorTarget>();

            foreach (var nst in normalSceneSimTargets)
            {
                nst.SimulatorUpdate(simulatedRectRelative, simulatedCutoutsRelative);
            }

            //Now find one in the prefab mode scene as well
            PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();

            if (prefabStage != null)
            {
                var prefabSceneSimTargets = prefabStage.stageHandle.FindComponentsOfType <MonoBehaviour>().OfType <INotchSimulatorTarget>();
                foreach (var nst in prefabSceneSimTargets)
                {
                    nst.SimulatorUpdate(simulatedRectRelative, simulatedCutoutsRelative);
                }
            }
        }
Ejemplo n.º 2
0
 internal static void RespawnMockup()
 {
     //When the game view is changed, the mockup sometimes disappears or isn't scaled correctly
     if (gameviewResolution != NotchSimulatorUtility.GetMainGameViewSize())
     {
         DestroyHiddenCanvas();                                            //So we delete the old canvas
         UpdateAllMockups();                                               //And we respawn it
         UpdateSimulatorTargets();
         gameviewResolution = NotchSimulatorUtility.GetMainGameViewSize(); //Update the saved game view
     }
 }
Ejemplo n.º 3
0
        internal static void UpdateAllMockups()
        {
            //When building, the scene may open-close multiple times and brought back the mockup canvas,
            //which combined with bugs mentioned at https://github.com/5argon/NotchSolution/issues/11,
            //will fail the build. This `if` prevents mockup refresh while building.
            if (BuildPipeline.isBuildingPlayer)
            {
                return;
            }

            EnsureCanvasAndEventSetup();

            //Make the editing environment contains an another copy of mockup canvas.
            var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();

            if (prefabStage != null)
            {
                EnsureCanvasAndEventSetup(prefabStage: prefabStage);
            }

            var  settings         = Settings.Instance;
            bool enableSimulation = settings.EnableSimulation;
            var  selectedDevice   = SimulationDatabase.ByIndex(Settings.Instance.ActiveConfiguration.DeviceIndex);

            if (enableSimulation && selectedDevice != null)
            {
                var    name         = selectedDevice.Meta.overlay;
                Sprite mockupSprite = null;
                if (!string.IsNullOrEmpty(name))
                {
                    var filePath = Path.Combine(NotchSimulatorUtility.DevicesFolder, name);
                    mockupSprite = AssetDatabase.LoadAssetAtPath <Sprite>(filePath);
                    if (mockupSprite == null)
                    {
                        if (System.IO.File.Exists(filePath))
                        {
                            Texture2D tex = new Texture2D(1, 1);
                            tex.LoadImage(System.IO.File.ReadAllBytes(filePath));
                            mockupSprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
                        }
                        else
                        {
                            Debug.LogWarning($"No mockup image named {name} in {NotchSimulatorUtility.DevicesFolder} folder!");
                        }
                    }
                }


                foreach (var mockup in AllMockupCanvases)
                {
                    mockup.UpdateMockupSprite(
                        sprite: mockupSprite,
                        orientation: NotchSimulatorUtility.GetGameViewOrientation(),
                        simulate: enableSimulation,
                        flipped: settings.FlipOrientation,
                        prefabModeOverlayColor: Settings.Instance.PrefabModeOverlayColor
                        );
                }
            }
            else
            {
                DestroyHiddenCanvas();
            }
        }
Ejemplo n.º 4
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();
        }