older velnet changes - seems to be mostly samples
parent
6d52a338c5
commit
78076c7f41
|
|
@ -9,12 +9,18 @@ namespace VelNet
|
||||||
[AddComponentMenu("VelNet/VelNet Sync Transform")]
|
[AddComponentMenu("VelNet/VelNet Sync Transform")]
|
||||||
public class SyncTransform : NetworkSerializedObjectStream
|
public class SyncTransform : NetworkSerializedObjectStream
|
||||||
{
|
{
|
||||||
public bool useLocalTransform;
|
[Space]
|
||||||
[Tooltip("0 to disable.")]
|
public bool position = true;
|
||||||
public float teleportDistance;
|
public bool rotation = true;
|
||||||
[Tooltip("0 to disable.")]
|
[Tooltip("Scale is always local")] public bool scale;
|
||||||
public float teleportAngle;
|
|
||||||
|
|
||||||
|
[Space]
|
||||||
|
public bool useLocalTransform;
|
||||||
|
|
||||||
|
[Tooltip("0 to disable.")] public float teleportDistance;
|
||||||
|
[Tooltip("0 to disable.")] public float teleportAngle;
|
||||||
|
|
||||||
|
private Vector3 targetScale;
|
||||||
private Vector3 targetPosition;
|
private Vector3 targetPosition;
|
||||||
private Quaternion targetRotation;
|
private Quaternion targetRotation;
|
||||||
private float distanceAtReceiveTime;
|
private float distanceAtReceiveTime;
|
||||||
|
|
@ -32,6 +38,8 @@ namespace VelNet
|
||||||
targetPosition = transform.position;
|
targetPosition = transform.position;
|
||||||
targetRotation = transform.rotation;
|
targetRotation = transform.rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
targetScale = transform.localScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -39,8 +47,9 @@ namespace VelNet
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void SendState(BinaryWriter writer)
|
protected override void SendState(BinaryWriter writer)
|
||||||
{
|
{
|
||||||
writer.Write(transform.localPosition);
|
if (position) writer.Write(transform.localPosition);
|
||||||
writer.Write(transform.localRotation);
|
if (rotation) writer.Write(transform.localRotation);
|
||||||
|
if (scale) writer.Write(transform.localScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -49,8 +58,9 @@ namespace VelNet
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void ReceiveState(BinaryReader reader)
|
protected override void ReceiveState(BinaryReader reader)
|
||||||
{
|
{
|
||||||
targetPosition = reader.ReadVector3();
|
if (position) targetPosition = reader.ReadVector3();
|
||||||
targetRotation = reader.ReadQuaternion();
|
if (rotation) targetRotation = reader.ReadQuaternion();
|
||||||
|
if (scale) targetScale = reader.ReadVector3();
|
||||||
|
|
||||||
// record the distance from the target for interpolation
|
// record the distance from the target for interpolation
|
||||||
if (useLocalTransform)
|
if (useLocalTransform)
|
||||||
|
|
@ -61,6 +71,7 @@ namespace VelNet
|
||||||
{
|
{
|
||||||
transform.localPosition = targetPosition;
|
transform.localPosition = targetPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (teleportAngle != 0 && teleportAngle < angleAtReceiveTime)
|
if (teleportAngle != 0 && teleportAngle < angleAtReceiveTime)
|
||||||
{
|
{
|
||||||
transform.localRotation = targetRotation;
|
transform.localRotation = targetRotation;
|
||||||
|
|
@ -74,6 +85,7 @@ namespace VelNet
|
||||||
{
|
{
|
||||||
transform.position = targetPosition;
|
transform.position = targetPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (teleportAngle != 0 && teleportAngle < angleAtReceiveTime)
|
if (teleportAngle != 0 && teleportAngle < angleAtReceiveTime)
|
||||||
{
|
{
|
||||||
transform.rotation = targetRotation;
|
transform.rotation = targetRotation;
|
||||||
|
|
@ -86,25 +98,38 @@ namespace VelNet
|
||||||
if (IsMine) return;
|
if (IsMine) return;
|
||||||
|
|
||||||
if (useLocalTransform)
|
if (useLocalTransform)
|
||||||
|
{
|
||||||
|
if (position)
|
||||||
{
|
{
|
||||||
transform.localPosition = Vector3.MoveTowards(
|
transform.localPosition = Vector3.MoveTowards(
|
||||||
transform.localPosition,
|
transform.localPosition,
|
||||||
targetPosition,
|
targetPosition,
|
||||||
Time.deltaTime * distanceAtReceiveTime * serializationRateHz
|
Time.deltaTime * distanceAtReceiveTime * serializationRateHz
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rotation)
|
||||||
|
{
|
||||||
transform.localRotation = Quaternion.RotateTowards(
|
transform.localRotation = Quaternion.RotateTowards(
|
||||||
transform.localRotation,
|
transform.localRotation,
|
||||||
targetRotation,
|
targetRotation,
|
||||||
Time.deltaTime * angleAtReceiveTime * serializationRateHz
|
Time.deltaTime * angleAtReceiveTime * serializationRateHz
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (position)
|
||||||
{
|
{
|
||||||
transform.position = Vector3.MoveTowards(
|
transform.position = Vector3.MoveTowards(
|
||||||
transform.position,
|
transform.position,
|
||||||
targetPosition,
|
targetPosition,
|
||||||
Time.deltaTime * distanceAtReceiveTime * serializationRateHz
|
Time.deltaTime * distanceAtReceiveTime * serializationRateHz
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rotation)
|
||||||
|
{
|
||||||
transform.rotation = Quaternion.RotateTowards(
|
transform.rotation = Quaternion.RotateTowards(
|
||||||
transform.rotation,
|
transform.rotation,
|
||||||
targetRotation,
|
targetRotation,
|
||||||
|
|
@ -112,5 +137,16 @@ namespace VelNet
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (scale)
|
||||||
|
{
|
||||||
|
transform.localScale = Vector3.Lerp(
|
||||||
|
transform.localScale,
|
||||||
|
targetScale,
|
||||||
|
Time.deltaTime * serializationRateHz
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1206,7 +1206,7 @@ namespace VelNet
|
||||||
NetworkObject prefab = instance.prefabs.Find(p => p.name == prefabName);
|
NetworkObject prefab = instance.prefabs.Find(p => p.name == prefabName);
|
||||||
if (prefab == null)
|
if (prefab == null)
|
||||||
{
|
{
|
||||||
VelNetLogger.Error("Couldn't find a prefab with that name: " + prefabName);
|
VelNetLogger.Error("Couldn't find a prefab with that name: " + prefabName + "\nMake sure to add the prefab to list of prefabs in VelNetManager");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue