simplify ReferenceTransform check

This commit is contained in:
JohnCorby 2022-01-20 22:40:28 -08:00
parent f035f64d10
commit c3422177ab
4 changed files with 19 additions and 49 deletions

View File

@ -31,8 +31,7 @@ namespace QSB.ShipSync.TransformSync
protected override void ApplyToAttached()
{
ApplyToSector();
if (ReferenceTransform == null || transform.position == Vector3.zero)
if (!ReferenceTransform)
{
return;
}

View File

@ -48,14 +48,7 @@ namespace QSB.Syncs.Sectored
protected void GetFromSector()
{
if (ReferenceSector != null)
{
_sectorId = ReferenceSector.ObjectId;
}
else
{
_sectorId = -1;
}
_sectorId = ReferenceSector?.ObjectId ?? -1;
}
protected void ApplyToSector()

View File

@ -50,28 +50,21 @@ namespace QSB.Syncs.Sectored.Rigidbodies
protected override void GetFromAttached()
{
GetFromSector();
if (!ReferenceTransform)
{
return;
}
if (ReferenceTransform != null)
{
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
_relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
_relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
}
else
{
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;
_relativeVelocity = Vector3.zero;
_relativeAngularVelocity = Vector3.zero;
}
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
_relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
_relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
}
protected override void ApplyToAttached()
{
ApplyToSector();
if (ReferenceTransform == null || transform.position == Vector3.zero)
if (!ReferenceTransform)
{
return;
}

View File

@ -1,5 +1,4 @@
using Mirror;
using QSB.Utility;
using QSB.Utility;
using UnityEngine;
namespace QSB.Syncs.Sectored.Transforms
@ -12,36 +11,22 @@ namespace QSB.Syncs.Sectored.Transforms
protected override Transform InitAttachedTransform()
=> hasAuthority ? InitLocalTransform() : InitRemoteTransform();
protected override void Deserialize(NetworkReader reader, bool initialState)
{
base.Deserialize(reader, initialState);
if (transform.position == Vector3.zero)
{
}
}
protected override void GetFromAttached()
{
GetFromSector();
if (!ReferenceTransform)
{
return;
}
if (ReferenceTransform != null)
{
transform.position = ReferenceTransform.ToRelPos(AttachedTransform.position);
transform.rotation = ReferenceTransform.ToRelRot(AttachedTransform.rotation);
}
else
{
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;
}
transform.position = ReferenceTransform.ToRelPos(AttachedTransform.position);
transform.rotation = ReferenceTransform.ToRelRot(AttachedTransform.rotation);
}
protected override void ApplyToAttached()
{
ApplyToSector();
if (ReferenceTransform == null || transform.position == Vector3.zero)
if (!ReferenceTransform)
{
return;
}