quantum-space-buddies/QSB/TransformSync/PlayerTransformSync.cs

66 lines
1.8 KiB
C#
Raw Normal View History

2020-12-02 09:51:53 +00:00
using OWML.Common;
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-12-02 09:51:53 +00:00
using QSB.Utility;
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-08-31 09:36:29 +01:00
public class PlayerTransformSync : TransformSync
2020-02-15 20:48:02 +01:00
{
2020-02-21 23:36:07 +01:00
public static PlayerTransformSync LocalInstance { get; private set; }
2020-02-10 23:03:28 +01:00
static PlayerTransformSync()
{
2020-12-02 09:51:53 +00:00
DebugLog.DebugWrite("Constructor", MessageType.Info);
AnimControllerPatch.Init();
}
public override void OnStartLocalPlayer()
{
2020-12-02 09:51:53 +00:00
DebugLog.DebugWrite("OnStartLocalPlayer", MessageType.Info);
LocalInstance = this;
}
2020-08-19 22:29:53 +02:00
private Transform GetPlayerModel()
2020-02-15 20:48:02 +01:00
{
return Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2");
}
protected override Transform InitLocalTransform()
2020-02-15 20:48:02 +01:00
{
var body = GetPlayerModel();
GetComponent<AnimationSync>().InitLocal(body);
2020-11-20 19:50:31 +00:00
GetComponent<InstrumentsManager>().InitLocal(body);
Player.Body = body.gameObject;
return body;
2020-02-12 20:05:08 +01:00
}
protected override Transform InitRemoteTransform()
2020-02-15 20:48:02 +01:00
{
var body = Instantiate(GetPlayerModel());
GetComponent<AnimationSync>().InitRemote(body);
2020-11-20 19:50:31 +00:00
GetComponent<InstrumentsManager>().InitRemote(body);
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
2020-08-08 12:25:09 +02:00
marker.Init(Player);
Player.Body = body.gameObject;
return body;
2020-02-10 23:03:28 +01:00
}
2020-09-04 20:10:01 +01:00
public override bool IsReady => Locator.GetPlayerTransform() != null
&& Player != null
2020-11-03 21:18:40 +00:00
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
2020-09-03 17:09:38 +01:00
&& Player.IsReady
2020-12-02 09:51:53 +00:00
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
2020-02-10 23:03:28 +01:00
}
}