question

jeffrbake avatar image
jeffrbake asked

Communicate between Unity Game and Launcher in Electron

So I have been tossing back and forth the idea to make my game launcher in Electron (for multiple reasons, but in the end it gives a feature set that is cross platform).

The only thing I am concerned about is when you launch a game, how would I go about sending the player's login info to the Unity game so it silently logs them in as the game loads?

I know once they are logged in, I can access a saved lobby state from PlayFab to load them into the right session.

Also, I assume PlayFab has an API that I can take advantage of from html/css/js?

unity3d
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Andy avatar image
Andy answered

I'm not familiar with Electron, but I'm assuming it has some way of providing parameters to your game when it's launched. After logging in from your launcher, you'd want to get the player's SessionTicket and EntityToken that are returned from a successful Login API call. You can pass these into the game and then just start calling any other client APIs using the sessionKey or entityToken to authenticate.

The precise details of getting and setting the auth key/token vary depending on the SDK you're using, so let us know if you're not clear on how that might work.

For html/js, we have a couple of choices. The simplest is probably the javascript SDK, but you could also go with NodeJS or just straight web requests.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jeffrbake avatar image jeffrbake commented ·

I was thinking about this today. Electron uses Nodejs as its backend, so couldn't I set up an api on the nodejs side and call it from unity? Then the "web" side of the application built on electron could also use the API on node for its functionality.

My only question I would have then is:
a) Would I need to encrypt those calls since it would be on a local network, and therefor open to tinkering?
b) Would this require any special setup on the client side to allow it to work?

Going to try and put together a demo this weekend using this. Thoguhts?

0 Likes 0 ·
Andy avatar image Andy ♦♦ jeffrbake commented ·

I'm not clear on what exposing an API in the Electron backend will buy you. Are you planning on caching the results of the PlayFab login call and then retrieving them from your game once it's launched? Could you walk through the proposed flow in a bit more detail?

Also, encrypting traffic via https is just generally good practice and definitely something I'd advise. You don't want to be sending login credentials in clear text ever.

0 Likes 0 ·
jeffrbake avatar image jeffrbake Andy ♦♦ commented ·

Player opens client -> client prompts for login -> on successful login client checks to make sure version is latest for the game -> Player can use the client to buy goods, change their character or change other settings related to the game
-------------
Player enters a lobby in the client, and when matched with other players, electron launches the game. -> When the game is launched, in the start function for the GameManager, it will send an api call to Nodejs asking for the login credentials for the player -> nodejs responds with the session ticket and also sends over the name of the lobby that they will be joining (PUN) as well as any other information needed for the game to load properly -> Game starts and the player plays the game.
-------------
Think of the client I wish to make a lot like the League of Legends client. You can do a lot of stuff regarding your account in it, but the actual game "League of Legends" is actually a separate application.

Once in the game, Unity will take over communication with PlayFab. I can also send information back to the electron client via nodejs to relay information. On game end, the game is closed and the client does its thing.

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.