/// <summary> /// Get all <see cref="INotchSimulatorTarget"> and update them. /// </summary> internal static void UpdateSimulatorTargets() { var simulatedRectRelative = NotchSimulatorUtility.enableSimulation ? NotchSimulatorUtility.CalculateSimulatorSafeAreaRelative() : new Rect(0, 0, 1, 1); var simulatedCutoutsRelative = NotchSimulatorUtility.enableSimulation ? NotchSimulatorUtility.CalculateSimulatorCutoutsRelative() : new Rect[0]; //This value could be used by the component statically. NotchSolutionUtility.SimulatedSafeAreaRelative = simulatedRectRelative; #if UNITY_2019_2_OR_NEWER NotchSolutionUtility.SimulatedCutoutsRelative = simulatedCutoutsRelative; #endif var normalSceneSimTargets = GameObject.FindObjectsOfType <UIBehaviour>().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 <UIBehaviour>().OfType <INotchSimulatorTarget>(); foreach (var nst in prefabSceneSimTargets) { nst.SimulatorUpdate(simulatedRectRelative, simulatedCutoutsRelative); } } }
/// <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); } } }