54 lines
1.2 KiB
C#
Raw Normal View History

2022-01-28 20:49:07 -08:00
using Cysharp.Threading.Tasks;
using Mirror;
2022-01-21 15:13:16 -08:00
using QSB.Anglerfish.Messages;
using QSB.Anglerfish.TransformSync;
2022-01-21 15:13:16 -08:00
using QSB.Messaging;
2021-11-09 17:56:45 -08:00
using QSB.WorldSync;
2022-01-28 20:49:07 -08:00
using System.Threading;
2021-11-09 17:56:45 -08:00
using UnityEngine;
namespace QSB.Anglerfish.WorldObjects
2021-11-09 17:56:45 -08:00
{
public class QSBAngler : WorldObject<AnglerfishController>
{
public override bool ShouldDisplayDebug() => false;
public AnglerTransformSync TransformSync;
public Transform TargetTransform;
public Vector3 TargetVelocity { get; private set; }
2021-11-10 09:28:05 +00:00
private Vector3 _lastTargetPosition;
2021-11-09 17:56:45 -08:00
public override async UniTask Init(CancellationToken ct)
2021-11-09 17:56:45 -08:00
{
if (QSBCore.IsHost)
{
NetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.singleton.AnglerPrefab));
}
2021-11-09 17:56:45 -08:00
await UniTask.WaitUntil(() => TransformSync, cancellationToken: ct);
}
public override void OnRemoval()
2021-11-09 17:56:45 -08:00
{
if (QSBCore.IsHost)
{
NetworkServer.Destroy(TransformSync.gameObject);
}
2021-11-09 18:38:19 -08:00
}
public override void SendInitialState(uint to) =>
this.SendMessage(new AnglerDataMessage(this) { To = to });
2022-01-21 15:13:16 -08:00
public void UpdateTargetVelocity()
2021-11-09 20:35:55 -08:00
{
if (TargetTransform == null)
{
return;
}
TargetVelocity = TargetTransform.position - _lastTargetPosition;
_lastTargetPosition = TargetTransform.position;
}
2021-11-09 17:56:45 -08:00
}
}