74 lines
1.9 KiB
C#
Raw Normal View History

2021-04-27 22:49:12 +01:00
using QSB.Animation.Player;
2020-11-20 19:50:31 +00:00
using QSB.Instruments;
2021-05-02 13:59:39 +01:00
using QSB.Syncs.TransformSync;
2020-02-21 23:36:07 +01:00
using UnityEngine;
2020-02-10 23:03:28 +01:00
2021-04-11 17:05:02 +01:00
namespace QSB.Player.TransformSync
2020-02-15 20:48:02 +01:00
{
2021-04-28 00:22:08 +01:00
public class PlayerTransformSync : SectoredTransformSync
2020-12-14 21:20:53 +00:00
{
public static PlayerTransformSync LocalInstance { get; private set; }
2021-04-28 10:02:16 +01:00
public override bool UseInterpolation => true;
2020-02-10 23:03:28 +01:00
2020-12-24 16:34:24 +00:00
static PlayerTransformSync() => AnimControllerPatch.Init();
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
2021-04-21 11:02:17 +01:00
public override void Start()
{
base.Start();
Player.TransformSync = this;
}
2021-04-22 20:42:38 +01:00
protected override void OnDestroy()
2020-12-14 21:20:53 +00:00
{
2021-03-23 13:18:29 +00:00
QSBPlayerManager.OnRemovePlayer?.Invoke(PlayerId);
2021-04-22 20:42:38 +01: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");
2021-04-21 11:02:17 +01:00
protected override GameObject InitLocalTransform()
2020-12-14 21:20:53 +00:00
{
2021-03-09 19:45:00 +00:00
SectorSync.SetSectorDetector(Locator.GetPlayerSectorDetector());
2020-12-14 21:20:53 +00:00
var body = GetPlayerModel();
2020-12-14 21:20:53 +00:00
GetComponent<AnimationSync>().InitLocal(body);
GetComponent<InstrumentsManager>().InitLocal(body);
2020-12-14 21:20:53 +00:00
Player.Body = body.gameObject;
2021-04-21 11:02:17 +01:00
return body.gameObject;
2020-12-14 21:20:53 +00:00
}
2020-02-12 20:05:08 +01:00
2021-04-21 11:02:17 +01:00
protected override GameObject InitRemoteTransform()
2020-12-14 21:20:53 +00:00
{
var body = Instantiate(GetPlayerModel());
2021-05-07 19:17:09 +01:00
Player.Body = body.gameObject;
2020-12-14 21:20:53 +00:00
GetComponent<AnimationSync>().InitRemote(body);
GetComponent<InstrumentsManager>().InitRemote(body);
2020-12-14 21:20:53 +00:00
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
marker.Init(Player);
2020-12-20 18:16:23 +00:00
body.gameObject.AddComponent<PlayerMapMarker>().PlayerName = Player.Name;
2021-04-21 11:02:17 +01:00
return body.gameObject;
2020-12-14 21:20:53 +00:00
}
2020-12-14 21:20:53 +00:00
public override bool IsReady => Locator.GetPlayerTransform() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
2021-04-18 18:46:55 +01:00
&& Player.PlayerStates.IsReady
2020-12-14 21:20:53 +00:00
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
}
2020-12-03 08:28:05 +00:00
}