コード例 #1
0
        private void DrawingSurfaceBackground_Loaded(object sender, RoutedEventArgs e)
        {
            if (!_unityStartedLoading)
            {
                _unityStartedLoading = true;

                UnityApp.SetLoadedCallback(() => { Dispatcher.BeginInvoke(Unity_Loaded); });

                int    physicalWidth, physicalHeight;
                object physicalResolution;

                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);

                if (DeviceExtendedProperties.TryGetValue("PhysicalScreenResolution", out physicalResolution))
                {
                    var resolution = (System.Windows.Size)physicalResolution;

                    physicalWidth  = (int)resolution.Width;
                    physicalHeight = (int)resolution.Height;
                }
                else
                {
                    physicalWidth  = nativeWidth;
                    physicalHeight = nativeHeight;
                }

                UnityApp.SetNativeResolution(nativeWidth, nativeHeight);
                UnityApp.SetRenderResolution(physicalWidth, physicalHeight);
                UnityPlayer.UnityApp.SetOrientation((int)Orientation);

                DrawingSurfaceBackground.SetBackgroundContentProvider(UnityApp.GetBackgroundContentProvider());
                DrawingSurfaceBackground.SetBackgroundManipulationHandler(UnityApp.GetManipulationHandler());
                if (isShowAds == 1)
                {
                    bannerAd = new AdView
                    {
                        Format   = AdFormats.Banner,
                        AdUnitID = "ca-app-pub-6844968633010430/8322003504"
                    };

                    bannerAd.FailedToReceiveAd += OnFailedToReceiveAd;
                    bannerAd.ReceivedAd        += OnReceivedAd;
                    AdRequest adRequest = new AdRequest();
                    //adRequest.ForceTesting = true;//here rem here
                    adGridAdmob.Children.Add(bannerAd);
                    bannerAd.LoadAd(adRequest);//hinh nh cai nay thua. Can kiem tra lai
                    // toanstt_Refresh_admob();
                }
            }
        }
コード例 #2
0
        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);
                UnityPlayer.UnityApp.SetOrientation((int)Orientation);

                DrawingSurfaceBackground.SetBackgroundContentProvider(UnityApp.GetBackgroundContentProvider());
                DrawingSurfaceBackground.SetBackgroundManipulationHandler(UnityApp.GetManipulationHandler());
            }
        }
コード例 #3
0
        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());
            }
        }
コード例 #4
0
        private void DrawingSurfaceBackground_Loaded(object sender, RoutedEventArgs e)
        {
            if (!_unityStartedLoading)
            {
                _unityStartedLoading = true;

                UnityApp.SetLoadedCallback(() => { Dispatcher.BeginInvoke(Unity_Loaded); });

                int    physicalWidth, physicalHeight;
                object physicalResolution;

                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);

                if (DeviceExtendedProperties.TryGetValue("PhysicalScreenResolution", out physicalResolution))
                {
                    var resolution = (System.Windows.Size)physicalResolution;

                    physicalWidth  = (int)resolution.Width;
                    physicalHeight = (int)resolution.Height;
                }
                else
                {
                    physicalWidth  = nativeWidth;
                    physicalHeight = nativeHeight;
                }

                UnityApp.SetNativeResolution(nativeWidth, nativeHeight);
                UnityApp.SetRenderResolution(physicalWidth, physicalHeight);
                UnityPlayer.UnityApp.SetOrientation((int)Orientation);

                DrawingSurfaceBackground.SetBackgroundContentProvider(UnityApp.GetBackgroundContentProvider());
                DrawingSurfaceBackground.SetBackgroundManipulationHandler(UnityApp.GetManipulationHandler());
            }
        }