Simplify add player extra data (#537)

* Simplify add player extra data

* Pass byte[] in the client too

* Renamed to extra message
This commit is contained in:
Paul Pacheco 2019-03-03 12:53:24 -06:00 committed by vis2k
parent 001cec6d82
commit e4fbbeddc3
4 changed files with 8 additions and 30 deletions

View File

@ -195,7 +195,7 @@ public override void OnServerDisconnect(NetworkConnection conn)
OnLobbyServerDisconnect(conn);
}
public override void OnServerAddPlayer(NetworkConnection conn)
public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage)
{
if (SceneManager.GetActiveScene().name != LobbyScene) return;

View File

@ -18,7 +18,7 @@ This demonstrates how to set the parent of the LobbyPlayerPrefab to an arbitrary
A similar technique would be used if a full canvas layout UI existed and we wanted to show
something more visual for each player in that layout, such as a name, avatar, etc.
Note: LobbyPlayer prefab will be marked DontDestroyOnLoad and carried forward to the game scene.
Note: LobbyPAlayer prefab will be marked DontDestroyOnLoad and carried forward to the game scene.
Because of this, NetworkLobbyManager must automatically set the parent to null
in ServerChangeScene and OnClientChangeScene.
*/

View File

@ -64,7 +64,7 @@ internal static void InternalAddPlayer(NetworkIdentity identity)
// use this to implicitly become ready
// -> extraMessage can contain character selection, etc.
public static bool AddPlayer(NetworkConnection readyConn, MessageBase extraMessage)
public static bool AddPlayer(NetworkConnection readyConn, byte[] extraData)
{
// ensure valid ready connection
if (readyConn != null)
@ -87,13 +87,10 @@ public static bool AddPlayer(NetworkConnection readyConn, MessageBase extraMessa
if (LogFilter.Debug) { Debug.Log("ClientScene.AddPlayer() called with connection [" + readyConnection + "]"); }
AddPlayerMessage msg = new AddPlayerMessage();
if (extraMessage != null)
AddPlayerMessage msg = new AddPlayerMessage()
{
NetworkWriter writer = new NetworkWriter();
extraMessage.Serialize(writer);
msg.value = writer.ToArray();
}
value = extraData
};
readyConnection.Send(msg);
return true;
}

View File

@ -552,21 +552,7 @@ internal void OnServerAddPlayerMessageInternal(NetworkConnection conn, AddPlayer
{
if (LogFilter.Debug) { Debug.Log("NetworkManager.OnServerAddPlayerMessageInternal"); }
if (msg.value != null && msg.value.Length > 0)
{
// convert payload to extra message and call OnServerAddPlayer
// (usually for character selection information)
NetworkMessage extraMessage = new NetworkMessage
{
reader = new NetworkReader(msg.value),
conn = conn
};
OnServerAddPlayer(conn, extraMessage);
}
else
{
OnServerAddPlayer(conn);
}
OnServerAddPlayer(conn, msg);
}
internal void OnServerRemovePlayerMessageInternal(NetworkConnection conn, RemovePlayerMessage msg)
@ -661,12 +647,7 @@ public virtual void OnServerReady(NetworkConnection conn)
NetworkServer.SetClientReady(conn);
}
public virtual void OnServerAddPlayer(NetworkConnection conn, NetworkMessage extraMessage)
{
OnServerAddPlayerInternal(conn);
}
public virtual void OnServerAddPlayer(NetworkConnection conn)
public virtual void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage)
{
OnServerAddPlayerInternal(conn);
}