jitter testing, avoid microphone for webgl build, dashboard ci
parent
2f20f79e89
commit
34ef979d2a
|
|
@ -1,20 +1,22 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
namespace VelNet
|
namespace VelNet
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A simple class that will sync the position and rotation of a network object with a rigidbody
|
/// A simple class that will sync the position and rotation of a network object with a rigidbody
|
||||||
|
/// This only uses the rigidbody for interpolation - it doesn't do any interpolatin itself
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AddComponentMenu("VelNet/VelNet Sync Rigidbody")]
|
[AddComponentMenu("VelNet/VelNet Sync Rigidbody")]
|
||||||
[RequireComponent(typeof(Rigidbody))]
|
[RequireComponent(typeof(Rigidbody))]
|
||||||
public class SyncRigidbody : NetworkSerializedObjectStream
|
public class SyncRigidbody : NetworkSerializedObjectStream
|
||||||
{
|
{
|
||||||
public bool useLocalTransform;
|
public bool useLocalTransform;
|
||||||
[Tooltip("0 to disable.")]
|
public float minPosDelta = .01f;
|
||||||
public float teleportDistance;
|
public float minAngleDelta = .1f;
|
||||||
[Tooltip("0 to disable.")]
|
public float minVelDelta = .01f;
|
||||||
public float teleportAngle;
|
public float minAngVelDelta = .1f;
|
||||||
|
|
||||||
public bool syncKinematic = true;
|
public bool syncKinematic = true;
|
||||||
public bool syncGravity = true;
|
public bool syncGravity = true;
|
||||||
|
|
@ -23,6 +25,8 @@ namespace VelNet
|
||||||
|
|
||||||
private Vector3 targetPosition;
|
private Vector3 targetPosition;
|
||||||
private Quaternion targetRotation;
|
private Quaternion targetRotation;
|
||||||
|
private Vector3 targetVel;
|
||||||
|
private Vector3 targetAngVel;
|
||||||
private float distanceAtReceiveTime;
|
private float distanceAtReceiveTime;
|
||||||
private float angleAtReceiveTime;
|
private float angleAtReceiveTime;
|
||||||
private Rigidbody rb;
|
private Rigidbody rb;
|
||||||
|
|
@ -58,11 +62,12 @@ namespace VelNet
|
||||||
writer.Write(transform.rotation);
|
writer.Write(transform.rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (syncVelocity) writer.Write(rb.velocity);
|
||||||
|
if (syncAngularVelocity) writer.Write(rb.angularVelocity);
|
||||||
|
|
||||||
// writer.Write((new bool[] {rb.isKinematic, rb.useGravity}).GetBitmasks());
|
// writer.Write((new bool[] {rb.isKinematic, rb.useGravity}).GetBitmasks());
|
||||||
if (syncKinematic) writer.Write(rb.isKinematic);
|
if (syncKinematic) writer.Write(rb.isKinematic);
|
||||||
if (syncGravity) writer.Write(rb.useGravity);
|
if (syncGravity) writer.Write(rb.useGravity);
|
||||||
if (syncVelocity) writer.Write(rb.velocity);
|
|
||||||
if (syncAngularVelocity) writer.Write(rb.angularVelocity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -74,21 +79,23 @@ namespace VelNet
|
||||||
targetPosition = reader.ReadVector3();
|
targetPosition = reader.ReadVector3();
|
||||||
targetRotation = reader.ReadQuaternion();
|
targetRotation = reader.ReadQuaternion();
|
||||||
|
|
||||||
|
if (syncVelocity) targetVel = reader.ReadVector3();
|
||||||
|
if (syncAngularVelocity) targetAngVel = reader.ReadVector3();
|
||||||
|
|
||||||
if (syncKinematic) rb.isKinematic = reader.ReadBoolean();
|
if (syncKinematic) rb.isKinematic = reader.ReadBoolean();
|
||||||
if (syncGravity) rb.useGravity = reader.ReadBoolean();
|
if (syncGravity) rb.useGravity = reader.ReadBoolean();
|
||||||
if (syncVelocity) rb.velocity = reader.ReadVector3();
|
|
||||||
if (syncAngularVelocity) rb.angularVelocity = reader.ReadVector3();
|
|
||||||
|
|
||||||
// record the distance from the target for interpolation
|
// record the distance from the target for interpolation
|
||||||
if (useLocalTransform)
|
if (useLocalTransform)
|
||||||
{
|
{
|
||||||
distanceAtReceiveTime = Vector3.Distance(targetPosition, transform.localPosition);
|
distanceAtReceiveTime = Vector3.Distance(targetPosition, transform.localPosition);
|
||||||
angleAtReceiveTime = Quaternion.Angle(targetRotation, transform.localRotation);
|
angleAtReceiveTime = Quaternion.Angle(targetRotation, transform.localRotation);
|
||||||
if (teleportDistance != 0 && teleportDistance < distanceAtReceiveTime)
|
if (minPosDelta < distanceAtReceiveTime)
|
||||||
{
|
{
|
||||||
transform.localPosition = targetPosition;
|
transform.localPosition = targetPosition;
|
||||||
}
|
}
|
||||||
if (teleportAngle != 0 && teleportAngle < angleAtReceiveTime)
|
|
||||||
|
if (minAngleDelta < angleAtReceiveTime)
|
||||||
{
|
{
|
||||||
transform.localRotation = targetRotation;
|
transform.localRotation = targetRotation;
|
||||||
}
|
}
|
||||||
|
|
@ -97,46 +104,27 @@ namespace VelNet
|
||||||
{
|
{
|
||||||
distanceAtReceiveTime = Vector3.Distance(targetPosition, transform.position);
|
distanceAtReceiveTime = Vector3.Distance(targetPosition, transform.position);
|
||||||
angleAtReceiveTime = Quaternion.Angle(targetRotation, transform.rotation);
|
angleAtReceiveTime = Quaternion.Angle(targetRotation, transform.rotation);
|
||||||
if (teleportDistance != 0 && teleportDistance < distanceAtReceiveTime)
|
if (minPosDelta < distanceAtReceiveTime)
|
||||||
{
|
{
|
||||||
transform.position = targetPosition;
|
transform.position = targetPosition;
|
||||||
}
|
}
|
||||||
if (teleportAngle != 0 && teleportAngle < angleAtReceiveTime)
|
|
||||||
|
if (minAngleDelta < angleAtReceiveTime)
|
||||||
{
|
{
|
||||||
transform.rotation = targetRotation;
|
transform.rotation = targetRotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float velDelta = Vector3.Distance(targetVel, rb.velocity);
|
||||||
|
float angVelDelta = Vector3.Distance(targetAngVel, rb.angularVelocity);
|
||||||
|
if (velDelta > minVelDelta)
|
||||||
|
{
|
||||||
|
rb.velocity = targetVel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
if (angVelDelta > minAngVelDelta)
|
||||||
{
|
{
|
||||||
if (IsMine) return;
|
rb.angularVelocity = targetAngVel;
|
||||||
|
|
||||||
if (useLocalTransform)
|
|
||||||
{
|
|
||||||
transform.localPosition = Vector3.MoveTowards(
|
|
||||||
transform.localPosition,
|
|
||||||
targetPosition,
|
|
||||||
Time.deltaTime * distanceAtReceiveTime * serializationRateHz
|
|
||||||
);
|
|
||||||
transform.localRotation = Quaternion.RotateTowards(
|
|
||||||
transform.localRotation,
|
|
||||||
targetRotation,
|
|
||||||
Time.deltaTime * angleAtReceiveTime * serializationRateHz
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
transform.position = Vector3.MoveTowards(
|
|
||||||
transform.position,
|
|
||||||
targetPosition,
|
|
||||||
Time.deltaTime * distanceAtReceiveTime * serializationRateHz
|
|
||||||
);
|
|
||||||
transform.rotation = Quaternion.RotateTowards(
|
|
||||||
transform.rotation,
|
|
||||||
targetRotation,
|
|
||||||
Time.deltaTime * angleAtReceiveTime * serializationRateHz
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,11 @@ namespace VelNet
|
||||||
[AddComponentMenu("VelNet/VelNet Sync Transform")]
|
[AddComponentMenu("VelNet/VelNet Sync Transform")]
|
||||||
public class SyncTransform : NetworkSerializedObjectStream
|
public class SyncTransform : NetworkSerializedObjectStream
|
||||||
{
|
{
|
||||||
[Space]
|
[Space] public bool position = true;
|
||||||
public bool position = true;
|
|
||||||
public bool rotation = true;
|
public bool rotation = true;
|
||||||
[Tooltip("Scale is always local")] public bool scale;
|
[Tooltip("Scale is always local")] public bool scale;
|
||||||
|
|
||||||
[Space]
|
[Space] public bool useLocalTransform;
|
||||||
public bool useLocalTransform;
|
|
||||||
|
|
||||||
[Tooltip("0 to disable.")] public float teleportDistance;
|
[Tooltip("0 to disable.")] public float teleportDistance;
|
||||||
[Tooltip("0 to disable.")] public float teleportAngle;
|
[Tooltip("0 to disable.")] public float teleportAngle;
|
||||||
|
|
@ -57,6 +55,7 @@ namespace VelNet
|
||||||
if (position) writer.Write(transform.position);
|
if (position) writer.Write(transform.position);
|
||||||
if (rotation) writer.Write(transform.rotation);
|
if (rotation) writer.Write(transform.rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scale) writer.Write(transform.localScale);
|
if (scale) writer.Write(transform.localScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,9 @@ namespace VelNet.Voice
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void StartMicrophone()
|
public void StartMicrophone()
|
||||||
{
|
{
|
||||||
|
#if !UNITY_WEBGL && !UNITY_EDITOR
|
||||||
StartMicrophone(Microphone.devices.FirstOrDefault());
|
StartMicrophone(Microphone.devices.FirstOrDefault());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -110,6 +112,7 @@ namespace VelNet.Voice
|
||||||
/// <param name="micDeviceName">The device name of the microphone to record with</param>
|
/// <param name="micDeviceName">The device name of the microphone to record with</param>
|
||||||
public void StartMicrophone(string micDeviceName)
|
public void StartMicrophone(string micDeviceName)
|
||||||
{
|
{
|
||||||
|
#if !UNITY_WEBGL && !UNITY_EDITOR
|
||||||
Debug.Log("Starting with microphone: " + micDeviceName);
|
Debug.Log("Starting with microphone: " + micDeviceName);
|
||||||
if (micDeviceName == null) return;
|
if (micDeviceName == null) return;
|
||||||
device = micDeviceName;
|
device = micDeviceName;
|
||||||
|
|
@ -121,6 +124,7 @@ namespace VelNet.Voice
|
||||||
Debug.Log("Frequency:" + clip.frequency);
|
Debug.Log("Frequency:" + clip.frequency);
|
||||||
tempData = new float[clip.samples * clip.channels];
|
tempData = new float[clip.samples * clip.channels];
|
||||||
Debug.Log("channels: " + clip.channels);
|
Debug.Log("channels: " + clip.channels);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnApplicationQuit()
|
private void OnApplicationQuit()
|
||||||
|
|
@ -149,8 +153,10 @@ namespace VelNet.Voice
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
#if !UNITY_WEBGL && !UNITY_EDITOR
|
||||||
if (clip != null)
|
if (clip != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
int micPosition = Microphone.GetPosition(device);
|
int micPosition = Microphone.GetPosition(device);
|
||||||
if (micPosition == lastPosition)
|
if (micPosition == lastPosition)
|
||||||
{
|
{
|
||||||
|
|
@ -238,6 +244,7 @@ namespace VelNet.Voice
|
||||||
|
|
||||||
sendQueue.Clear();
|
sendQueue.Clear();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public float[] DecodeOpusData(byte[] data, int count)
|
public float[] DecodeOpusData(byte[] data, int count)
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,10 @@ namespace VelNet
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
#if !UNITY_WEBGL && !UNITY_EDITOR
|
||||||
microphones.AddOptions(new List<string>(Microphone.devices));
|
microphones.AddOptions(new List<string>(Microphone.devices));
|
||||||
HandleMicrophoneSelection();
|
HandleMicrophoneSelection();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -208,9 +208,9 @@ GameObject:
|
||||||
- component: {fileID: 5845716565458182149}
|
- component: {fileID: 5845716565458182149}
|
||||||
- component: {fileID: 9102273340480352682}
|
- component: {fileID: 9102273340480352682}
|
||||||
- component: {fileID: 7564913803199044469}
|
- component: {fileID: 7564913803199044469}
|
||||||
- component: {fileID: 3931189231264197893}
|
|
||||||
- component: {fileID: 1833529818468634519}
|
- component: {fileID: 1833529818468634519}
|
||||||
- component: {fileID: 1058783918878763107}
|
- component: {fileID: 1058783918878763107}
|
||||||
|
- component: {fileID: 3933010506106872429}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: PlayerPrefab
|
m_Name: PlayerPrefab
|
||||||
m_TagString: TestSphere
|
m_TagString: TestSphere
|
||||||
|
|
@ -340,19 +340,6 @@ MonoBehaviour:
|
||||||
useLocalTransform: 0
|
useLocalTransform: 0
|
||||||
teleportDistance: 0
|
teleportDistance: 0
|
||||||
teleportAngle: 0
|
teleportAngle: 0
|
||||||
--- !u!114 &3931189231264197893
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 6139051692386484099}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 544bfd0908e09d141adb9828d99baa08, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
networkObject: {fileID: 9102273340480352682}
|
|
||||||
--- !u!114 &1833529818468634519
|
--- !u!114 &1833529818468634519
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
@ -466,6 +453,19 @@ AudioSource:
|
||||||
m_PreInfinity: 2
|
m_PreInfinity: 2
|
||||||
m_PostInfinity: 2
|
m_PostInfinity: 2
|
||||||
m_RotationOrder: 4
|
m_RotationOrder: 4
|
||||||
|
--- !u!114 &3933010506106872429
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6139051692386484099}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 1006f76dad9c183459e79084f8c67539, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
networkObject: {fileID: 9102273340480352682}
|
||||||
--- !u!1 &7360746642267561319
|
--- !u!1 &7360746642267561319
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,16 @@ namespace VelNet
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
#if !UNITY_WEBGL && !UNITY_EDITOR
|
||||||
microphones.AddOptions(Microphone.devices.ToList());
|
microphones.AddOptions(Microphone.devices.ToList());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleMicrophoneSelection()
|
public void HandleMicrophoneSelection()
|
||||||
{
|
{
|
||||||
|
#if !UNITY_WEBGL && !UNITY_EDITOR
|
||||||
velVoice.StartMicrophone(microphones.options[microphones.value].text);
|
velVoice.StartMicrophone(microphones.options[microphones.value].text);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue