mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 09:39:56 +00:00
remove reparenting transform sync
This commit is contained in:
parent
c9d2dfd733
commit
93274af6e5
@ -8,7 +8,7 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
||||
{
|
||||
public abstract class SectoredRigidbodySync : BaseSectoredSync<OWRigidbody>
|
||||
{
|
||||
public override bool ShouldReparentAttachedObject => false;
|
||||
public override bool DestroyAttachedObject => false;
|
||||
|
||||
public const float PositionMovedThreshold = 0.05f;
|
||||
public const float AngleRotatedThreshold = 0.05f;
|
||||
|
@ -8,7 +8,7 @@ namespace QSB.Syncs.Sectored.Transforms
|
||||
{
|
||||
public abstract class SectoredTransformSync : BaseSectoredSync<Transform>
|
||||
{
|
||||
public override bool ShouldReparentAttachedObject => true;
|
||||
public override bool DestroyAttachedObject => true;
|
||||
|
||||
protected abstract Transform InitLocalTransform();
|
||||
protected abstract Transform InitRemoteTransform();
|
||||
@ -79,20 +79,22 @@ namespace QSB.Syncs.Sectored.Transforms
|
||||
return true;
|
||||
}
|
||||
|
||||
var targetPos = transform.position;
|
||||
var targetRot = transform.rotation;
|
||||
if (targetPos != Vector3.zero)
|
||||
if (ReferenceTransform == null || transform.position == Vector3.zero)
|
||||
{
|
||||
if (UseInterpolation)
|
||||
{
|
||||
AttachedObject.localPosition = SmartSmoothDamp(AttachedObject.localPosition, targetPos);
|
||||
AttachedObject.localRotation = SmartSmoothDamp(AttachedObject.localRotation, targetRot);
|
||||
}
|
||||
else
|
||||
{
|
||||
AttachedObject.localPosition = targetPos;
|
||||
AttachedObject.localRotation = targetRot;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (UseInterpolation)
|
||||
{
|
||||
var relPos = ReferenceTransform.ToRelPos(AttachedObject.position);
|
||||
var relRot = ReferenceTransform.ToRelRot(AttachedObject.rotation);
|
||||
AttachedObject.position = ReferenceTransform.FromRelPos(SmartSmoothDamp(relPos, transform.position));
|
||||
AttachedObject.rotation = ReferenceTransform.FromRelRot(SmartSmoothDamp(relRot, transform.rotation));
|
||||
}
|
||||
else
|
||||
{
|
||||
AttachedObject.position = ReferenceTransform.FromRelPos(transform.position);
|
||||
AttachedObject.rotation = ReferenceTransform.FromRelRot(transform.rotation);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -94,7 +94,7 @@ namespace QSB.Syncs
|
||||
public abstract bool UseInterpolation { get; }
|
||||
public abstract bool IgnoreDisabledAttachedObject { get; }
|
||||
public abstract bool IgnoreNullReferenceTransform { get; }
|
||||
public abstract bool ShouldReparentAttachedObject { get; }
|
||||
public abstract bool DestroyAttachedObject { get; }
|
||||
public abstract bool IsPlayerObject { get; }
|
||||
|
||||
public T AttachedObject { get; set; }
|
||||
@ -126,7 +126,7 @@ namespace QSB.Syncs
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
if (ShouldReparentAttachedObject)
|
||||
if (DestroyAttachedObject)
|
||||
{
|
||||
if (!HasAuthority && AttachedObject != null)
|
||||
{
|
||||
@ -145,7 +145,7 @@ namespace QSB.Syncs
|
||||
}
|
||||
|
||||
// TODO : maybe make it's own option
|
||||
if (ShouldReparentAttachedObject)
|
||||
if (DestroyAttachedObject)
|
||||
{
|
||||
if (!HasAuthority && AttachedObject != null)
|
||||
{
|
||||
@ -215,14 +215,6 @@ namespace QSB.Syncs
|
||||
return;
|
||||
}
|
||||
|
||||
if (ShouldReparentAttachedObject
|
||||
&& !HasAuthority
|
||||
&& AttachedObject.transform.parent != ReferenceTransform)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning : {LogName} : AttachedObject's parent is different to ReferenceTransform. Correcting...", MessageType.Warning);
|
||||
ReparentAttachedObject(ReferenceTransform);
|
||||
}
|
||||
|
||||
UpdateTransform();
|
||||
|
||||
base.Update();
|
||||
@ -252,48 +244,7 @@ namespace QSB.Syncs
|
||||
}
|
||||
|
||||
public void SetReferenceTransform(Transform referenceTransform)
|
||||
{
|
||||
if (ReferenceTransform == referenceTransform)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReferenceTransform = referenceTransform;
|
||||
|
||||
if (ShouldReparentAttachedObject)
|
||||
{
|
||||
if (AttachedObject == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - AttachedObject was null for {LogName} when trying to set reference transform to {referenceTransform?.name}. Waiting until not null...", MessageType.Warning);
|
||||
QSBCore.UnityEvents.RunWhen(
|
||||
() => AttachedObject != null,
|
||||
() => ReparentAttachedObject(referenceTransform));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasAuthority)
|
||||
{
|
||||
ReparentAttachedObject(referenceTransform);
|
||||
}
|
||||
}
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
transform.position = ReferenceTransform.ToRelPos(AttachedObject.transform.position);
|
||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedObject.transform.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReparentAttachedObject(Transform newParent)
|
||||
{
|
||||
if (AttachedObject.transform.parent != null && AttachedObject.transform.parent.GetComponent<Sector>() == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Trying to reparent AttachedObject {AttachedObject.name} which wasnt attached to sector!", MessageType.Warning);
|
||||
}
|
||||
|
||||
AttachedObject.transform.SetParent(newParent, true);
|
||||
AttachedObject.transform.localScale = Vector3.one;
|
||||
}
|
||||
=> ReferenceTransform = referenceTransform;
|
||||
|
||||
protected virtual void OnRenderObject()
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ namespace QSB.Syncs.Unsectored
|
||||
{
|
||||
public override bool IgnoreDisabledAttachedObject => false;
|
||||
public override bool IgnoreNullReferenceTransform => false;
|
||||
public override bool ShouldReparentAttachedObject => false;
|
||||
public override bool DestroyAttachedObject => false;
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState) { }
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ namespace QSB.Utility
|
||||
{
|
||||
var playerBody = Locator.GetPlayerBody();
|
||||
playerBody.WarpToPositionRotation(otherPlayer.Body.transform.position, otherPlayer.Body.transform.rotation);
|
||||
var parentBody = otherPlayer.Body.GetAttachedOWRigidbody(true);
|
||||
var parentBody = otherPlayer.TransformSync?.ReferenceSector?.AttachedObject?.GetOWRigidbody();
|
||||
if (parentBody != null)
|
||||
{
|
||||
playerBody.SetVelocity(parentBody.GetVelocity());
|
||||
|
@ -143,11 +143,9 @@ namespace QSB.Utility
|
||||
var networkTransform = player.TransformSync;
|
||||
var referenceSector = networkTransform.ReferenceSector;
|
||||
var referenceTransform = networkTransform.ReferenceTransform;
|
||||
var parent = networkTransform.AttachedObject?.transform.parent;
|
||||
|
||||
WriteLine(2, $" - Ref. Sector : {(referenceSector == null ? "NULL" : referenceSector.Name)}", referenceSector == null ? Color.red : Color.white);
|
||||
WriteLine(2, $" - Ref. Transform : {(referenceTransform == null ? "NULL" : referenceTransform.name)}", referenceTransform == null ? Color.red : Color.white);
|
||||
WriteLine(2, $" - Parent : {(parent == null ? "NULL" : parent.name)}", parent == null ? Color.red : Color.white);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
Loading…
x
Reference in New Issue
Block a user