Reputation: 308
I am noob at unity. So, I am trying my best to explain the problem where I am stuck and I have no clue how to approach. I have a Ruby on Rails website running.
I am building a small game on unity which is much like an inventory management system. But, the inventory is specific to a user and the user can make changes to it. The user sees the game as a part of his dashboard. What I want to do:
Also,
Upvotes: 2
Views: 3339
Reputation: 1370
If you want to communicate directly with the browser, then
from WebGL to index.html - Application.ExternalCall("MyFunction", MyValue)
from index.html to WebGL - SendMessage("MyGameObject","MyFunction", MyValue)
So in your case the moment user land on his dashboard the unity should get something like id of user sign-in from browser which is need to call function from index.html and return it back to unity with the data you get from session.
WebGL
public void ReloadInventoryBaseOnUser()
{
Application.ExternalCall("GetUserID");
}
index.html
function GetUserID(){
//$.ajax here to get session id
SendMessage("Manager","SetUserID", userID);
focus();
}
WebGL
public void SetUserID(string ID){
userID = ID;
ReloadInventory(userID);
}
The session is server side thing, You can write an Http handler (that will share the session id if any) and return the value from there using $.ajax
. so assuming that you have store the id into js variable userID
Upvotes: 2
Reputation: 125445
You can test user sign in/sign out and dashboard in the Editor without building to WebGl. It will work but you should always test your game for WebGl once in a while during development to make sure that what you are doing will work in the future. Without doing this, your final game may not work because you used unsupported API for WebGL. That's why you must test the game but no all the time, just once in a while.
For communication with your server, you should use the new Unity API UnityWebRequest instead of WWW. The WWW class will be removed this month or in the coming months. UnityWebRequest fully supports WebGL build. .Net classes are NOT supported in WebGL Build. So you can't use anything like HttpWebRequest or Sockets...
Upvotes: 0