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;
|
2022-01-14 22:54:18 -08:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
public class QSBAngler : WorldObject<AnglerfishController>
|
|
|
|
|
{
|
2022-01-21 17:56:20 -08:00
|
|
|
|
public override bool ShouldDisplayDebug() => false;
|
|
|
|
|
|
2022-01-14 22:28:44 -08:00
|
|
|
|
public AnglerTransformSync TransformSync;
|
2021-11-10 09:28:05 +00:00
|
|
|
|
public Transform TargetTransform;
|
|
|
|
|
public Vector3 TargetVelocity { get; private set; }
|
|
|
|
|
|
|
|
|
|
private Vector3 _lastTargetPosition;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
|
2022-01-28 20:49:07 -08:00
|
|
|
|
public override async UniTask Init(CancellationToken cancellationToken)
|
2021-11-09 17:56:45 -08:00
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
2022-01-27 03:15:52 -08:00
|
|
|
|
NetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.singleton.AnglerPrefab));
|
2021-11-09 17:56:45 -08:00
|
|
|
|
}
|
2021-11-30 20:17:14 -08:00
|
|
|
|
|
2022-01-28 20:49:07 -08:00
|
|
|
|
await UniTask.WaitUntil(() => TransformSync, cancellationToken: cancellationToken);
|
2021-11-09 17:56:45 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnRemoval()
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
2022-01-14 22:54:18 -08:00
|
|
|
|
NetworkServer.Destroy(TransformSync.gameObject);
|
2021-11-09 17:56:45 -08:00
|
|
|
|
}
|
2021-11-09 18:38:19 -08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 23:40:38 -08:00
|
|
|
|
public override void SendInitialState(uint to)
|
2022-01-21 15:13:16 -08:00
|
|
|
|
{
|
|
|
|
|
if (TransformSync.hasAuthority)
|
|
|
|
|
{
|
|
|
|
|
this.SendMessage(new AnglerDataMessage(this) { To = to });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|