A limitation of Mirror support in UniVoice so far as been support for Host mode.
The main reason for this is that most teams using UniVoice have been doing so in a dedicated server environment.
However, Host mode has its own uses:
- makes it much easier to test in Unity. Run the server in the editor and the client on one build.
- local networking and co-op experiences.
- ParrelSync and other tools can be used to test multiplayer using two editor instances
So it only made sense to add support for it. I marked this as an enhancement I want to make in April, but recently there was a lot of activity on the Github issue so I got to work on it.
How it works
The changes are pretty simple. See the commit here
When in Host mode, the server needs to register local client with ID 0 immediately after starting up. This happens in MirrorServer.cs on line 85
When the server stops, or goes from Host to ServerOnly mode, the local client should disconnect. This happens on lines 99 and 90 respectively.
MirrorClient.cs needs a minor change. It needs to Unregister the MirrorMessage handler only when it goes from ClientOnly to Offline more. This happens on line 59
Some thoughts
I'm still not 100% sure how the RegisterHandler API in Mirror works. You register a handler by providing the listener method, but for unregistering you don't need it. This makes me think that if you were to register multiple times (which happens right now as it's done in both MirrorServer and MirrorClient), unregistering from either place would unregister both.
This makes me think that a Mirror message handler utility might be useful that wraps this functionality and adds the ability to unregister a single handler.
Future Plans
I plan on making a video showing this very soon.