Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Win App Store - xaml callbacks to handle Snap mode

Discussion in 'Scripting' started by ItsAmee, Aug 7, 2014.

  1. ItsAmee

    ItsAmee

    Joined:
    Nov 22, 2012
    Posts:
    11
    I'm using XAML callbacks to find out id the game window is in snap mode or not. The following code works if the Snap window is only 1/4 screen width, but stretch it widen and it fails.
    The crux seems to be testing ;- Window.Current.SizeChanged += Current_SizeChanged; rather than is the app running 'full screen'.
    I'm thinking I should include a test to see if the snapped window is more than screen.width * 0.75 or something but can't find any way to pole the screen resolution.
    Or any better ideas?

    Code (CSharp):
    1. using System;
    2.  
    3. using System.Collections.Generic;
    4.  
    5. using System.IO;
    6.  
    7. using System.Linq;
    8.  
    9. using Windows.ApplicationModel;
    10.  
    11. using Windows.ApplicationModel.Activation;
    12.  
    13. using Windows.Foundation;
    14.  
    15. using Windows.Foundation.Collections;
    16.  
    17. using Windows.UI.Core;
    18.  
    19. using Windows.UI.Xaml;
    20.  
    21. using Windows.UI.Xaml.Controls;
    22.  
    23. using Windows.UI.Xaml.Controls.Primitives;
    24.  
    25. using Windows.UI.Xaml.Data;
    26.  
    27. using Windows.UI.Xaml.Input;
    28.  
    29. using Windows.UI.Xaml.Media;
    30.  
    31. using Windows.UI.Xaml.Navigation;
    32.  
    33. using UnityPlayer;
    34.  
    35. using Windows.UI.ViewManagement;
    36.  
    37. // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
    38.  
    39. namespace Template
    40.  
    41. {
    42.  
    43.   /// <summary>
    44.  
    45.   /// Provides application-specific behavior to supplement the default Application class.
    46.  
    47.   /// </summary>
    48.  
    49.   sealed partial class App : Application
    50.  
    51.   {
    52.  
    53.   private WinRTBridge.WinRTBridge _bridge;
    54.  
    55.   private AppCallbacks appCallbacks;
    56.  
    57.   /// <summary>
    58.  
    59.   /// Initializes the singleton application object.  This is the first line of authored code
    60.  
    61.   /// executed, and as such is the logical equivalent of main() or WinMain().
    62.  
    63.   /// </summary>
    64.  
    65.   public App()
    66.  
    67.   {
    68.  
    69.   this.InitializeComponent();
    70.  
    71.   appCallbacks = new AppCallbacks(false);
    72.  
    73.   appCallbacks.RenderingStarted += RemoveSplashScreen;
    74.  
    75.   }
    76.  
    77.   /// <summary>
    78.  
    79.   /// Invoked when the application is launched normally by the end user.  Other entry points
    80.  
    81.   /// will be used when the application is launched to open a specific file, to display
    82.  
    83.   /// search results, and so forth.
    84.  
    85.   /// </summary>
    86.  
    87.   /// <param name="args">Details about the launch request and process.</param>
    88.  
    89.   protected override void OnLaunched(LaunchActivatedEventArgs args)
    90.  
    91.   {
    92.  
    93.   appCallbacks.SetAppArguments(args.Arguments);
    94.  
    95.   Frame rootFrame = Window.Current.Content as Frame;
    96.  
    97.   // Do not repeat app initialization when the Window already has content,
    98.  
    99.   // just ensure that the window is active
    100.  
    101.   if (rootFrame == null && !appCallbacks.IsInitialized())
    102.  
    103.   {
    104.  
    105.   var mainPage = new MainPage(args.SplashScreen);
    106.  
    107.   Window.Current.Content = mainPage;
    108.  
    109.   Window.Current.Activate();
    110.  
    111.   // Setup scripting bridge
    112.  
    113.   _bridge = new WinRTBridge.WinRTBridge();
    114.  
    115.   appCallbacks.SetBridge(_bridge);
    116.  
    117.   appCallbacks.SetKeyboardTriggerControl(mainPage);
    118.  
    119.   appCallbacks.SetSwapChainBackgroundPanel(mainPage.GetSwapChainBackgroundPanel());
    120.  
    121.   appCallbacks.SetCoreWindowEvents(Window.Current.CoreWindow);
    122.  
    123.   appCallbacks.InitializeD3DXAML();
    124.  
    125.   }
    126.  
    127.   Window.Current.Activate();
    128.  
    129.   Window.Current.SizeChanged += Current_SizeChanged;
    130.  
    131.   }
    132.  
    133.   void Current_SizeChanged(object sender, WindowSizeChangedEventArgs e)
    134.  
    135.   {
    136.  
    137.   ApplicationViewState myViewState = ApplicationView.Value;
    138.  
    139.   if (myViewState == ApplicationViewState.Snapped)
    140.  
    141.   {
    142.  
    143.   AppCallbacks.Instance.InvokeOnAppThread(new AppCallbackItem(() =>
    144.  
    145.   {
    146.  
    147.   Windows8Handler.PauseGame(true);
    148.  
    149.   }), false);
    150.  
    151.   }
    152.  
    153.   else
    154.  
    155.   {
    156.  
    157.   AppCallbacks.Instance.InvokeOnAppThread(new AppCallbackItem(() =>
    158.  
    159.   {
    160.  
    161.   Windows8Handler.PauseGame(false);
    162.  
    163.   }), false);
    164.  
    165.   }
    166.  
    167.   }
    168.  
    169.   private void RemoveSplashScreen()
    170.  
    171.   {
    172.  
    173.   try
    174.  
    175.   {
    176.  
    177.   MainPage page = (MainPage)Window.Current.Content;
    178.  
    179.   page.RemoveSplashScreen();
    180.  
    181.   }
    182.  
    183.   catch (InvalidCastException)
    184.  
    185.   { }
    186.  
    187.   }
    188.  
    189.   }
    190.  
    191. }
     
    Last edited: Aug 7, 2014
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Please use code tags
    Code (csharp):
    1.  
    code is unreadable if not
     
  3. ItsAmee

    ItsAmee

    Joined:
    Nov 22, 2012
    Posts:
    11
    Thanks, better?