当前位置:主页 > 游戏服务器 > 应用安全 >

云存储_刀片机服务器_年度促销

If you are an SAP Employee, please follow us on Jam.

Since a long time…I had the idea of making Unity3D and Alexa work together…however…other project kept me away for actually doing it…so…a couple of days ago…a conversation with a friend made me remember that I actually really wanted to do this…so I did

At first…I wasn’t exactly sure how to do it…but then slowly the main idea came into my mind…what if Unity read a webservice that gets updated by Alexa? When the right command is parsed, then Unity will create the object and problems is solved…seems easy? Well…it actually is…

First things first…we need to create a small NodeJS webserver on Heroku…then…we need to install the Heroku Toolbelt…

Now…create a folder called node_alexa and inside create the following files…

package.json

procfile

index.js

Once you have that…log into your Heroku Toolbelt and write the following…

Heroku Toolbelt

Your webservice is ready to rock You should be able to find by going to "http://yourappname.herokuapp.com/"

Now…this simple NodeJS powered webservice will serve as a simple Echo server…meaning…whatever you type will be returned as a json response…of course…if you type "empty" then the response will be a empty json…so the main idea here is that we can keep the last entered value…if you pass a command it will be called again when you don’t pass any commands at all…so by calling it once…we can cal it multiple times without disrupting its value…

Next in line…will be to create our Unity app…

Create a new app and call it "WebService" or something like that…project name doesn’t matter too much…

If the Hierarchy window select "Main Camera" and change the "Tranform" details like this…

Now, create a new "3D Object" -> "Cube" and name it "Platform" with the following "Transform" details…

After that, we might need to create four wall that will go around the platform…so create 4 "3D Object" -> "Cube" and name them "Wall 1", "Wall 2", "Wall 3" and "Wall 4″…

When everything is ready, your workspace should look like this…

Go to the project tab and create a new folder called "plugins" and then create a new C# file called "SimpleJSON"…inside copy the source code from here…this will allow us to use SimpleJSON to parse the JSON…

Now…create another folder called "Script" and inside create a new C# file called "MetaCoding"…or whatever you like… MetaCoding.cs

Once you have the code…simply attach the script to the Main Camera…

The basic concept for this script is pretty simple…We’re creating "DownloadWebService" as an IEnumerator method so we can call it as a Coroutine…and that allow us to have a sleep as we want to give some time between calls…

This method will fetch our Heroku WebService looking for a "create" command…once it has it…it will parse the JSON response and split in 3…so we can have…"create", "blue" and "sphere"…this will call CreateObject which will then create a blue sphere…after we have done that…the coroutine will continue as simply send a new command to our WebService to clean the output…to make this work nicely…we want to give 5 seconds after we clean the webservice before trying to see if there’s another "create" call…

And this call be will be done by our Alexa skill…so basically when saying "create blue sphere" on Alexa…she will be send the command to the WebService…update the message and our Unity app will grab it…do its work…and clean up the Webservice…the wait for Alexa to provide the next command…

So…to kind of wrap up…we need to create our Alexa skill…

First, we’re going to create a Lambda function…so log in here…

Of course…I have everything already setup…so I’m going to create a dummy function just to show the steps…

Click on "Create Lambda Function" and you will be presented with this…

There’s a bunch of course…so type in "Color" in the filter box…

Choose "alexa-skills-kit-color-expert"

Leave this as it is and press "Next"

Choose a name and a description…

Choose an existing role if you have it already…otherwise just create a lambda_basic_execution…then raise up Timeout to 10 seconds and leave everything else as it is…press "Next"…a confirmation window will appear…so just press "Create function"…

You will be presented with a screen where you can upload your source code (which will be doing later on) and an ARN number…which we need for the next step…

The following part deals with create the Alexa skill…so please follow along…and log in here…

Choose "Alexa Skills Kit"…and create a new skill…

Choose a name for you skill and the most important…choose an "Invocation Name"…which is what you’re going to use tell Alexa to open you application…something like…"Alexa, open Sandbox"…click next…

On the Interaction Model tab we have two windows…fill this on "Intent Schema"…

Intent Schema

This are basically the parameters that we can use when asking Alexa to do something…

And fill this on "Sample Utterances"…

Sample Utterances

猜你喜欢

微信公众号