62 lines
1.5 KiB
C#
Raw Normal View History

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-10 09:18:57 +00:00
using System.Collections.Generic;
using UnityEngine;
2021-11-09 17:56:45 -08:00
namespace QSB.Anglerfish.TransformSync
{
public class AnglerTransformSync : UnsectoredRigidbodySync
{
public override bool IsReady => QSBCore.WorldObjectsReady;
public override bool UseInterpolation => true;
2021-11-09 18:38:19 -08:00
private QSBAngler _qsbAngler;
2021-11-09 17:56:45 -08:00
private static readonly List<AnglerTransformSync> _instances = new List<AnglerTransformSync>();
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-10 09:28:05 +00:00
public override float GetNetworkSendInterval()
=> 1 / 4f;
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();
SetReferenceTransform(_qsbAngler.AttachedObject._brambleBody.transform);
}
protected override void OnRenderObject()
{
base.OnRenderObject();
if (!QSBCore.WorldObjectsReady
|| !QSBCore.DebugMode
|| !QSBCore.ShowLinesInDebug
|| !IsReady
|| ReferenceTransform == null
|| _intermediaryTransform.GetReferenceTransform() == null)
{
return;
}
Popcron.Gizmos.Line(AttachedObject.transform.position, _qsbAngler.AttachedObject.GetTargetPosition(), Color.white);
2021-11-09 17:56:45 -08:00
}
}
}