2020-07-28 15:59:24 +02:00
|
|
|
|
using QSB.Animation;
|
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-02-21 23:36:07 +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
|
|
|
|
|
2020-07-28 00:13:43 +01:00
|
|
|
|
public Transform bodyTransform;
|
|
|
|
|
|
2020-03-07 16:40:17 +01:00
|
|
|
|
public override void OnStartLocalPlayer()
|
|
|
|
|
{
|
|
|
|
|
LocalInstance = this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 15:59:24 +02:00
|
|
|
|
private uint GetAttachedNetId()
|
2020-07-28 00:13:43 +01:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
Players are stored in PlayerRegistry using a specific ID. This ID has to remain the same
|
|
|
|
|
for all components of a player, so I've chosen to used the netId of PlayerTransformSync.
|
|
|
|
|
This is minus 0 so all transformsyncs follow the same template.
|
|
|
|
|
*/
|
|
|
|
|
return netId.Value - 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 21:51:58 +01:00
|
|
|
|
private Transform GetPlayerModel()
|
2020-02-15 20:48:02 +01:00
|
|
|
|
{
|
2020-03-13 20:44:32 +01:00
|
|
|
|
return Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2");
|
2020-02-11 19:56:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 21:51:58 +01:00
|
|
|
|
protected override Transform InitLocalTransform()
|
2020-02-15 20:48:02 +01:00
|
|
|
|
{
|
2020-02-21 21:51:58 +01:00
|
|
|
|
var body = GetPlayerModel();
|
2020-02-14 22:14:24 +01:00
|
|
|
|
|
2020-07-28 00:13:43 +01:00
|
|
|
|
bodyTransform = body;
|
|
|
|
|
|
2020-02-23 18:31:38 +01:00
|
|
|
|
GetComponent<AnimationSync>().InitLocal(body);
|
2020-02-21 21:51:58 +01:00
|
|
|
|
|
2020-07-30 21:57:39 +02:00
|
|
|
|
PlayerRegistry.GetPlayer(GetAttachedNetId()).Body = body.gameObject;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2020-02-21 21:51:58 +01:00
|
|
|
|
return body;
|
2020-02-12 20:05:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 21:51:58 +01:00
|
|
|
|
protected override Transform InitRemoteTransform()
|
2020-02-15 20:48:02 +01:00
|
|
|
|
{
|
2020-02-21 21:51:58 +01:00
|
|
|
|
var body = Instantiate(GetPlayerModel());
|
2020-02-12 22:00:17 +01:00
|
|
|
|
|
2020-07-28 00:13:43 +01:00
|
|
|
|
bodyTransform = body;
|
|
|
|
|
|
2020-02-23 18:31:38 +01:00
|
|
|
|
GetComponent<AnimationSync>().InitRemote(body);
|
2020-02-14 22:14:24 +01:00
|
|
|
|
|
2020-05-19 19:41:33 +02:00
|
|
|
|
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
|
|
|
|
|
marker.SetId(netId.Value);
|
|
|
|
|
|
2020-07-30 21:57:39 +02:00
|
|
|
|
PlayerRegistry.GetPlayer(GetAttachedNetId()).Body = body.gameObject;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2020-02-21 21:51:58 +01:00
|
|
|
|
return body;
|
2020-02-10 23:03:28 +01:00
|
|
|
|
}
|
2020-02-23 18:31:38 +01:00
|
|
|
|
|
2020-03-13 20:44:32 +01:00
|
|
|
|
protected override bool IsReady()
|
|
|
|
|
{
|
2020-07-29 15:07:07 +01:00
|
|
|
|
return Locator.GetPlayerTransform() != null && PlayerRegistry.PlayerExists(GetAttachedNetId());
|
2020-03-13 20:44:32 +01:00
|
|
|
|
}
|
2020-02-10 23:03:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|