heroiclabs / unity-sampleproject

A sample game called Pirate Panic for Unity engine built with Nakama server.
https://heroiclabs.com
Apache License 2.0
141 stars 40 forks source link

Update demo game to work with latest Nakama and with WebGL support #5

Closed saulrecon closed 3 years ago

saulrecon commented 5 years ago

Is it possible to update the sample project to include compatibility with Nakama (latest is 2.3.1) as well as support WebGL? I did notice a pull request with what seems to be the necessary updates (not WebGL though, I think), although there are some initial bugs with it as is. Thanks!!

novabyte commented 5 years ago

@saulrecon Yep. Thanks for the reminder. I'll take a look and see what needs to be updated. 👍

Godatplay commented 5 years ago

...and now 2.3.2. >_< +1

saulrecon commented 4 years ago

Any updates on this yet? I'm hoping to use this as part of a larger prototype for a new game type and would love to be able to leverage the built-in functionality in this demo game.

novabyte commented 4 years ago

Hey @saulrecon. I definitely don't want to limit your chance to leverage this code to prototype. We're a bit swamped with the lead up to Christmas. Lots of game studios want to get their games ready for the Christmas season/launch.

We'll handle it in the new year or happy to give advice on how to approach the upgrade if you want.

polats commented 4 years ago

Hi everyone, we're also interested in using Nakama + WebGL for some of our projects. @novabyte I can take a stab at doing the upgrade, some advice would surely be helpful!

I've started with making an HTML5 compile and running the app via serve on node.js.

On start I get the error:

Counldn't connect to Nakama server; message: System.TypeInitializationException: The type initializer for 'System.Threading.Timer' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Threading.Timer.Scheduler' threw an exception. ---> System.SystemException: Thread creation failed. UnityLoader.js:4 at System.Threading.Thread.StartInternal (System.Security.Principal.IPrincipal principal, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0

and when clicking a retry, I get the following:

Counldn't connect to Nakama server; message: System.ArgumentNullException: Value cannot be null. UnityLoader.js:4 Parameter name: obj UnityLoader.js:4 at System.Threading.Monitor.ReliableEnterTimeout (System.Object obj, System.Int32 timeout, System.Boolean& lockTaken) [0x00000] in <00000000000000000000000000000000>:0

Attaching screenshot of the console below:

image

novabyte commented 4 years ago

@polats It looks like the code uses timer tasks in a few places which won't work in WebGL because Unity doesn't know how to convert it to a window.setTimeout call. I think the best approach will be to just remove those code paths.

Godatplay commented 4 years ago

Our studio is looking to do the same thing. Is it possible to merge in the pull request, then those of us migrating this could add more after that?

polats commented 4 years ago

I'll try and do a PR once I have a clean fix. I've had some initial success and was able to login to Nakama by using the Nakama 2.2 update by @ArisTsevrenis https://github.com/heroiclabs/unity-sampleproject/pull/4

From that update I had to initialize the Nakama Client with UnityWebRequestAdapter as discussed here: https://github.com/heroiclabs/nakama-unity#unity-webgl

Then I had to create a different way to get a device id (NakamaSessionManager.cs) since SystemInfo.deviceUniqueIdentifier doesn't work on WebGL.

I'm still running into some of the Timer Task issues when changing the user name, will continue investingating:

image

polats commented 4 years ago

@Godatplay I have an in-progress build forked here: https://github.com/polats/unity-sampleproject/tree/webgl-fix-11-22-2019

The build runs the updated Nakama version from https://github.com/heroiclabs/nakama-unity (2.4.0-dev), and should properly compile and run as a webGL executable.

Some issues remaining though:

Not sure if we should do a pull-request because of the above issues.

novabyte commented 3 years ago

We've completed a code refresh of this project which updates it to the latest client SDK.