void Awake() { // We init the portrait value with the current portrait value m_IsPortait = DeviceInfo.IsPortrait(); #if UNITY_EDITOR // In editor, we are in fact interested by the orientation of the device, not by the gameview resolution // So we try to get the first preview device and look at its orientation var firstDevice = GetFirstPreviewDevice(); if (firstDevice != null) { m_IsPortait = firstDevice.m_Orientation == ScreenshotResolution.Orientation.PORTRAIT; } #endif Debug.Log("On orientation changed. Init portrait: " + m_IsPortait); }
void Update() { #if UNITY_EDITOR // Update only if it is a simulated device if (DeviceInfo.GetSimulatedDevice() == null) { return; } #endif // Check if orientation changed bool portrait = DeviceInfo.IsPortrait(); if (portrait != m_IsPortait) { m_IsPortait = portrait; Debug.Log("Orientation change detected. Is portrait: " + m_IsPortait); onOrientationChangedDelegate(m_IsPortait); } }