quantum-space-buddies/QSB/TransformSync/PlayerCameraSync.cs
2020-12-22 09:13:08 +00:00

47 lines
1.2 KiB
C#

using QSB.Events;
using QSB.Player;
using QSB.Tools;
using QSB.Utility;
using UnityEngine;
namespace QSB.TransformSync
{
public class PlayerCameraSync : TransformSync
{
protected override Transform InitLocalTransform()
{
var body = Locator.GetPlayerCamera().gameObject.transform;
Player.CameraBody = body.gameObject;
Player.IsReady = true;
GlobalMessenger<bool>.FireEvent(EventNames.QSBPlayerReady, true);
DebugLog.DebugWrite("PlayerCameraSync init done - Request state!");
GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest);
return body;
}
protected override Transform InitRemoteTransform()
{
var body = new GameObject("RemotePlayerCamera");
PlayerToolsManager.Init(body.transform);
var camera = body.AddComponent<Camera>();
camera.enabled = false;
var owcamera = body.AddComponent<OWCamera>();
owcamera.fieldOfView = 70;
Player.Camera = owcamera;
Player.CameraBody = body;
return body.transform;
}
public override bool IsReady => Locator.GetPlayerTransform() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
}
}