2021-05-15 14:10:51 +01:00

78 lines
1.9 KiB
C#

using QSB.Animation.Player;
using QSB.Instruments;
using QSB.SectorSync;
using QSB.Syncs.TransformSync;
using UnityEngine;
namespace QSB.Player.TransformSync
{
public class PlayerTransformSync : SectoredTransformSync
{
static PlayerTransformSync() => AnimControllerPatch.Init();
public override void OnStartLocalPlayer()
=> LocalInstance = this;
public override void Start()
{
base.Start();
Player.TransformSync = this;
}
protected override void OnDestroy()
{
QSBPlayerManager.OnRemovePlayer?.Invoke(PlayerId);
base.OnDestroy();
if (QSBPlayerManager.PlayerExists(PlayerId))
{
Player.HudMarker?.Remove();
QSBPlayerManager.RemovePlayer(PlayerId);
}
}
private Transform GetPlayerModel() =>
Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2");
protected override Transform InitLocalTransform()
{
SectorSync.Init(Locator.GetPlayerSectorDetector(), this);
var body = GetPlayerModel();
GetComponent<AnimationSync>().InitLocal(body);
GetComponent<InstrumentsManager>().InitLocal(body);
Player.Body = body.gameObject;
return body;
}
protected override Transform InitRemoteTransform()
{
var body = Instantiate(GetPlayerModel());
Player.Body = body.gameObject;
GetComponent<AnimationSync>().InitRemote(body);
GetComponent<InstrumentsManager>().InitRemote(body);
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
marker.Init(Player);
body.gameObject.AddComponent<PlayerMapMarker>().PlayerName = Player.Name;
return body;
}
public override bool IsReady => Locator.GetPlayerTransform() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
&& Player.PlayerStates.IsReady
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
public static PlayerTransformSync LocalInstance { get; private set; }
public override bool UseInterpolation => true;
public override TargetType Type => TargetType.Player;
}
}