Greetings, I’m venturing into multiplayer/networked game development using mirror and starting with a simple room/lobby implementation with a custom UI to learn the basics.
I am using the 2020.1.0b10.3837 version of Unity and grabbed the latest mirror code. I was able to build and run their room and chat examples.
I copied their NetworkRoomManagerExt and NetworkRoomPlayerExt classes into my project and was able to get it working but with the built-in development UI.
I am now trying to retrofit it to use my own custom UI.
I’ve wired the Host Game and Join buttons up to the NetworkRoomManager’s StartHost() and StartClient() methods and that all works great.
The problem arose when I tried to follow the pattern from the Mirror chat example to set the player name.
I added a Player Name property to the NetworkRoomManagerExt class and wired the OnValueChanged event of my player name input field to it.
Then, I added the following overrides:
public override void OnRoomStartServer()
{
base.OnRoomStartServer();
NetworkServer.RegisterHandler<CreatePlayerMessage>(OnCreatePlayer);
}
public override void OnClientConnect(NetworkConnection conn)
{
base.OnRoomClientConnect(conn);
Debug.Log($"OnClientConnect {conn?.connectionId ?? -1}, {conn?.identity?.hasAuthority}, {conn?.identity?.name ?? "null"}");
// tell the server to create a player with this name
conn.Send(new CreatePlayerMessage { name = PlayerName });
}
Note: I originally tried using OnRoomCoientConnect but that gave me this error:
So I tried using OnClientConnect() instead.
This is the result I’m getting:
I’m struggling to see how to use my custom UI with the room/lobby code I copied from the sample. The sample hides all the UI/Network interaction and I don’t see any good examples of how to replace the built-in developer UI with mine.
Here’s how I’ve layed out my UI:
The Host Button disables the Panel_Login and IPAddress input sections and calls StartHost().