100 lines
2.7 KiB
C#
Raw Normal View History

2020-09-02 11:17:04 +01:00
using OWML.Common;
2021-05-15 14:10:51 +01:00
using QSB.SectorSync;
2021-08-14 15:03:01 +01:00
using QSB.Syncs.Sectored.Transforms;
2021-07-26 22:55:09 +01:00
using QSB.Tools.ProbeLauncherTool;
2020-08-23 10:07:43 +02:00
using QSB.Utility;
using UnityEngine;
namespace QSB.Tools.ProbeTool.TransformSync
{
2022-01-14 22:39:41 -08:00
public class PlayerProbeSync : SectoredTransformSync
2022-01-14 21:34:09 -08:00
{
protected override float DistanceLeeway => 10f;
2022-01-16 06:11:44 -08:00
protected override bool UseInterpolation => true;
protected override bool AllowDisabledAttachedObject => true;
protected override bool IsPlayerObject => true;
2022-01-14 21:34:09 -08:00
2022-01-14 22:34:13 -08:00
public static PlayerProbeSync LocalInstance { get; private set; }
2022-01-14 21:34:09 -08:00
public override void OnStartAuthority() => LocalInstance = this;
protected override Transform InitLocalTransform()
{
2022-01-16 06:53:45 -08:00
SectorSync.Init(Locator.GetProbe().GetSectorDetector(), TargetType.Probe);
2022-01-14 21:34:09 -08:00
var body = Locator.GetProbe().transform;
Player.ProbeBody = body.gameObject;
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());
var launcherListener = Player.Body.AddComponent<ProbeLauncherListener>();
launcherListener.Init(Player.LocalProbeLauncher);
return body;
}
protected override Transform InitRemoteTransform()
{
var probe = Locator.GetProbe().transform;
if (probe == null)
{
DebugLog.ToConsole("Error - Probe is null!", MessageType.Error);
return default;
}
var body = probe.gameObject.activeSelf
? probe.InstantiateInactive()
: Instantiate(probe);
body.name = "RemoteProbeTransform";
ProbeCreator.CreateProbe(body, Player);
Player.ProbeBody = body.gameObject;
return body;
}
2022-01-16 06:53:45 -08:00
protected override void GetFromAttached()
2022-01-14 21:34:09 -08:00
{
2022-01-16 06:53:45 -08:00
if (AttachedTransform.gameObject.activeInHierarchy)
2022-01-14 21:34:09 -08:00
{
2022-01-16 06:53:45 -08:00
base.GetFromAttached();
return;
2022-01-14 21:34:09 -08:00
}
2022-01-16 06:53:45 -08:00
var probeOWRigidbody = Locator.GetProbe().GetOWRigidbody();
if (probeOWRigidbody == null)
2022-01-14 21:34:09 -08:00
{
2022-01-16 06:53:45 -08:00
DebugLog.ToConsole($"Warning - Could not find OWRigidbody of local probe.", MessageType.Warning);
2022-01-14 21:34:09 -08:00
}
2022-01-16 06:53:45 -08:00
var probeLauncher = Player.LocalProbeLauncher;
// TODO : make this sync to the *active* probe launcher's _launcherTransform
var launcherTransform = probeLauncher._launcherTransform;
probeOWRigidbody.SetPosition(launcherTransform.position);
probeOWRigidbody.SetRotation(launcherTransform.rotation);
base.GetFromAttached();
var currentReferenceSector = ReferenceSector;
var playerReferenceSector = Player.TransformSync.ReferenceSector;
if (currentReferenceSector != playerReferenceSector)
{
SetReferenceSector(playerReferenceSector);
}
2022-01-14 21:34:09 -08:00
}
2022-01-16 06:11:44 -08:00
protected override bool IsReady => AttachedTransform != null || Locator.GetProbe() != null;
2022-01-14 21:34:09 -08:00
}
2021-11-19 00:28:36 -08:00
}