mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 09:35:26 +00:00
18a520bc78
* cleanup
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using QSB.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace QSB.TransformSync
|
|
{
|
|
public class PlayerCameraSync : TransformSync
|
|
{
|
|
public static PlayerCameraSync LocalInstance { get; private set; }
|
|
|
|
public override void OnStartLocalPlayer()
|
|
{
|
|
LocalInstance = this;
|
|
}
|
|
|
|
private uint GetAttachedNetId()
|
|
{
|
|
/*
|
|
Players are stored in PlayerRegistry using a specific ID. This ID has to remain the same
|
|
for all components of a player, so I've chosen to used the netId of PlayerTransformSync.
|
|
Since every networkbehaviour has it's own ascending netId, and we know that PlayerCameraSync
|
|
is the 3rd network transform to be loaded (After PlayerTransformSync and ShipTransformSync),
|
|
we can just minus 2 from PlayerCameraSync's netId to get PlayerTransformSyncs's netId.
|
|
*/
|
|
return netId.Value - 2;
|
|
}
|
|
|
|
protected override Transform InitLocalTransform()
|
|
{
|
|
var body = Locator.GetPlayerCamera().gameObject.transform;
|
|
|
|
PlayerToolsManager.Init(body);
|
|
|
|
PlayerRegistry.RegisterPlayerCamera(GetAttachedNetId(), body.gameObject);
|
|
|
|
return body;
|
|
}
|
|
|
|
protected override Transform InitRemoteTransform()
|
|
{
|
|
var body = new GameObject("PlayerCamera");
|
|
|
|
PlayerToolsManager.Init(body.transform);
|
|
|
|
PlayerRegistry.RegisterPlayerCamera(GetAttachedNetId(), body);
|
|
|
|
return body.transform;
|
|
}
|
|
|
|
protected override bool IsReady()
|
|
{
|
|
return Locator.GetPlayerTransform() != null;
|
|
}
|
|
}
|
|
}
|