juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.09k stars 505 forks source link

Concrete implementation of IsLoaded for WebGL #892

Open t5ujiri opened 8 months ago

t5ujiri commented 8 months ago

Is your feature request related to a problem? Please describe. IsLoaded function throws UnimplementedError in WebGL builds, and it prevents me from waiting for Unity initialization to send first command from flutter.

Describe the solution you'd like the implementation of IsLoaded for WebGL

Describe alternatives you've considered If it's difficult to implement it with technical issues, workarounds would be appreciated.

timbotimbo commented 8 months ago

The web integration is simply an iframe with Unity WebGL, compared to iOS and Android which use Unity-as-a-library. Because of this most of the plugin API won't work on Web.

Sending messages to an from Unity is almost the only thing that actually works on web. For example even the pause function in the example is simply a message to a c# script in Unity, while on mobile it actually interacts with the unity instance.

I would suggest sending a message from Unity in a Start or Awake function, which lets you know in Flutter that your scene is available.

Web was once added in a pull request and hasn't really received much support or documentation after that.

Ahmadre commented 6 months ago

The web integration is simply an iframe with Unity WebGL, compared to iOS and Android which use Unity-as-a-library.

Because of this most of the plugin API won't work on Web.

Sending messages to an from Unity is almost the only thing that actually works on web.

For example even the pause function in the example is simply a message to a c# script in Unity, while on mobile it actually interacts with the unity instance.

I would suggest sending a message from Unity in a Start or Awake function, which lets you know in Flutter that your scene is available.

Web was once added in a pull request and hasn't really received much support or documentation after that.

Good point @timbotimbo 🙏

My production project has reached an advanced state and I could integrate now a current "onUnityLoaded" implementation for Web now.

You're also right Web came from me and I just added some sections about WebGL in Readme. But @juicycleff and myself wanted to create a docs page and not spam everything in the Readme.

Let me implement that onLoaded Callback and then I will add an architecture overview for all platforms.

I will notify you @t5ujiri when it's merged into base branch.