2023-05-08 18:30:59 +00:00
|
|
|
|
using QSB.OrbSync.WorldObjects;
|
|
|
|
|
using QSB.OwnershipSync;
|
2021-10-20 16:29:49 +00:00
|
|
|
|
using QSB.Syncs.Unsectored.Transforms;
|
2022-03-14 08:53:12 +00:00
|
|
|
|
using QSB.Utility.LinkedWorldObject;
|
2021-04-28 09:02:16 +00:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.OrbSync.TransformSync;
|
|
|
|
|
|
2022-03-14 10:34:00 +00:00
|
|
|
|
public class NomaiOrbTransformSync : UnsectoredTransformSync, ILinkedNetworkBehaviour
|
2021-04-28 09:02:16 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// normally prints error when attached object is null.
|
|
|
|
|
/// this overrides it so that doesn't happen, since the orb can be destroyed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override bool CheckValid() => AttachedTransform && base.CheckValid();
|
2022-01-26 03:42:22 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
protected override bool UseInterpolation => true;
|
|
|
|
|
protected override float DistanceChangeThreshold => 1f;
|
2022-01-15 05:25:13 +00:00
|
|
|
|
|
2022-03-14 10:34:00 +00:00
|
|
|
|
private QSBOrb _qsbOrb;
|
|
|
|
|
public void SetWorldObject(IWorldObject worldObject) => _qsbOrb = (QSBOrb)worldObject;
|
2022-03-14 08:53:12 +00:00
|
|
|
|
|
2022-03-14 10:34:00 +00:00
|
|
|
|
protected override Transform InitLocalTransform() => _qsbOrb.AttachedObject.transform;
|
|
|
|
|
protected override Transform InitRemoteTransform() => _qsbOrb.AttachedObject.transform;
|
2022-03-14 08:53:12 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void OnStartClient()
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
2022-01-15 05:25:13 +00:00
|
|
|
|
{
|
2023-05-08 18:41:43 +00:00
|
|
|
|
netIdentity.RegisterOwnerQueue();
|
2022-01-15 05:25:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
base.OnStartClient();
|
|
|
|
|
}
|
2022-01-15 05:25:13 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void OnStopClient()
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
2023-05-08 18:41:43 +00:00
|
|
|
|
netIdentity.UnregisterOwnerQueue();
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-01-15 05:25:13 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
base.OnStopClient();
|
|
|
|
|
}
|
2022-01-15 05:25:13 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
protected override void Init()
|
|
|
|
|
{
|
|
|
|
|
base.Init();
|
|
|
|
|
var body = AttachedTransform.GetAttachedOWRigidbody();
|
|
|
|
|
SetReferenceTransform(body.GetOrigParent());
|
2022-02-03 06:41:59 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
body.OnUnsuspendOWRigidbody += OnUnsuspend;
|
|
|
|
|
body.OnSuspendOWRigidbody += OnSuspend;
|
2023-05-08 18:41:43 +00:00
|
|
|
|
netIdentity.UpdateOwnerQueue(body.IsSuspended() ? OwnerQueueAction.Remove : OwnerQueueAction.Add);
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Uninit()
|
|
|
|
|
{
|
|
|
|
|
base.Uninit();
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-10-06 07:39:36 +00:00
|
|
|
|
var body = AttachedTransform.GetAttachedOWRigidbody();
|
|
|
|
|
body.OnUnsuspendOWRigidbody -= OnUnsuspend;
|
|
|
|
|
body.OnSuspendOWRigidbody -= OnSuspend;
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2022-01-22 01:51:26 +00:00
|
|
|
|
|
2023-05-08 18:41:43 +00:00
|
|
|
|
private void OnUnsuspend(OWRigidbody suspendedBody) => netIdentity.UpdateOwnerQueue(OwnerQueueAction.Add);
|
|
|
|
|
private void OnSuspend(OWRigidbody suspendedBody) => netIdentity.UpdateOwnerQueue(OwnerQueueAction.Remove);
|
2022-02-13 12:15:43 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
protected override void ApplyToAttached()
|
|
|
|
|
{
|
|
|
|
|
base.ApplyToAttached();
|
2022-02-14 00:57:27 +00:00
|
|
|
|
|
2022-03-14 10:34:00 +00:00
|
|
|
|
_qsbOrb.AttachedObject.SetTargetPosition(AttachedTransform.position);
|
2022-01-15 05:25:13 +00:00
|
|
|
|
}
|
2022-03-14 10:34:21 +00:00
|
|
|
|
}
|