99 lines
3.2 KiB
C#
Raw Normal View History

2022-01-16 06:53:45 -08:00
using QSB.Anglerfish.WorldObjects;
2021-12-23 17:07:29 -08:00
using QSB.AuthoritySync;
2021-11-09 17:56:45 -08:00
using QSB.Syncs.Unsectored.Rigidbodies;
using QSB.WorldSync;
2021-11-25 15:32:34 +00:00
using System.Collections.Generic;
using UnityEngine;
2021-11-09 17:56:45 -08:00
namespace QSB.Anglerfish.TransformSync
{
2022-01-14 22:39:41 -08:00
public class AnglerTransformSync : UnsectoredRigidbodySync
2022-01-14 21:29:57 -08:00
{
2022-01-16 06:11:44 -08:00
protected override bool UseInterpolation => false;
2022-01-16 06:53:45 -08:00
protected override bool OnlyApplyOnDeserialize => true;
2022-01-14 21:29:57 -08:00
private QSBAngler _qsbAngler;
2022-01-14 22:28:44 -08:00
private static readonly List<AnglerTransformSync> _instances = new();
2022-01-14 21:29:57 -08:00
2022-01-16 04:51:37 -08:00
protected override OWRigidbody InitAttachedRigidbody()
2022-01-14 21:29:57 -08:00
=> _qsbAngler.AttachedObject._anglerBody;
2022-01-18 12:19:58 -08:00
public override void OnStartClient()
2022-01-14 21:29:57 -08:00
{
_instances.Add(this);
2022-01-18 12:19:58 -08:00
base.OnStartClient();
2022-01-14 21:29:57 -08:00
}
2022-01-18 15:06:45 -08:00
public override void OnStopClient()
2022-01-14 21:29:57 -08:00
{
_instances.Remove(this);
2022-01-18 15:06:45 -08:00
base.OnStopClient();
2022-01-14 21:29:57 -08:00
}
protected override float SendInterval => 1;
protected override bool UseReliableRpc => true;
protected override void Init()
{
_qsbAngler = AnglerManager.Anglers[_instances.IndexOf(this)].GetWorldObject<QSBAngler>();
2022-01-14 22:07:32 -08:00
_qsbAngler.TransformSync = this;
2022-01-14 21:29:57 -08:00
base.Init();
SetReferenceTransform(_qsbAngler.AttachedObject._brambleBody.transform);
if (QSBCore.IsHost)
{
netIdentity.RegisterAuthQueue();
}
AttachedRigidbody.OnUnsuspendOWRigidbody += OnUnsuspend;
AttachedRigidbody.OnSuspendOWRigidbody += OnSuspend;
netIdentity.SendAuthQueueMessage(AttachedRigidbody.IsSuspended() ? AuthQueueAction.Remove : AuthQueueAction.Add);
}
2022-01-21 17:51:26 -08:00
protected override void Uninit()
{
base.Uninit();
2022-01-21 17:51:26 -08:00
if (QSBCore.IsHost)
{
netIdentity.UnregisterAuthQueue();
}
AttachedRigidbody.OnUnsuspendOWRigidbody -= OnUnsuspend;
AttachedRigidbody.OnSuspendOWRigidbody -= OnSuspend;
}
2022-01-14 21:29:57 -08:00
private void OnUnsuspend(OWRigidbody suspendedBody) => netIdentity.SendAuthQueueMessage(AuthQueueAction.Add);
private void OnSuspend(OWRigidbody suspendedBody) => netIdentity.SendAuthQueueMessage(AuthQueueAction.Remove);
protected override void OnRenderObject()
{
2022-01-20 22:33:03 +00:00
if (!QSBCore.DebugSettings.DrawLines
|| !IsValid
2022-01-27 02:15:42 -08:00
|| !ReferenceTransform)
2022-01-14 21:29:57 -08:00
{
return;
}
base.OnRenderObject();
Popcron.Gizmos.Sphere(AttachedRigidbody.GetPosition(), _qsbAngler.AttachedObject._arrivalDistance, Color.blue);
Popcron.Gizmos.Sphere(AttachedRigidbody.GetPosition(), _qsbAngler.AttachedObject._pursueDistance, Color.red);
Popcron.Gizmos.Sphere(AttachedRigidbody.GetPosition(), _qsbAngler.AttachedObject._escapeDistance, Color.yellow);
Popcron.Gizmos.Sphere(AttachedRigidbody.GetPosition()
+ AttachedRigidbody.transform.TransformDirection(_qsbAngler.AttachedObject._mouthOffset), 3, Color.grey);
2022-01-21 20:58:12 -08:00
if (_qsbAngler.TargetTransform)
2022-01-14 21:29:57 -08:00
{
Popcron.Gizmos.Line(_qsbAngler.TargetTransform.position, AttachedRigidbody.GetPosition(), Color.gray);
Popcron.Gizmos.Line(_qsbAngler.TargetTransform.position, _qsbAngler.TargetTransform.position + _qsbAngler.TargetVelocity, Color.green);
Popcron.Gizmos.Line(AttachedRigidbody.GetPosition(), _qsbAngler.AttachedObject._targetPos, Color.red);
Popcron.Gizmos.Sphere(_qsbAngler.AttachedObject._targetPos, 5, Color.red);
}
2021-12-13 13:26:54 -08:00
// Popcron.Gizmos.Line(AttachedObject.GetPosition(), _qsbAngler.AttachedObject.GetTargetPosition(), Color.white);
2021-11-09 17:56:45 -08:00
}
}
}