quantum-space-buddies/QSB/TransformSync/PlayerTransformSync.cs
2020-12-03 08:28:05 +00:00

65 lines
1.5 KiB
C#

using OWML.Common;
using QSB.Animation;
using QSB.Instruments;
using QSB.Player;
using QSB.Utility;
using UnityEngine;
namespace QSB.TransformSync
{
public class PlayerTransformSync : TransformSync
{
public static PlayerTransformSync LocalInstance { get; private set; }
static PlayerTransformSync()
{
DebugLog.DebugWrite("Constructor", MessageType.Info);
AnimControllerPatch.Init();
}
public override void OnStartLocalPlayer()
{
DebugLog.DebugWrite("OnStartLocalPlayer", MessageType.Info);
LocalInstance = this;
}
private Transform GetPlayerModel()
{
return Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2");
}
protected override Transform InitLocalTransform()
{
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());
GetComponent<AnimationSync>().InitRemote(body);
GetComponent<InstrumentsManager>().InitRemote(body);
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
marker.Init(Player);
Player.Body = body.gameObject;
return body;
}
public override bool IsReady => Locator.GetPlayerTransform() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
&& Player.IsReady
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
}
}