2020-12-11 23:13:32 +00:00
|
|
|
|
using QSB.Animation;
|
2020-11-20 19:50:31 +00:00
|
|
|
|
using QSB.Instruments;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-02-21 23:36:07 +01:00
|
|
|
|
using UnityEngine;
|
2020-02-10 23:03:28 +01:00
|
|
|
|
|
2020-02-21 23:36:07 +01:00
|
|
|
|
namespace QSB.TransformSync
|
2020-02-15 20:48:02 +01:00
|
|
|
|
{
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public class PlayerTransformSync : TransformSync
|
|
|
|
|
{
|
|
|
|
|
public static PlayerTransformSync LocalInstance { get; private set; }
|
2020-02-10 23:03:28 +01:00
|
|
|
|
|
2020-12-24 16:34:24 +00:00
|
|
|
|
static PlayerTransformSync() => AnimControllerPatch.Init();
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2021-02-16 12:15:43 +00:00
|
|
|
|
public override void OnStartLocalPlayer()
|
2021-02-15 10:58:21 +00:00
|
|
|
|
=> LocalInstance = this;
|
2020-08-19 22:29:53 +02:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
protected override void OnDestroy()
|
|
|
|
|
{
|
2021-03-23 13:18:29 +00:00
|
|
|
|
QSBPlayerManager.OnRemovePlayer?.Invoke(PlayerId);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
base.OnDestroy();
|
2021-03-09 16:43:41 +00:00
|
|
|
|
if (QSBPlayerManager.PlayerExists(PlayerId))
|
|
|
|
|
{
|
|
|
|
|
Player.HudMarker?.Remove();
|
|
|
|
|
QSBPlayerManager.RemovePlayer(PlayerId);
|
|
|
|
|
}
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2020-12-13 22:25:23 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
private Transform GetPlayerModel() =>
|
|
|
|
|
Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2");
|
2020-02-11 19:56:57 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
protected override Transform InitLocalTransform()
|
|
|
|
|
{
|
2021-03-09 19:45:00 +00:00
|
|
|
|
SectorSync.SetSectorDetector(Locator.GetPlayerSectorDetector());
|
2020-12-14 21:20:53 +00:00
|
|
|
|
var body = GetPlayerModel();
|
2020-02-14 22:14:24 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
GetComponent<AnimationSync>().InitLocal(body);
|
|
|
|
|
GetComponent<InstrumentsManager>().InitLocal(body);
|
2020-02-21 21:51:58 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
Player.Body = body.gameObject;
|
2020-10-23 19:06:11 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
return body;
|
|
|
|
|
}
|
2020-02-12 20:05:08 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
protected override Transform InitRemoteTransform()
|
|
|
|
|
{
|
|
|
|
|
var body = Instantiate(GetPlayerModel());
|
2020-02-12 22:00:17 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
GetComponent<AnimationSync>().InitRemote(body);
|
|
|
|
|
GetComponent<InstrumentsManager>().InitRemote(body);
|
2020-02-14 22:14:24 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
|
|
|
|
|
marker.Init(Player);
|
2020-05-19 19:41:33 +02:00
|
|
|
|
|
2020-12-20 18:16:23 +00:00
|
|
|
|
body.gameObject.AddComponent<PlayerMapMarker>().PlayerName = Player.Name;
|
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
Player.Body = body.gameObject;
|
2020-10-23 19:06:11 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
return body;
|
|
|
|
|
}
|
2020-02-23 18:31:38 +01:00
|
|
|
|
|
2021-01-03 12:38:02 +00:00
|
|
|
|
private void OnRenderObject()
|
|
|
|
|
{
|
2021-01-31 16:14:17 +00:00
|
|
|
|
if (!QSBCore.HasWokenUp || !Player.IsReady || !QSBCore.DebugMode || !QSBCore.ShowLinesInDebug)
|
2021-01-03 12:38:02 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Popcron.Gizmos.Line(ReferenceSector.Position, Player.Body.transform.position, Color.blue, true);
|
2021-01-26 14:07:17 +00:00
|
|
|
|
Popcron.Gizmos.Sphere(ReferenceSector.Position, 5f, Color.cyan);
|
2021-01-03 12:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public override bool IsReady => Locator.GetPlayerTransform() != null
|
|
|
|
|
&& Player != null
|
|
|
|
|
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
|
|
|
|
|
&& Player.IsReady
|
|
|
|
|
&& NetId.Value != uint.MaxValue
|
|
|
|
|
&& NetId.Value != 0U;
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|