mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 18:35:34 +00:00
49fa4d1eeb
* oh my god so many things * i came in and rewrote half the mod, sorry
73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using OWML.ModHelper.Events;
|
|
using QSB.Animation;
|
|
using QSB.Events;
|
|
using QSB.Utility;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace QSB.TransformSync
|
|
{
|
|
public class PlayerTransformSync : TransformSync
|
|
{
|
|
public static PlayerTransformSync LocalInstance { get; private set; }
|
|
|
|
public Transform bodyTransform;
|
|
|
|
public override void OnStartLocalPlayer()
|
|
{
|
|
LocalInstance = this;
|
|
}
|
|
|
|
uint GetAttachedNetId()
|
|
{
|
|
/*
|
|
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;
|
|
}
|
|
|
|
private Transform GetPlayerModel()
|
|
{
|
|
return Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2");
|
|
}
|
|
|
|
protected override Transform InitLocalTransform()
|
|
{
|
|
DebugLog.ToConsole("PlayerSync local " + GetAttachedNetId());
|
|
var body = GetPlayerModel();
|
|
|
|
bodyTransform = body;
|
|
|
|
GetComponent<AnimationSync>().InitLocal(body);
|
|
|
|
PlayerRegistry.RegisterPlayerBody(GetAttachedNetId(), body.gameObject);
|
|
|
|
return body;
|
|
}
|
|
|
|
protected override Transform InitRemoteTransform()
|
|
{
|
|
DebugLog.ToConsole("PlayerSync remote " + GetAttachedNetId());
|
|
var body = Instantiate(GetPlayerModel());
|
|
|
|
bodyTransform = body;
|
|
|
|
GetComponent<AnimationSync>().InitRemote(body);
|
|
|
|
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
|
|
marker.SetId(netId.Value);
|
|
|
|
PlayerRegistry.RegisterPlayerBody(GetAttachedNetId(), body.gameObject);
|
|
|
|
return body;
|
|
}
|
|
|
|
protected override bool IsReady()
|
|
{
|
|
return Locator.GetPlayerTransform() != null;
|
|
}
|
|
}
|
|
}
|