mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 18:35:34 +00:00
45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
|
using QSB.Messaging;
|
|||
|
using UnityEngine.Networking;
|
|||
|
|
|||
|
namespace QSB.Events
|
|||
|
{
|
|||
|
public class PlayerJoin : NetworkBehaviour
|
|||
|
{
|
|||
|
private MessageHandler<JoinEvent> _joinHandler;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_joinHandler = new MessageHandler<JoinEvent>();
|
|||
|
_joinHandler.OnClientReceiveMessage += OnClientReceiveMessage;
|
|||
|
_joinHandler.OnServerReceiveMessage += OnServerReceiveMessage;
|
|||
|
}
|
|||
|
|
|||
|
public void Join(string playerName)
|
|||
|
{
|
|||
|
var message = new JoinEvent
|
|||
|
{
|
|||
|
PlayerName = playerName
|
|||
|
};
|
|||
|
if (isServer)
|
|||
|
{
|
|||
|
_joinHandler.SendToAll(message);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_joinHandler.SendToServer(message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnServerReceiveMessage(JoinEvent message)
|
|||
|
{
|
|||
|
_joinHandler.SendToAll(message);
|
|||
|
}
|
|||
|
|
|||
|
private void OnClientReceiveMessage(JoinEvent message)
|
|||
|
{
|
|||
|
DebugLog.All(message.PlayerName, "joined!");
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|