2020-09-02 11:17:04 +01:00
|
|
|
|
using OWML.Common;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-09-02 11:17:04 +01:00
|
|
|
|
using QSB.Tools;
|
2020-08-23 10:07:43 +02:00
|
|
|
|
using QSB.Utility;
|
2020-08-07 20:39:07 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.TransformSync
|
|
|
|
|
{
|
2020-08-31 09:36:29 +01:00
|
|
|
|
public class PlayerProbeSync : TransformSync
|
2020-08-07 20:39:07 +01:00
|
|
|
|
{
|
|
|
|
|
public static PlayerProbeSync LocalInstance { get; private set; }
|
|
|
|
|
|
2020-08-21 14:16:34 +01:00
|
|
|
|
private Transform _disabledSocket;
|
2020-08-07 20:39:07 +01:00
|
|
|
|
|
|
|
|
|
public override void OnStartLocalPlayer()
|
|
|
|
|
{
|
|
|
|
|
LocalInstance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Transform GetProbe()
|
|
|
|
|
{
|
|
|
|
|
return Locator.GetProbe().transform.Find("CameraPivot").Find("Geometry");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Transform InitLocalTransform()
|
|
|
|
|
{
|
|
|
|
|
var body = GetProbe();
|
|
|
|
|
|
2020-09-29 21:34:46 +01:00
|
|
|
|
SetSocket(Player.Camera.transform);
|
2020-08-07 20:39:07 +01:00
|
|
|
|
Player.ProbeBody = body.gameObject;
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Transform InitRemoteTransform()
|
|
|
|
|
{
|
2020-08-07 22:39:50 +02:00
|
|
|
|
var probe = GetProbe();
|
|
|
|
|
|
2020-09-02 11:17:04 +01:00
|
|
|
|
if (probe == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole("Error - Probe is null!", MessageType.Error);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-23 10:07:43 +02:00
|
|
|
|
var body = probe.InstantiateInactive();
|
2020-09-02 11:17:04 +01:00
|
|
|
|
body.name = "RemoteProbeTransform";
|
2020-08-07 22:39:50 +02:00
|
|
|
|
|
|
|
|
|
Destroy(body.GetComponentInChildren<ProbeAnimatorController>());
|
2020-08-07 20:39:07 +01:00
|
|
|
|
|
2020-08-08 12:25:09 +02:00
|
|
|
|
PlayerToolsManager.CreateProbe(body, Player);
|
2020-08-07 20:39:07 +01:00
|
|
|
|
|
2020-09-29 21:34:46 +01:00
|
|
|
|
QSB.Helper.Events.Unity.RunWhen(() => (Player.ProbeLauncher != null), () => SetSocket(Player.ProbeLauncher.ToolGameObject.transform));
|
2020-08-07 20:39:07 +01:00
|
|
|
|
Player.ProbeBody = body.gameObject;
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 21:34:46 +01:00
|
|
|
|
private void SetSocket(Transform socket)
|
|
|
|
|
{
|
2020-10-22 21:21:41 +01:00
|
|
|
|
DebugLog.DebugWrite($"Setting DisabledSocket for {AttachedNetId} to {socket.name}");
|
2020-09-29 21:34:46 +01:00
|
|
|
|
_disabledSocket = socket;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-07 20:39:07 +01:00
|
|
|
|
protected override void UpdateTransform()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateTransform();
|
2020-10-22 21:21:41 +01:00
|
|
|
|
if (Player == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Player is null for {AttachedNetId}!", MessageType.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ReferenceSector == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"ReferenceSector is null for {AttachedNetId}!", MessageType.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (_disabledSocket == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"DisabledSocket is null for {AttachedNetId}! (ProbeLauncher null? : {Player.ProbeLauncher == null})", MessageType.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-29 21:34:46 +01:00
|
|
|
|
if (Player.GetState(State.ProbeActive) || ReferenceSector?.Sector == null)
|
2020-08-07 20:39:07 +01:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (hasAuthority)
|
|
|
|
|
{
|
2020-08-21 14:16:34 +01:00
|
|
|
|
transform.position = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
|
2020-08-07 20:39:07 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (SyncedTransform.position == Vector3.zero ||
|
|
|
|
|
SyncedTransform.position == Locator.GetAstroObject(AstroObject.Name.Sun).transform.position)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-21 14:16:34 +01:00
|
|
|
|
SyncedTransform.localPosition = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
|
2020-08-07 20:39:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:10:01 +01:00
|
|
|
|
public override bool IsReady => Locator.GetProbe() != null
|
|
|
|
|
&& Player != null
|
2020-11-03 21:18:40 +00:00
|
|
|
|
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
|
2020-09-04 20:10:01 +01:00
|
|
|
|
&& Player.IsReady
|
2020-09-04 20:09:25 +01:00
|
|
|
|
&& netId.Value != uint.MaxValue
|
2020-09-03 17:09:38 +01:00
|
|
|
|
&& netId.Value != 0U;
|
2020-08-07 20:39:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|