Files
2026-03-04 10:03:45 +08:00

111 lines
2.8 KiB
C#

using UnityEngine;
namespace Smooth
{
public class StatePUN2
{
public float ownerTimestamp;
public Vector3 position;
public Quaternion rotation;
public Vector3 scale;
public Vector3 velocity;
public Vector3 angularVelocity;
public bool teleport;
public bool atPositionalRest;
public bool atRotationalRest;
public float receivedOnServerTimestamp;
public Vector3 reusableRotationVector;
public bool serverShouldRelayPosition;
public bool serverShouldRelayRotation;
public bool serverShouldRelayScale;
public bool serverShouldRelayVelocity;
public bool serverShouldRelayAngularVelocity;
public bool serverShouldRelayTeleport;
public float receivedTimestamp;
public int localTimeResetIndicator;
public StatePUN2 copyFromState(StatePUN2 state)
{
ownerTimestamp = state.ownerTimestamp;
position = state.position;
rotation = state.rotation;
scale = state.scale;
velocity = state.velocity;
angularVelocity = state.angularVelocity;
receivedTimestamp = state.receivedTimestamp;
localTimeResetIndicator = state.localTimeResetIndicator;
return this;
}
public static StatePUN2 Lerp(StatePUN2 targetTempState, StatePUN2 start, StatePUN2 end, float t)
{
targetTempState.position = Vector3.Lerp(start.position, end.position, t);
targetTempState.rotation = Quaternion.Lerp(start.rotation, end.rotation, t);
targetTempState.scale = Vector3.Lerp(start.scale, end.scale, t);
targetTempState.velocity = Vector3.Lerp(start.velocity, end.velocity, t);
targetTempState.angularVelocity = Vector3.Lerp(start.angularVelocity, end.angularVelocity, t);
targetTempState.ownerTimestamp = Mathf.Lerp(start.ownerTimestamp, end.ownerTimestamp, t);
return targetTempState;
}
public void resetTheVariables()
{
ownerTimestamp = 0f;
position = Vector3.zero;
rotation = Quaternion.identity;
scale = Vector3.zero;
velocity = Vector3.zero;
angularVelocity = Vector3.zero;
atPositionalRest = false;
atRotationalRest = false;
teleport = false;
receivedTimestamp = 0f;
localTimeResetIndicator = 0;
}
public void copyFromSmoothSync(SmoothSyncPUN2 smoothSyncScript)
{
ownerTimestamp = smoothSyncScript.localTime;
position = smoothSyncScript.getPosition();
rotation = smoothSyncScript.getRotation();
scale = smoothSyncScript.getScale();
if (smoothSyncScript.hasRigidbody)
{
velocity = smoothSyncScript.rb.velocity;
angularVelocity = smoothSyncScript.rb.angularVelocity * 57.29578f;
}
else if (smoothSyncScript.hasRigidbody2D)
{
velocity = smoothSyncScript.rb2D.velocity;
angularVelocity.x = 0f;
angularVelocity.y = 0f;
angularVelocity.z = smoothSyncScript.rb2D.angularVelocity;
}
else
{
velocity = Vector3.zero;
angularVelocity = Vector3.zero;
}
localTimeResetIndicator = smoothSyncScript.localTimeResetIndicator;
}
}
}