Git Product home page Git Product logo

appservices's Introduction

Azure App Services for Unity3d

For game developers looking to use Azure App Services (previously Mobile Services) in their Unity project. This App Services REST API library for Unity is quite similar in structure to the Azure Mobile Services SDK so if you've used that before you should feel relatively at home.

Prerequisites

Requires Unity v5.3 or greater as UnityWebRequest and JsonUtility features are used. Unity will be extending platform support for UnityWebRequest so keep Unity up to date if you need to support these additional platforms.

How to setup App Services with a new Unity project

  1. Download AppServices
    • Copy 'AppServices' into project Assets folder.
  2. Create an Azure App Service Mobile App
    • Create a Table (using Easy Tables) for app data.

Azure App Services Demos for Unity 5

Try the Azure App Services Demos project for Unity v5.4.x on Mac / Windows. (The demo project has got everything already bundled in and does not require any additional assets to work. Just wire it up with your Azure App Service and run it right inside the Unity Editor.) For detailed instructions read my developer blog on how to setup Azure App Services and Unity demo project.

Supported Features

MobileServiceClient

API Description
Login Client-directed login using access token.
InvokeApi Invoke custom API (Easy API) using GET, POST, PUT, PATCH or DELETE

MobileServiceTable

API Description
Insert Create a new item.
Read Get a list of items.
Update Update an item’s data using id property.
Delete Delete an item using id property.
Query Get a list of results using a custom query.
Lookup Get an item’s data using id property.

MobileServiceClient Interface

Login(MobileServiceAuthenticationProvider provider, string token,	Action<IRestResponse<MobileServiceUser>> callback = null);
InvokeApi<T>(string apiName, Action<IRestResponse<T>> callback = null) where T : new();
InvokeApi<T>(string apiName, Method httpMethod, Action<IRestResponse<T>> callback = null) where T : new();
InvokeApi<T>(string apiName, Method httpMethod, T body, Action<IRestResponse<T>> callback = null) where T : new();

MobileServiceTable Interface

Insert<T>(T item, Action<IRestResponse<T>> callback = null) where T : new();
Read<T>(Action<IRestResponse<T[]>> callback = null) where T : new();
Update<T>(T item, Action<IRestResponse<T>> callback = null) where T : new();
Delete<T>(string id, Action<IRestResponse<T>> callback = null) where T : new();
Query<T>(CustomQuery query, Action<IRestResponse<T[]>> callback = null) where T : new();
Query<T>(CustomQuery query, Action<IRestResponse<T>> callback = null) where T : INestedResults, new();
Lookup<T>(string id, Action<IRestResponse<T>> callback = null) where T : new();

Sample usage

using UnityEngine;
using System;
using System.Net;
using System.Collections.Generic;
using Unity3dAzure.AppServices;

private MobileServiceClient _client;
private MobileServiceTable<TodoItem> _table;
void Start () {
	_client = new MobileServiceClient(appUrl); // <- add your app url here.
	_table = _client.GetTable<TodoItem>("TodoItem");
}
private void ReadItems() {
	StartCoroutine( _table.Read<TodoItem>(OnReadItemsCompleted) );
}

private void OnReadItemsCompleted(IRestResponse<TodoItem[]> response) {
	if (!response.IsError) {
		Debug.Log ("OnReadCompleted: " + response.Url + " data: " + response.Content);
		TodoItem[] items = response.Data;
		Debug.Log ( "Todo items count: " + items.Count);
	} else {
		Debug.LogWarning ("Read Error Status:" + response.StatusCode + " Url: " + response.Url);
	}
}

Known issues

  • There is an issue with PATCH on Android using UnityWebRequest with Azure App Services. Android won't recognize the "PATCH" http method currently required to update an item in App Services. One workaround is to enable the X-HTTP-Method-Override header. Here's the quick fix for App Services running node backend:
    1. Install the "method-override" package.
      npm install method-override --save
      
    2. In 'app.js' file insert:
      var methodOverride = require('method-override');  
      // after the line "var app = express();" add  
      app.use(methodOverride('X-HTTP-Method-Override'));
      

This will enable PATCH requests to be sent on Android.

Supported platforms

Will work on all the platforms UnityWebRequest supports including:

  • Unity Editor and Standalone players
  • iOS
  • Android
  • Windows

Questions or tweet #Azure #GameDev @deadlyfingers

appservices's People

Contributors

deadlyfingers avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.