Code Monkey home page Code Monkey logo

appservicesdemo's Introduction

Azure App Services for Unity3d

Contains a Unity 5 project featuring two demo scenes for Azure App Services (previously Mobile Services).

  1. Highscores demo scene
  2. Inventory demo scene

:octocat: Download instructions

This project contains git submodule dependencies so use:
git clone --recursive https://github.com/Unity3dAzure/AppServicesDemo.git

Or if you've already done a git clone then use:
git submodule update --init --recursive

Highscore demo features

  • Client-directed login with Facebook
  • Insert Highscore
  • Update Highscore
  • Read list of Highscores using infinite scrolling (hall of fame)
  • Query for today's top ten highscores (daily leaderboard)
  • Query for username (user's scores)

App Services Highscores Unity demo video

Inventory demo features

  • Client-directed login with Facebook
  • Load User's inventory.
  • Save User's inventory. (Inserts if new or Updates existing record)

App Services Inventory Unity demo video

Developer blogs

Setup Azure App Services for Unity

  1. Create an Azure Mobile App
    • Create 'Highscores' and 'Inventory' table for storing app data using Easy Tables.
  2. In Unity open scene file(s) inside the Scenes folder:
    • HighscoresDemo.unity
    • InventoryDemo.unity
  3. Then select the AppServicesController gameobject in the Unity Hierarchy window and paste your Azure App Service URL into the Editor Inspector field.
    alt Unity Editor Mobile Services config

Setup Azure App Services with Authentication

This demo uses Facebook identity to save user's highscore or inventory items:

  1. Create Facebook app
  2. Fill in the Azure App Services Authentication settings with Facebook App Id & App Secret.
  3. Paste Facebook access user token into Unity access token field to enable Login button.
  4. Modify 'Highscores' and 'Inventory' table script (using 'Insert' snippet below) to save user.id

Easy Table Insert script (tables/Highscores.js, tables/Inventory.js)

var table = module.exports = require('azure-mobile-apps').table();
table.insert(function (context) {
	if (context.user) {
		context.item.userId = context.user.id;
	}
	return context.execute();
});

Setup Azure App Services custom APIs with Easy APIs

With Azure App Services you can create custom APIs using Easy APIs.

  1. Create a 'hello' api (using "get" method) to say hello! (Example Easy API message script below)
  2. Create a 'GenerateScores' api (using "post" method) to generate 10 random scores. (Example Easy API query script below)

Easy API 'hello' script (api/hello.js)

module.exports = {
    "get": function (req, res, next) {
        res.send(200, { message : "Hello Unity!" });
    }
}

Easy API 'GenerateScores' script (api/GenerateScores.js)

var util = require('util');
module.exports = {
    "post": function (req, res, next) {
        var insert = "INSERT INTO Highscores (username,score) VALUES ";
        var i = 10;
        while (i--) {
            var min = 1;
            var max = 1000;
            var rand = Math.floor(Math.random() * (max - min)) + min;
            var values = util.format("('%s',%d),", 'Zumo', rand);
            insert = insert + values;
        }
        insert = insert.slice(0, -1); // remove last ','
        var query = {
            sql: insert
        };
        req.azureMobile.data.execute(query).then(function(results){
            res.send(200, { message : "Zumo set some highscores!" });
        });
    }
}

Known issues

  • There is an issue with PATCH on Android using UnityWebRequest with Azure App Services. Android doesn't support PATCH requests made with UnityWebRequest needed to perform Azure App Service updates. 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.

Credits

Dependencies included

  • TSTableView is used to display recyclable list of results.

Dependencies installed as git submodules

Refer to the download instructions above to install these submodules.

Questions or tweet #Azure #GameDev @deadlyfingers

appservicesdemo's People

Contributors

deadlyfingers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

appservicesdemo's Issues

Problem with UWP in Unity 5.5.1f

Table operations usually work in the editor. But not on my Windows Phone 10. Error occurs while trying to insert.

Should this plugin work on Windows Universal 10?

Details of getting facebook login to work

So I created an app on facebook.

Copied the key and pasted that in the code.

Turned on authentication for facebook in the Mobile App and checked everything

Ran the code. Clicked Login. And I get

image

Fix Unity asset database error

Some links are broke in Unity Editor after checking in and need to be manually reconnected.
Unity Console mentions "Rebuilding Library because asset database could not be found." But it should be ok not to check in the Library directory.

Add support for Windows UnityEditor

Support to be added for Windows UnityEditor and running as Windows modern app.

Also to mark this update Unity3D serialized fields will also be enabled in Unity Editor to allow easier entry of Azure Mobile Services config.
unityazureserializefield

Sending and using variables in an easy api call

Hi
Im just working with the azure code here, and wondering if there is an example anywhere of sending custom data to the easy api system and then being able to access that on the server. So far i have been trying to use
/// <summary> /// Invokes custom API with body (of type B) and returning response (of type T) /// </summary> public IEnumerator InvokeApi<B, T>(string apiName, Method httpMethod, B body, Action<IRestResponse<T>> callback = null) where T : new() { string url = ApiUrl(apiName); Debug.Log(httpMethod.ToString() + " custom API Request Url: " + url); ZumoRequest request = new ZumoRequest(url, httpMethod, true, User); request.AddBody<B>(body); yield return request.Request.Send(); request.ParseJson<T>(callback); }

but appear to not receive the body under the req in the get request on easy api. is there an example of something i can do here, any help would be greatly appreciated. Thanks

Add support for UniTask and Use UnityEngine.Networking.

This is more of a suggestion really.
Rather than use WWW.EscapeURL and Request.Send(),
instead use UnityWebRequest.EscapeURL() and Request.SendWebRequest()
from the UnityEngine.Networking namespace.

##Then try replacing the IEnumerator coroutines with UniTask types
Great work with this.

Missing Files

When opening the project in Unity there seems to be several files missing. More specifically
DataModel, Azure, RESTClient, AppServiceClient, AppServiceTable, IRestResponse

AAD demo

Had a request to show AAD as sign-in option in addition to the social sign-in options already available.

Calls never complete

Hello,

I made a fork of bitrave here and modified it but have experienced quite a few issues when it comes to building thus my search for something else. I found Unity3dAzure and it is good to see you are carrying on! I am more than interested to help development with this. Anyway onto the issue!

I tried cloning this repo and following the steps but none of the network requests ever seem to complete. Ignore the error, that is related to onGUI code from inputting a score

capture

Infinite scrolling

The Read results are limited to 50 results by default. But demo would be nicer with infinite scrolling buffer to load in next page of results into the table view.

Easy Tables are unsupported service. Is there a way to avoid Easy Tables ?

The steps

  1. Load VS2015.
  2. Create ASP.NET 5 Web API + add DB and DB SERVER
  3. Publish to Azure
  4. Goto 'Web App' Click 'Easy tables'

not supported..

I was trying to get a jump on using the ASP.NET 5 stuff since it is all shiny new

Can I just connect to the blank DB with SQL Man Studio and create new table ?

Keeping dependencies up to date

This demo project has a couple of dependencies - both of which are copied into the 'Assets' folder:

I would like to keep these packages up to date without having to bundle them as part of this repro. At the same time however I like the way this demo project is self contained and means people can just grab the zip archive without having to run additional git commands to download submodules for example.

Here are the options that come to mind:

  1. Leave as is - just bundle everything in this repro.
  2. git submodules (pity GitHub doesn't include the dependencies as part of zip archive)
  3. git subtree (makes things complicated and requires advanced git-fu)
  4. A Unity3d package manager could download external dependencies when opening the project (ok not sure if this option exists, but it should!)

Request: Support and example code for using Azure Blob storage

These tools are great for working with databases on Azure from Unity. I went from having no idea where to start to doing database lookup very quickly.

I would love to be able to save and load files to Azure blob storage with the same convenience. An example of how to use the REST API to do that would be very helpful.

Unity3d script broken links

For some reason the Scene script links always break between different computer setups. The scripts have to be removed and then re-attached to the Scene. Is there any way to stop this happening?

Specific instructions on how to create the HighScore table with a Mobile App Service

I created an easy table and a database.

Not sure if that is what I do or something else. Where exactly do I past in the js script?

How would an example that uses a API App Service be different ?

I imagine in the long run I would want to create Azure API App Service since you have swagger and can then easily expose that endpoint to other things like LOGIC APPS

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.