mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-25 15:35:22 +00:00
Delete EventHandler.cs
This commit is contained in:
parent
df5404aa72
commit
650a3c88db
@ -1,52 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using QSB.Messaging;
|
||||
using QSB.TransformSync;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Events
|
||||
{
|
||||
public class EventHandler : NetworkBehaviour
|
||||
{
|
||||
public static EventHandler LocalInstance;
|
||||
|
||||
private MessageHandler<EventMessage> _eventHandler;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
LocalInstance = this;
|
||||
|
||||
_eventHandler = new MessageHandler<EventMessage>(MessageType.Event);
|
||||
_eventHandler.OnClientReceiveMessage += OnClientReceiveMessage;
|
||||
_eventHandler.OnServerReceiveMessage += OnServerReceiveMessage;
|
||||
}
|
||||
|
||||
public void Send(EventMessage message)
|
||||
{
|
||||
StartCoroutine(SendEvent(message));
|
||||
}
|
||||
|
||||
private IEnumerator SendEvent(EventMessage message)
|
||||
{
|
||||
yield return new WaitUntil(() => PlayerTransformSync.LocalInstance != null);
|
||||
_eventHandler.SendToServer(message);
|
||||
}
|
||||
|
||||
private void OnServerReceiveMessage(EventMessage message)
|
||||
{
|
||||
_eventHandler.SendToAll(message);
|
||||
}
|
||||
|
||||
private void OnClientReceiveMessage(EventMessage message)
|
||||
{
|
||||
if (message.SenderId == PlayerRegistry.LocalPlayer?.NetId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var _event = EventSender.EventList.First(x => x.Type == (EventType)message.EventType);
|
||||
_event.OnReceive(message.SenderId, message.Data);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user