/// <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); } } }
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(); } }