73 lines
1.7 KiB
C#
Raw Normal View History

2020-09-02 11:17:04 +01:00
using OWML.Common;
2020-11-03 21:33:48 +00:00
using QSB.Player;
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-23 10:07:43 +02:00
using QSB.Utility;
using UnityEngine;
2021-04-11 17:05:02 +01:00
namespace QSB.ProbeSync.TransformSync
{
2021-04-28 00:22:08 +01:00
public class PlayerProbeSync : SectoredTransformSync
2020-12-14 21:20:53 +00:00
{
2021-04-20 08:36:07 +01:00
public static PlayerProbeSync LocalInstance { get; private set; }
2021-04-21 16:49:30 +01:00
2021-04-20 08:36:07 +01:00
public override void OnStartAuthority()
2021-04-28 00:22:08 +01:00
{
DebugLog.DebugWrite($"OnStartAuthority probe");
LocalInstance = this;
}
2021-04-20 08:36:07 +01:00
protected override Transform InitLocalTransform()
2020-12-14 21:20:53 +00:00
{
2021-05-15 14:10:51 +01:00
SectorSync.Init(Locator.GetProbe().GetSectorDetector(), this);
2020-12-14 21:41:56 +01:00
2021-07-04 16:03:45 +01:00
var body = Locator.GetProbe().transform;
2020-12-14 21:20:53 +00:00
Player.ProbeBody = body.gameObject;
2020-12-14 21:41:56 +01:00
2021-07-04 16:03:45 +01:00
if (Player.Body == null)
{
DebugLog.ToConsole($"Warning - Player.Body is null!", MessageType.Warning);
return null;
}
var listener = Player.Body.AddComponent<ProbeListener>();
listener.Init(Locator.GetProbe());
return body;
2020-12-14 21:20:53 +00:00
}
2020-12-14 21:41:56 +01:00
protected override Transform InitRemoteTransform()
2020-12-14 21:20:53 +00:00
{
2021-07-03 21:51:13 +01:00
var probe = Locator.GetProbe().transform;
2020-12-14 21:41:56 +01:00
2020-12-14 21:20:53 +00:00
if (probe == null)
{
DebugLog.ToConsole("Error - Probe is null!", MessageType.Error);
return default;
}
2020-12-14 21:41:56 +01:00
2020-12-14 21:20:53 +00:00
var body = probe.InstantiateInactive();
body.name = "RemoteProbeTransform";
2020-12-14 21:41:56 +01:00
2020-12-14 21:20:53 +00:00
PlayerToolsManager.CreateProbe(body, Player);
2020-12-14 21:41:56 +01:00
2020-12-14 21:20:53 +00:00
Player.ProbeBody = body.gameObject;
2020-12-14 21:41:56 +01:00
return body;
2020-12-14 21:20:53 +00:00
}
2020-12-14 21:41:56 +01:00
2020-12-14 21:20:53 +00:00
public override bool IsReady => Locator.GetProbe() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
2021-04-18 18:46:55 +01:00
&& Player.PlayerStates.IsReady
2020-12-14 21:20:53 +00:00
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
2021-05-15 14:10:51 +01:00
protected override float DistanceLeeway => 10f;
public override bool UseInterpolation => true;
public override TargetType Type => TargetType.Probe;
2020-12-14 21:20:53 +00:00
}
2020-12-03 08:28:05 +00:00
}