mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-06 10:09:31 +00:00
7c7a3e6423
This reverts commit 01332e3ad2
.
80 lines
2.2 KiB
C#
80 lines
2.2 KiB
C#
using Mirror;
|
|
using QSB.Messaging;
|
|
using QSB.Player.TransformSync;
|
|
using QSB.SectorSync.WorldObjects;
|
|
using QSB.WorldSync;
|
|
using UnityEngine;
|
|
|
|
namespace QSB.Utility.Messages;
|
|
|
|
public class DebugRequestTeleportInfoMessage : QSBMessage
|
|
{
|
|
public DebugRequestTeleportInfoMessage(uint to) => To = to;
|
|
|
|
public override void OnReceiveRemote() => new DebugTeleportInfoMessage(From).Send();
|
|
}
|
|
|
|
public class DebugTeleportInfoMessage : QSBMessage
|
|
{
|
|
private int SectorId;
|
|
private Vector3 RelPos;
|
|
private Quaternion RelRot;
|
|
private float DegreesY;
|
|
private Vector3 RelVel;
|
|
private Vector3 RelAngVel;
|
|
|
|
public DebugTeleportInfoMessage(uint to)
|
|
{
|
|
To = to;
|
|
|
|
var qsbSector = PlayerTransformSync.LocalInstance.ReferenceSector;
|
|
SectorId = qsbSector.ObjectId;
|
|
|
|
var body = Locator.GetPlayerBody();
|
|
var refBody = qsbSector.AttachedObject.GetOWRigidbody();
|
|
|
|
var pos = body.GetPosition();
|
|
RelPos = refBody.transform.ToRelPos(pos);
|
|
RelRot = refBody.transform.ToRelRot(body.GetRotation());
|
|
DegreesY = Locator.GetPlayerCameraController().GetDegreesY();
|
|
RelVel = refBody.ToRelVel(body.GetVelocity(), pos);
|
|
RelAngVel = refBody.ToRelAngVel(body.GetAngularVelocity());
|
|
}
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
{
|
|
base.Serialize(writer);
|
|
writer.Write(SectorId);
|
|
writer.Write(RelPos);
|
|
writer.Write(RelRot);
|
|
writer.Write(DegreesY);
|
|
writer.Write(RelVel);
|
|
writer.Write(RelAngVel);
|
|
}
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
{
|
|
base.Deserialize(reader);
|
|
SectorId = reader.Read<int>();
|
|
RelPos = reader.ReadVector3();
|
|
RelRot = reader.ReadQuaternion();
|
|
DegreesY = reader.Read<float>();
|
|
RelVel = reader.ReadVector3();
|
|
RelAngVel = reader.ReadVector3();
|
|
}
|
|
|
|
public override void OnReceiveRemote()
|
|
{
|
|
var qsbSector = SectorId.GetWorldObject<QSBSector>();
|
|
|
|
var body = Locator.GetPlayerBody();
|
|
var refBody = qsbSector.AttachedObject.GetOWRigidbody();
|
|
|
|
var pos = refBody.transform.FromRelPos(RelPos);
|
|
body.SetPosition(pos);
|
|
body.SetRotation(refBody.transform.FromRelRot(RelRot));
|
|
Locator.GetPlayerCameraController().SetDegreesY(DegreesY);
|
|
body.SetVelocity(refBody.FromRelVel(RelVel, pos));
|
|
body.SetAngularVelocity(refBody.FromRelAngVel(RelAngVel));
|
|
}
|
|
} |