mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-09 03:40:46 +00:00
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using QSB.Events;
|
|
using QSB.QuantumSync.WorldObjects;
|
|
using QSB.WorldSync;
|
|
using UnityEngine;
|
|
|
|
namespace QSB.QuantumSync.Events
|
|
{
|
|
public class SocketStateChangeEvent : QSBEvent<SocketStateChangeMessage>
|
|
{
|
|
public override QSB.Events.EventType Type => QSB.Events.EventType.SocketStateChange;
|
|
|
|
public override void SetupListener() => GlobalMessenger<int, int, Quaternion>.AddListener(EventNames.QSBSocketStateChange, Handler);
|
|
public override void CloseListener() => GlobalMessenger<int, int, Quaternion>.RemoveListener(EventNames.QSBSocketStateChange, Handler);
|
|
|
|
private void Handler(int objid, int socketid, Quaternion localRotation) => SendEvent(CreateMessage(objid, socketid, localRotation));
|
|
|
|
private SocketStateChangeMessage CreateMessage(int objid, int socketid, Quaternion localRotation) => new SocketStateChangeMessage
|
|
{
|
|
AboutId = LocalPlayerId,
|
|
ObjectId = objid,
|
|
SocketId = socketid,
|
|
LocalRotation = localRotation
|
|
};
|
|
|
|
public override void OnReceiveRemote(bool server, SocketStateChangeMessage message)
|
|
{
|
|
if (!QSBCore.HasWokenUp)
|
|
{
|
|
return;
|
|
}
|
|
var obj = QSBWorldSync.GetWorldFromId<QSBSocketedQuantumObject>(message.ObjectId);
|
|
obj.MoveToSocket(message);
|
|
}
|
|
}
|
|
} |