2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2021-05-15 14:10:51 +01:00
|
|
|
|
using QSB.SectorSync;
|
2021-05-02 13:59:39 +01:00
|
|
|
|
using QSB.Syncs.TransformSync;
|
2021-05-03 20:27:52 +01:00
|
|
|
|
using QSB.Tools;
|
2020-08-24 15:51:12 +01:00
|
|
|
|
using QSB.Utility;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2021-04-11 17:05:02 +01:00
|
|
|
|
namespace QSB.Player.TransformSync
|
2020-07-28 00:13:43 +01:00
|
|
|
|
{
|
2021-04-28 00:22:08 +01:00
|
|
|
|
public class PlayerCameraSync : SectoredTransformSync
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
2021-05-15 11:25:47 +01:00
|
|
|
|
protected override Transform InitLocalTransform()
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
2021-05-15 14:10:51 +01:00
|
|
|
|
SectorSync.Init(Locator.GetPlayerSectorDetector(), this);
|
2020-12-02 21:29:53 +00:00
|
|
|
|
var body = Locator.GetPlayerCamera().gameObject.transform;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2021-01-05 15:56:14 +00:00
|
|
|
|
Player.Camera = Locator.GetPlayerCamera();
|
2020-12-22 09:13:08 +00:00
|
|
|
|
Player.CameraBody = body.gameObject;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2021-04-18 18:46:55 +01:00
|
|
|
|
Player.PlayerStates.IsReady = true;
|
2021-02-10 19:34:41 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBPlayerReady, true);
|
2020-12-02 21:29:53 +00:00
|
|
|
|
DebugLog.DebugWrite("PlayerCameraSync init done - Request state!");
|
2021-02-10 19:34:41 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBPlayerStatesRequest);
|
2020-08-10 11:45:24 +01:00
|
|
|
|
|
2021-05-15 11:25:47 +01:00
|
|
|
|
return body;
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2021-05-15 11:25:47 +01:00
|
|
|
|
protected override Transform InitRemoteTransform()
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
|
|
|
|
var body = new GameObject("RemotePlayerCamera");
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
PlayerToolsManager.Init(body.transform);
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2020-12-22 09:13:08 +00:00
|
|
|
|
var camera = body.AddComponent<Camera>();
|
|
|
|
|
camera.enabled = false;
|
|
|
|
|
var owcamera = body.AddComponent<OWCamera>();
|
|
|
|
|
owcamera.fieldOfView = 70;
|
2021-01-05 15:56:14 +00:00
|
|
|
|
owcamera.nearClipPlane = 0.1f;
|
|
|
|
|
owcamera.farClipPlane = 50000f;
|
2020-12-22 09:13:08 +00:00
|
|
|
|
Player.Camera = owcamera;
|
|
|
|
|
Player.CameraBody = body;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2021-05-15 11:25:47 +01:00
|
|
|
|
return body.transform;
|
2021-01-03 16:09:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public override bool IsReady => Locator.GetPlayerTransform() != null
|
|
|
|
|
&& Player != null
|
|
|
|
|
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
|
|
|
|
|
&& NetId.Value != uint.MaxValue
|
|
|
|
|
&& NetId.Value != 0U;
|
2021-04-28 10:02:16 +01:00
|
|
|
|
|
|
|
|
|
public override bool UseInterpolation => true;
|
2021-05-15 14:10:51 +01:00
|
|
|
|
|
|
|
|
|
public override TargetType Type => TargetType.PlayerCamera;
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|