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-12-12 18:14:04 +00:00
|
|
|
|
using System.Linq;
|
2020-08-07 20:39:07 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.TransformSync
|
|
|
|
|
{
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public class PlayerProbeSync : TransformSync
|
|
|
|
|
{
|
|
|
|
|
private Transform _disabledSocket;
|
|
|
|
|
|
2020-12-12 18:14:04 +00:00
|
|
|
|
protected void Start()
|
|
|
|
|
{
|
|
|
|
|
var lowestBound = QSBPlayerManager.GetSyncObjects<PlayerTransformSync>().Where(x => x.NetId.Value < NetId.Value).OrderBy(x => x.NetId.Value).Last();
|
|
|
|
|
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 23:13:32 +00:00
|
|
|
|
private Transform GetProbe()
|
2020-12-11 23:13:13 +00:00
|
|
|
|
=> Locator.GetProbe().transform.Find("CameraPivot").Find("Geometry");
|
2020-12-02 21:29:53 +00:00
|
|
|
|
|
|
|
|
|
protected override Transform InitLocalTransform()
|
|
|
|
|
{
|
|
|
|
|
var body = GetProbe();
|
|
|
|
|
|
|
|
|
|
SetSocket(Player.Camera.transform);
|
|
|
|
|
Player.ProbeBody = body.gameObject;
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Transform InitRemoteTransform()
|
|
|
|
|
{
|
|
|
|
|
var probe = GetProbe();
|
|
|
|
|
|
|
|
|
|
if (probe == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole("Error - Probe is null!", MessageType.Error);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var body = probe.InstantiateInactive();
|
|
|
|
|
body.name = "RemoteProbeTransform";
|
|
|
|
|
|
|
|
|
|
Destroy(body.GetComponentInChildren<ProbeAnimatorController>());
|
|
|
|
|
|
|
|
|
|
PlayerToolsManager.CreateProbe(body, Player);
|
|
|
|
|
|
2020-12-14 16:24:52 +00:00
|
|
|
|
QSBCore.Helper.Events.Unity.RunWhen(() => (Player.ProbeLauncher != null), () => SetSocket(Player.ProbeLauncher.ToolGameObject.transform));
|
2020-12-02 21:29:53 +00:00
|
|
|
|
Player.ProbeBody = body.gameObject;
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetSocket(Transform socket)
|
|
|
|
|
{
|
|
|
|
|
_disabledSocket = socket;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateTransform()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateTransform();
|
|
|
|
|
if (Player == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Player 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;
|
|
|
|
|
}
|
|
|
|
|
if (Player.GetState(State.ProbeActive) || ReferenceSector?.Sector == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (HasAuthority)
|
|
|
|
|
{
|
|
|
|
|
transform.position = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (SyncedTransform.position == Vector3.zero)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
SyncedTransform.localPosition = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsReady => Locator.GetProbe() != null
|
|
|
|
|
&& Player != null
|
|
|
|
|
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
|
|
|
|
|
&& Player.IsReady
|
|
|
|
|
&& NetId.Value != uint.MaxValue
|
|
|
|
|
&& NetId.Value != 0U;
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|