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. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Creating a Windows Azure Mobile Services plugin

Discussion in 'Windows' started by digitalerr0r, Sep 15, 2013.

  1. digitalerr0r

    digitalerr0r

    Joined:
    Sep 15, 2013
    Posts:
    25
    Hi,
    I'm trying to get Windows Azure Mobile Services working with unity and I think the only way is to implement my own plugin?

    I started doing this (https://docs.unity3d.com/Documentation/Manual/windowsstore-plugins.html), creating one Class Library for Windows 8 and then use NuGet to install the Windws Azure Mobile Services SDK and then having a function that is trying to insert a new item to my service. Then I added another project to the solution thats targets .Net Framework 3.5 with the same namespace and functions so that the Editor doesn't give me any exceptions. (I also copy the built dll files from the plugin-projects folder to the assets/plugins/(metro) folder)

    It builds but nothing really happens (except for the Debug.Log telling me that the functions are running).

    Anyone tried to do anything similar, or know where I'm making my mistakes?

    (I know about the plugin from bitrave, but would like to know the process of writing my own - http://www.bitrave.com/azure-mobile-services-for-unity-3d/)

    Thanks for any help!
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    9,894
    Could you elaborate on "nothing happens" part? You can attach a debugger to your scripts when it's running on the phone and check what is going on.
     
  3. digitalerr0r

    digitalerr0r

    Joined:
    Sep 15, 2013
    Posts:
    25
    Thanks for your responsIt seems like the dependencies are ok and that I got the correct DLLs, and I don't get any exceptions regarding this.
    The Unity game scene is simply rendering a GUI.Label with a string that is set in the plugin.

    GUI.Lable(rect, AzurePlugin.Windows.Insert());

    The GUI string is set correctly to: "Awesome item 2" because the Insert function looks like this:

    public static string Insert()
    {
    Item item = new Item { Text = "Awesome item 2" };
    MobileService.GetTable<Item>().InsertAsync(item);

    return item.Text;
    }

    In other words, the Insert function runs and returns, but nothing gets inserted in the mobile service when i log in to Windows Azure.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    9,894
    what is Item defined as? It's a struct I suppose?
     
  5. digitalerr0r

    digitalerr0r

    Joined:
    Sep 15, 2013
    Posts:
    25
    That is a class.
    Here is the entire plugin:

    Code (csharp):
    1.  
    2. using Microsoft.WindowsAzure.MobileServices;
    3. using System;
    4.  
    5. namespace AzureMobilePlugin
    6. {
    7.     public class AzureMobile
    8.     {
    9.         public static MobileServiceClient MobileService = new MobileServiceClient(
    10.             "https://mytestgame.azure-mobile.net/",
    11.             "authstring"
    12.         );
    13.  
    14.         public static string Insert()
    15.         {
    16.             Item item = new Item { Text = "Awesome item 2" };
    17.            
    18.             try
    19.             {
    20.                 MobileService.GetTable<Item>().InsertAsync(item);
    21.             }
    22.             catch (Exception e)
    23.             {
    24.                 return e.InnerException.Message;
    25.             }
    26.  
    27.             return item.Text;
    28.         }
    29.  
    30.         public void Get()
    31.         {
    32.             IMobileServiceTable<Item> todoTable = MobileService.GetTable<Item>();
    33.         }
    34.     }
    35.  
    36.     public class Item
    37.     {
    38.         public int Id { get; set; }
    39.         public string Text { get; set; }
    40.     }
    41. }
    42.  

    And the game:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class AzureTest : MonoBehaviour
    5. {
    6.     string lol = "Insert";
    7.     // Use this for initialization
    8.     void Start()
    9.     {
    10.        
    11.     }
    12.  
    13.     void OnGUI()
    14.     {
    15.         if(GUI.Button(new Rect(0, 0, 100, 100), lol))
    16.         {
    17.             lol = AzureMobilePlugin.AzureMobile.Insert();
    18.         }
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.  
    25.     }
    26. }
    And then I spenjt 1 min on manage.windowsazure.com to set up the service.
     
  6. digitalerr0r

    digitalerr0r

    Joined:
    Sep 15, 2013
    Posts:
    25
    Hi,
    stupid mistake. I though I had enabled the Internet (Client) capability in the app manifest but I hadn't.

    For anyone else having this issue (seen a few around), the solution is this :)


    Thanks for the quick answers Tautvydas
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    9,894
    No problem :).
     
  8. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
    Hi digitalerr0r,
    Thanks for this post, it's very interesting.
    However I wonder about the portability of your plugin. Can you confirm that what you've posted can only work on Windows Phone / Windows App builds?
    What about other platforms?

    Thanks.