mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-25 06:35:45 +00:00
485698e93b
* Showing player markers * Marker above head * Use player name on marker * Sync full state on init * Sync game state on start * removed name from death and leave message Co-authored-by: Ricardo Lopes <raicuparta@gmail.com>
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using System.Linq;
|
|
using QSB.Messaging;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
|
|
namespace QSB.Events
|
|
{
|
|
public class PlayerLeave : NetworkBehaviour
|
|
{
|
|
private MessageHandler<LeaveMessage> _leaveHandler;
|
|
|
|
private void Awake()
|
|
{
|
|
_leaveHandler = new MessageHandler<LeaveMessage>();
|
|
_leaveHandler.OnClientReceiveMessage += OnClientReceiveMessage;
|
|
}
|
|
|
|
public void Leave(uint playerId, uint[] objectIds)
|
|
{
|
|
var message = new LeaveMessage
|
|
{
|
|
SenderId = playerId,
|
|
ObjectIds = objectIds
|
|
};
|
|
_leaveHandler.SendToAll(message);
|
|
}
|
|
|
|
private void OnClientReceiveMessage(LeaveMessage message)
|
|
{
|
|
var playerName = PlayerJoin.PlayerNames[message.SenderId];
|
|
DebugLog.All(playerName, "left");
|
|
PlayerJoin.PlayerNames.Remove(message.SenderId);
|
|
foreach (var objectId in message.ObjectIds)
|
|
{
|
|
DestroyObject(objectId);
|
|
}
|
|
}
|
|
|
|
private void DestroyObject(uint objectId)
|
|
{
|
|
var component = GameObject.FindObjectsOfType<NetworkBehaviour>()
|
|
.FirstOrDefault(x => x.netId.Value == objectId);
|
|
if (component == null)
|
|
{
|
|
return;
|
|
}
|
|
var transformSync = component.GetComponent<TransformSync.TransformSync>();
|
|
if (transformSync != null)
|
|
{
|
|
Destroy(transformSync.SyncedTransform.gameObject);
|
|
}
|
|
Destroy(component.gameObject);
|
|
}
|
|
|
|
}
|
|
}
|