2021-11-10 09:18:57 +00:00
|
|
|
|
using QSB.Anglerfish.TransformSync;
|
2021-12-01 17:50:56 -08:00
|
|
|
|
using QSB.AuthoritySync;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
using QuantumUNET;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Anglerfish.WorldObjects
|
|
|
|
|
{
|
|
|
|
|
public class QSBAngler : WorldObject<AnglerfishController>
|
|
|
|
|
{
|
2021-11-10 09:28:05 +00:00
|
|
|
|
public AnglerTransformSync TransformSync;
|
|
|
|
|
public Transform TargetTransform;
|
|
|
|
|
public Vector3 TargetVelocity { get; private set; }
|
|
|
|
|
|
|
|
|
|
private Vector3 _lastTargetPosition;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
|
|
|
|
|
public override void Init(AnglerfishController attachedObject, int id)
|
|
|
|
|
{
|
|
|
|
|
ObjectId = id;
|
|
|
|
|
AttachedObject = attachedObject;
|
|
|
|
|
|
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
2021-11-30 20:50:28 -08:00
|
|
|
|
QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.AnglerPrefab));
|
2021-11-09 17:56:45 -08:00
|
|
|
|
}
|
2021-11-30 20:17:14 -08:00
|
|
|
|
|
2021-12-02 00:42:24 -08:00
|
|
|
|
StartDelayedReady();
|
2021-11-30 20:17:14 -08:00
|
|
|
|
QSBCore.UnityEvents.RunWhen(() => TransformSync, () =>
|
2021-12-02 00:42:24 -08:00
|
|
|
|
{
|
|
|
|
|
FinishDelayedReady();
|
|
|
|
|
|
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
|
|
|
|
TransformSync.NetIdentity.RegisterAuthQueue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// for when you host/connect mid-game
|
|
|
|
|
TransformSync.NetIdentity.FireAuthQueue(!AttachedObject._anglerBody.IsSuspended());
|
|
|
|
|
});
|
2021-11-09 17:56:45 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnRemoval()
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
2021-12-01 17:50:56 -08:00
|
|
|
|
TransformSync.NetIdentity.UnregisterAuthQueue();
|
2021-11-10 09:28:05 +00:00
|
|
|
|
QNetworkServer.Destroy(TransformSync.gameObject);
|
2021-11-09 17:56:45 -08:00
|
|
|
|
}
|
2021-11-09 18:38:19 -08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-30 17:29:26 -08:00
|
|
|
|
public void UpdateTargetVelocity()
|
2021-11-09 20:35:55 -08:00
|
|
|
|
{
|
2021-11-10 09:28:05 +00:00
|
|
|
|
if (TargetTransform == null)
|
2021-11-09 22:01:50 -08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-25 15:38:05 +00:00
|
|
|
|
|
2021-11-10 09:28:05 +00:00
|
|
|
|
TargetVelocity = TargetTransform.position - _lastTargetPosition;
|
|
|
|
|
_lastTargetPosition = TargetTransform.position;
|
2021-11-09 20:35:55 -08:00
|
|
|
|
}
|
2021-11-09 17:56:45 -08:00
|
|
|
|
}
|
|
|
|
|
}
|