Loupe

[Unity] Interagir entre Unity et vos applications Windows Phone 8 / Windows Store

Dans cet article, nous allons voir comment créer une passerelle entre Unity et vos applications Windows Phone 8 ou Windows Store.

Introduction

Quand vous travaillez avec ses plate-formes sous Unity, il va vous créer une solution Visual Studio avec tous les éléments d’une nouvelle solution pour ce type de projet (App.xaml, MainPage.xaml, …) mais adaptée pour être capable de lancer votre jeu.

Dans cette nouvelle solution, vous avez alors accès au framework de la plate-forme ciblée.

Créer une passerelle

Nous voulons être capable de lancer une action spécifique, comme le partage d’une image, dans notre code Unity qui pourra être utilisé par notre projet WP8/Windows Store.

   1: using System;
   2:  
   3: /// <summary>
   4: /// Windows specific and interop between Unity and Windows Store or Windows Phone 8
   5: /// </summary>
   6: public static class WindowsGateway
   7: {
   8:     public static Action<string, string, string> OnActionWithParametersRaised = delegate { };
   9:  
  10:     public static Action OnActionRaised = delegate { };
  11:  
  12:     static WindowsGateway()
  13:     {
  14:         OnActionWithParametersRaised = delegate { };
  15:         OnActionRaised = delegate { };
  16:     }
  17: }

On utilise une classe statique avec des délégués vides. Ces délégués pourront être implémentés dans notre projet WP8/Windows Store, dans la MainPage.xaml.cs par exemple.

   1: namespace MyUnityApp
   2: {
   3:     public partial class MainPage : PhoneApplicationPage
   4:     {
   5:         // [...]
   6:  
   7:         private void Unity_Loaded()
   8:         {
   9:             // [...]
  10:  
  11:             WindowsGateway.OnActionWithParametersRaised += OnActionWithParameters;
  12:             WindowsGateway.OnActionRaised += OnAction;
  13:         }
  14:  
  15:         private void OnAction()
  16:         {
  17:  
  18:         }
  19:  
  20:         private void OnActionWithParameters(string url, string title, string message)
  21:         {
  22:  
  23:         }
  24:  
  25:         // [...]
  26:  
  27:     }
  28: }

Et voilà ! Sourire

Ces billets pourraient aussi vous intéresser

Vous nous direz ?!

Commentaires

comments powered by Disqus