quantum-space-buddies/QSB/ShipSync/TransformSync/ShipLegTransformSync.cs
2023-07-28 19:30:57 +01:00

36 lines
1.2 KiB
C#

using QSB.ShipSync.WorldObjects;
using QSB.Syncs.Sectored.Rigidbodies;
using QSB.Utility.LinkedWorldObject;
using QSB.WorldSync;
namespace QSB.ShipSync.TransformSync;
public class ShipLegTransformSync : SectoredRigidbodySync, ILinkedNetworkBehaviour
{
/// <summary>
/// normally prints error when attached object is null.
/// this overrides it so that doesn't happen, since the module can be destroyed.
/// </summary>
protected override bool CheckValid()
=> AttachedTransform
&& base.CheckValid();
protected override bool CheckReady()
=> base.CheckReady()
&& _qsbModule != null // not sure how either of these can be null, but i guess better safe than sorry
&& _qsbModule.AttachedObject != null
&& _qsbModule.AttachedObject.isDetached;
protected override bool UseInterpolation => true;
private QSBShipDetachableLeg _qsbModule;
public void SetWorldObject(IWorldObject worldObject) => _qsbModule = (QSBShipDetachableLeg)worldObject;
protected override OWRigidbody InitAttachedRigidbody()
{
var owRigidbody = _qsbModule.AttachedObject.GetComponent<OWRigidbody>();
SectorDetector.Init(owRigidbody.transform.Find("DetectorVolume").GetComponent<SectorDetector>());
return owRigidbody;
}
}