Search Unity

Windows Store Game how to deal with snap view?

Discussion in 'Windows' started by GlutenFreeGames, Aug 14, 2013.

  1. GlutenFreeGames

    GlutenFreeGames

    Joined:
    Jun 13, 2013
    Posts:
    51
    Hey everyone,
    My game was rejected today for improperly dealing with when it's moved to the snap view. I believe in one of the videos I watched it said I could deal with this by simply pausing the game when it's in snapped view? Is there a function in Unity that responds to this snap view event? (for example: Application.EnteredSnapView?)
     
  2. GlutenFreeGames

    GlutenFreeGames

    Joined:
    Jun 13, 2013
    Posts:
    51
    would OnApplicationFocus or OnApplicationPause respond to the application being put into snap view? (I'm going to test my hunch but I would still love advice if anyone has any! thanks)
     
  3. SteAbra

    SteAbra

    Joined:
    Feb 2, 2010
    Posts:
    13
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,893
    As far as I recall OnApplicationPause, OnApplicationFocus aren't called when entering/leaving snapping, at least in 4.2. This should be fixed in 4.3.

    You have to subscribe to CoreApplication::Suspending, CoreApplication::Resuming events, and call appcallbacks.UnitySetPause(1) - to pause, appcallbacks.UnitySetPause(0) to unpause the game.
     
  5. GlutenFreeGames

    GlutenFreeGames

    Joined:
    Jun 13, 2013
    Posts:
    51
    Thanks everyone! Thanks Tomas, that sounds like it might be pushing my coding knowledge to the limits but I'll try it out!
     
  6. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    you should have your mainpage.xaml (or whatever you'ved called it) as a visual state aware page, and in mainpage.xaml.cs you create a handler for SizeChanged to your method... in which, you will check the value of applicationview.value and if it matches what you have defined in XAML for the "snapped" visual state.. you can make an appcallback to UnityPause(1) (1 = pause, 0 = unpause).

    you may be able to do a cleaner way in XAML/C# with Windows.UI.ViewManagement.ApplicationViewState.Snapped;
     
  7. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    i wanted to add that, i've tried two different ways to "pause" unity.. one using their appcallback method UnityPause , and a 'very' manual way of issuing dispatched events between Unity and XAML/C#, holding pause variable inside a gameobject in unity while settings time.timescale to a very small float value...

    and well, it has interesting results.

    using appcallback method with UnityPause will freeze updates to the SwapChainBackgroundPanel, but "not" hold/drop marshaled delegates ... so you could in theory, have some strange things happening in-game if you say put in a trigger event via XAML/C# :)
     
  8. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Can someone elaborate more on the process of modifying your mainpage.xaml to make it visual state aware and adding a handler to the .cs file? I tried to use the linked-to video but since it's not using a unity built project I couldn't follow it exactly.
     
  9. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
  10. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    I'm having the same problem trying to determine if my app has been placed in snap view mode. Screen.fullscreen doesn't work as it seem to always return False.

    tswalk, can you elaborate on how to check Windows.UI.ViewManagement.ApplicationViewState.Snapped?
     
  11. digitalerr0r

    digitalerr0r

    Joined:
    Sep 15, 2013
    Posts:
    25
  12. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    Hi digitalerr0r! Your blog post is superb.

    One question:
    Is there a way for the App.xaml.cs to call a non-static function? I need to do more than just pause the game when it is snapped. I need to perform other tasks such as showing different content on the screen, etc.

    Is it possible for the App.xaml.cs to communicate with a specific instance of a Unity object?
     
  13. digitalerr0r

    digitalerr0r

    Joined:
    Sep 15, 2013
    Posts:
    25
    Yeah, I think you can do whatever you want - as the script you are executing is written inside a Unity script. So let that function do what you need - you can call everything you want from the xaml code behind file. Also create instances and so on. You can also let the static function initiate a series of things like displaying another set of GUI before pausing. You dont need to pause at all even, just show a leaderboard or whatever - it's up to you! :)
     
  14. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    My problem now is that I only know how to call a static class/method (thanks to your excellent blog post) and I don't know how to do anything useful inside of a static class. I want to change the background, show some sprites and text, etc. How do I do that inside of a static class?

    How can my static class communicate with my instantiated objects?
     
  15. digitalerr0r

    digitalerr0r

    Joined:
    Sep 15, 2013
    Posts:
    25
    There are many ways, but one way would be to try and find it using var _findResult = GameObject.Find("ObjectName") and then you can search for a component of that result using GetComponent. This can be done inside a static class/function. I can post some code later, as im currently on a mobile device.
     
  16. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    Thanks digitalerr0r! I tried doing that earlier, but must have had some bugs in my code. I have it working now with the code below:

    Code (csharp):
    1. GameObject oMainGO = GameObject.Find("Main");
    2. Main oMain = (Main)oMainGO.GetComponent("Main");
    Thanks again for your help!
     
  17. digitalerr0r

    digitalerr0r

    Joined:
    Sep 15, 2013
    Posts:
    25
    Glad I could help, good that you got it working!
     
  18. Default117

    Default117

    Joined:
    Mar 13, 2011
    Posts:
    134
    Since we're on the topic, i'm trying to achieve this by writing a plugin. Through this plugin i can 'register' call backs from C# which will then be called from the plugin if a size change is detected.

    But whenever i do "using Windows.UI.Core;" so that i can use WindowSizeChangedEventArgs, i'm unable to compile.

    If i listen for OnWindowSizeChange in the main app cs file, i have no issues.
    Any ideas?
     
  19. digitalerr0r

    digitalerr0r

    Joined:
    Sep 15, 2013
    Posts:
    25
    Is this in the plugin that loads in Unity? You need to place Windows spesific plugins inside Plugins/Metro folder, and then create a "fake" plugin that contains the same functions inside the Editor plugin (they need to have the same name).

    Check this article, it's about writing a Windows Azure plugin, but don't worry about that - scroll down to Part II of this article to learn the concepts and how to do it:
    http://digitalerr0r.wordpress.com/2...the-cloud-with-windows-azure-mobile-services/
     
  20. Default117

    Default117

    Joined:
    Mar 13, 2011
    Posts:
    134
    Yeah i've got that part down pat, fake dll and real dll ;)
    As an example:

    Code (csharp):
    1. using System;using System.Collections.Generic;
    2. using System.Diagnostics;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Threading.Tasks;
    6. using Windows.UI.Core;
    7. using Windows.UI.Xaml;
    8.  
    9.  
    10. namespace Win8Plugin
    11. {
    12.     public class Snap
    13.     {
    14.         public static void RegisterForSnap()
    15.         {
    16.             Window.Current.SizeChanged += Current_SizeChanged;
    17.         }
    18.  
    19.  
    20.         private static void Current_SizeChanged(object sender, WindowSizeChangedEventArgs e)
    21.         {
    22.             Debug.WriteLine("A change in size was detected");
    23.         }
    24.     }
    25. }
    But when i try to build it, i get this error: