2021-11-10 09:18:57 +00:00
|
|
|
|
using QSB.Anglerfish.WorldObjects;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
using QSB.Syncs.Unsectored.Rigidbodies;
|
|
|
|
|
using QSB.WorldSync;
|
2021-11-13 22:10:32 -08:00
|
|
|
|
using QuantumUNET.Transport;
|
2021-11-25 15:32:34 +00:00
|
|
|
|
using System.Collections.Generic;
|
2021-11-09 22:01:50 -08:00
|
|
|
|
using UnityEngine;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
|
|
|
|
|
namespace QSB.Anglerfish.TransformSync
|
|
|
|
|
{
|
|
|
|
|
public class AnglerTransformSync : UnsectoredRigidbodySync
|
|
|
|
|
{
|
2021-12-04 09:51:27 +00:00
|
|
|
|
public override bool IsReady => WorldObjectManager.AllObjectsAdded;
|
2021-11-13 22:10:32 -08:00
|
|
|
|
public override bool UseInterpolation => false;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
|
2021-11-09 18:38:19 -08:00
|
|
|
|
private QSBAngler _qsbAngler;
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private static readonly List<AnglerTransformSync> _instances = new();
|
2021-11-10 01:20:16 -08:00
|
|
|
|
|
2021-11-10 09:28:05 +00:00
|
|
|
|
protected override OWRigidbody GetRigidbody()
|
|
|
|
|
=> _qsbAngler.AttachedObject._anglerBody;
|
|
|
|
|
|
2021-11-09 17:56:45 -08:00
|
|
|
|
public override void Start()
|
|
|
|
|
{
|
|
|
|
|
_instances.Add(this);
|
|
|
|
|
base.Start();
|
|
|
|
|
}
|
2021-11-10 01:20:16 -08:00
|
|
|
|
|
2021-11-09 17:56:45 -08:00
|
|
|
|
protected override void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
_instances.Remove(this);
|
|
|
|
|
base.OnDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-13 22:10:32 -08:00
|
|
|
|
public override float GetNetworkSendInterval() => 1;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
|
|
|
|
|
protected override void Init()
|
|
|
|
|
{
|
2021-11-09 18:38:19 -08:00
|
|
|
|
_qsbAngler = QSBWorldSync.GetWorldFromId<QSBAngler>(_instances.IndexOf(this));
|
2021-11-10 09:28:05 +00:00
|
|
|
|
_qsbAngler.TransformSync = this;
|
2021-11-09 17:56:45 -08:00
|
|
|
|
|
|
|
|
|
base.Init();
|
2021-11-09 22:01:50 -08:00
|
|
|
|
SetReferenceTransform(_qsbAngler.AttachedObject._brambleBody.transform);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-13 22:10:32 -08:00
|
|
|
|
private bool _shouldUpdate;
|
|
|
|
|
|
|
|
|
|
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
|
|
|
|
{
|
|
|
|
|
base.DeserializeTransform(reader, initialState);
|
2021-12-01 23:09:34 -08:00
|
|
|
|
|
2021-12-04 09:51:27 +00:00
|
|
|
|
if (!WorldObjectManager.AllObjectsReady || HasAuthority)
|
2021-12-01 23:09:34 -08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-13 22:10:32 -08:00
|
|
|
|
_shouldUpdate = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool UpdateTransform()
|
|
|
|
|
{
|
|
|
|
|
if (HasAuthority)
|
|
|
|
|
{
|
|
|
|
|
return base.UpdateTransform();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_shouldUpdate)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-11-25 15:38:05 +00:00
|
|
|
|
|
2021-11-13 22:10:32 -08:00
|
|
|
|
_shouldUpdate = false;
|
|
|
|
|
return base.UpdateTransform();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 22:01:50 -08:00
|
|
|
|
protected override void OnRenderObject()
|
|
|
|
|
{
|
2021-12-04 09:51:27 +00:00
|
|
|
|
if (!WorldObjectManager.AllObjectsReady
|
2021-11-09 22:01:50 -08:00
|
|
|
|
|| !QSBCore.ShowLinesInDebug
|
|
|
|
|
|| !IsReady
|
2021-12-01 01:44:12 -08:00
|
|
|
|
|| ReferenceTransform == null
|
|
|
|
|
|| ((OWRigidbody)AttachedObject).IsSuspended())
|
2021-11-09 22:01:50 -08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 03:55:56 -08:00
|
|
|
|
base.OnRenderObject();
|
|
|
|
|
|
2021-12-01 01:44:12 -08:00
|
|
|
|
Popcron.Gizmos.Sphere(AttachedObject.transform.position, _qsbAngler.AttachedObject._arrivalDistance, Color.blue);
|
|
|
|
|
Popcron.Gizmos.Sphere(AttachedObject.transform.position, _qsbAngler.AttachedObject._pursueDistance, Color.red);
|
|
|
|
|
Popcron.Gizmos.Sphere(AttachedObject.transform.position, _qsbAngler.AttachedObject._escapeDistance, Color.yellow);
|
|
|
|
|
Popcron.Gizmos.Sphere(AttachedObject.transform.position
|
|
|
|
|
+ AttachedObject.transform.TransformDirection(_qsbAngler.AttachedObject._mouthOffset), 3, Color.grey);
|
|
|
|
|
|
|
|
|
|
if (_qsbAngler.TargetTransform != null)
|
|
|
|
|
{
|
|
|
|
|
Popcron.Gizmos.Line(_qsbAngler.TargetTransform.position, ((OWRigidbody)AttachedObject).GetPosition(), Color.gray);
|
|
|
|
|
Popcron.Gizmos.Line(_qsbAngler.TargetTransform.position, _qsbAngler.TargetTransform.position + _qsbAngler.TargetVelocity, Color.green);
|
|
|
|
|
Popcron.Gizmos.Line(((OWRigidbody)AttachedObject).GetPosition(), _qsbAngler.AttachedObject._targetPos, Color.red);
|
|
|
|
|
Popcron.Gizmos.Sphere(_qsbAngler.AttachedObject._targetPos, 5, Color.red);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Popcron.Gizmos.Line(AttachedObject.transform.position, _qsbAngler.AttachedObject.GetTargetPosition(), Color.white);
|
2021-11-09 17:56:45 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|