2020-07-28 15:59:24 +02:00
|
|
|
|
using QSB.Utility;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.TransformSync
|
|
|
|
|
{
|
|
|
|
|
public class PlayerCameraSync : TransformSync
|
|
|
|
|
{
|
|
|
|
|
public static PlayerCameraSync LocalInstance { get; private set; }
|
|
|
|
|
|
|
|
|
|
public override void OnStartLocalPlayer()
|
|
|
|
|
{
|
|
|
|
|
LocalInstance = this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 15:59:24 +02:00
|
|
|
|
private uint GetAttachedNetId()
|
2020-07-28 00:13:43 +01:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
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);
|
|
|
|
|
|
2020-07-30 21:57:39 +02:00
|
|
|
|
PlayerRegistry.GetPlayer(GetAttachedNetId()).Camera = body.gameObject;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Transform InitRemoteTransform()
|
|
|
|
|
{
|
|
|
|
|
var body = new GameObject("PlayerCamera");
|
|
|
|
|
|
|
|
|
|
PlayerToolsManager.Init(body.transform);
|
|
|
|
|
|
2020-07-30 21:57:39 +02:00
|
|
|
|
PlayerRegistry.GetPlayer(GetAttachedNetId()).Camera = body;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
|
|
|
|
return body.transform;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsReady()
|
|
|
|
|
{
|
2020-07-29 15:07:07 +01:00
|
|
|
|
return Locator.GetPlayerTransform() != null && PlayerRegistry.PlayerExists(GetAttachedNetId());
|
2020-07-28 00:13:43 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|