2021-12-11 22:29:48 -08:00

62 lines
1.4 KiB
C#

using QSB.Anglerfish.TransformSync;
using QSB.AuthoritySync;
using QSB.WorldSync;
using QuantumUNET;
using UnityEngine;
namespace QSB.Anglerfish.WorldObjects
{
public class QSBAngler : WorldObject<AnglerfishController>
{
public AnglerTransformSync TransformSync;
public Transform TargetTransform;
public Vector3 TargetVelocity { get; private set; }
private Vector3 _lastTargetPosition;
public override void Init()
{
AnglerTransformSync.Anglers.Add(AttachedObject);
if (QSBCore.IsHost)
{
QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.AnglerPrefab));
}
StartDelayedReady();
QSBCore.UnityEvents.RunWhen(() => TransformSync, () =>
{
FinishDelayedReady();
if (QSBCore.IsHost)
{
TransformSync.NetIdentity.RegisterAuthQueue();
}
// for when you host/connect mid-game
TransformSync.NetIdentity.FireAuthQueue(!AttachedObject._anglerBody.IsSuspended());
});
}
public override void OnRemoval()
{
AnglerTransformSync.Anglers.Remove(AttachedObject);
if (QSBCore.IsHost)
{
TransformSync.NetIdentity.UnregisterAuthQueue();
QNetworkServer.Destroy(TransformSync.gameObject);
}
}
public void UpdateTargetVelocity()
{
if (TargetTransform == null)
{
return;
}
TargetVelocity = TargetTransform.position - _lastTargetPosition;
_lastTargetPosition = TargetTransform.position;
}
}
}