private void DrawingSurfaceBackground_Loaded(object sender, RoutedEventArgs e) { if (!_unityStartedLoading) { _unityStartedLoading = true; UnityApp.SetLoadedCallback(() => { Dispatcher.BeginInvoke(Unity_Loaded); }); var content = Application.Current.Host.Content; var width = (int)Math.Floor(content.ActualWidth * content.ScaleFactor / 100.0 + 0.5); var height = (int)Math.Floor(content.ActualHeight * content.ScaleFactor / 100.0 + 0.5); UnityApp.SetNativeResolution(width, height); UnityApp.SetRenderResolution(width, height); UnityApp.SetOrientation((int)Orientation); DrawingSurfaceBackground.SetBackgroundContentProvider(UnityApp.GetBackgroundContentProvider()); DrawingSurfaceBackground.SetBackgroundManipulationHandler(UnityApp.GetManipulationHandler()); } }
private void DrawingSurfaceBackground_Loaded(object sender, RoutedEventArgs e) { if (!_unityStartedLoading) { _unityStartedLoading = true; //UnityApp.SetLoadedCallback(() => { Dispatcher.BeginInvoke(Unity_Loaded); }); var content = Application.Current.Host.Content; var nativeWidth = (int)Math.Floor(content.ActualWidth * content.ScaleFactor / 100.0 + 0.5); var nativeHeight = (int)Math.Floor(content.ActualHeight * content.ScaleFactor / 100.0 + 0.5); var physicalWidth = nativeWidth; var physicalHeight = nativeHeight; object physicalResolution; if (DeviceExtendedProperties.TryGetValue("PhysicalScreenResolution", out physicalResolution)) { var resolution = (System.Windows.Size)physicalResolution; var nativeScale = content.ActualHeight / content.ActualWidth; var physicalScale = resolution.Height / resolution.Width; // don't use physical resolution for devices that don't have hardware buttons (e.g. Lumia 630) if (Math.Abs(nativeScale - physicalScale) < 0.01) { physicalWidth = (int)resolution.Width; physicalHeight = (int)resolution.Height; } } UnityApp.SetNativeResolution(nativeWidth, nativeHeight); UnityApp.SetRenderResolution(physicalWidth, physicalHeight); UnityApp.SetOrientation((int)Orientation); DrawingSurfaceBackground.SetBackgroundContentProvider(UnityApp.GetBackgroundContentProvider()); DrawingSurfaceBackground.SetBackgroundManipulationHandler(UnityApp.GetManipulationHandler()); } }
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { UnityApp.SetOrientation((int)e.Orientation); }