2020-08-07 20:39:07 +01:00
|
|
|
|
using QSB.Tools;
|
2020-08-18 13:56:07 +01:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using System;
|
2020-08-07 20:39:07 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.TransformSync
|
|
|
|
|
{
|
|
|
|
|
public class PlayerProbeSync : TransformSync
|
|
|
|
|
{
|
|
|
|
|
public static PlayerProbeSync LocalInstance { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Transform bodyTransform;
|
|
|
|
|
|
|
|
|
|
public override void OnStartLocalPlayer()
|
|
|
|
|
{
|
|
|
|
|
LocalInstance = this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 13:56:07 +01:00
|
|
|
|
public override uint PlayerId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
uint id = uint.MaxValue;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
id = netId.Value - 3;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Error while geting netId of {GetType().Name}! " +
|
|
|
|
|
$"{Environment.NewLine} - Did you destroy the TransformSync without destroying the {GetType().Name}?" +
|
|
|
|
|
$"{Environment.NewLine} - Did a destroyed TransformSync/{GetType().Name} still have an active action/event listener?" +
|
|
|
|
|
$"{Environment.NewLine} If you are a user seeing this, please report this error.", OWML.Common.MessageType.Error);
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 20:39:07 +01:00
|
|
|
|
|
|
|
|
|
private Transform GetProbe()
|
|
|
|
|
{
|
|
|
|
|
return Locator.GetProbe().transform.Find("CameraPivot").Find("Geometry");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Transform InitLocalTransform()
|
|
|
|
|
{
|
|
|
|
|
var body = GetProbe();
|
|
|
|
|
|
|
|
|
|
bodyTransform = body;
|
|
|
|
|
|
|
|
|
|
Player.ProbeBody = body.gameObject;
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Transform InitRemoteTransform()
|
|
|
|
|
{
|
2020-08-07 22:39:50 +02:00
|
|
|
|
var probe = GetProbe();
|
|
|
|
|
|
|
|
|
|
probe.gameObject.SetActive(false);
|
|
|
|
|
var body = Instantiate(probe);
|
|
|
|
|
probe.gameObject.SetActive(true);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
bodyTransform = body;
|
|
|
|
|
|
|
|
|
|
Player.ProbeBody = body.gameObject;
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateTransform()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateTransform();
|
|
|
|
|
if (Player.GetState(State.ProbeActive))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (hasAuthority)
|
|
|
|
|
{
|
2020-08-16 17:15:36 +02:00
|
|
|
|
transform.position = ReferenceSector.Transform.InverseTransformPoint(Player.ProbeLauncher.ToolGameObject.transform.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-16 17:15:36 +02:00
|
|
|
|
SyncedTransform.localPosition = ReferenceSector.Transform.InverseTransformPoint(Player.ProbeLauncher.ToolGameObject.transform.position);
|
2020-08-07 20:39:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 21:16:21 +02:00
|
|
|
|
public override bool IsReady => Locator.GetProbe() != null && Player != null && Player.IsReady;
|
2020-08-07 20:39:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|