mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
add visualization
This commit is contained in:
parent
1be238b095
commit
4146b0a65d
1 changed files with 42 additions and 0 deletions
|
@ -27,6 +27,12 @@ namespace SanAndreasUnity.Net
|
|||
|
||||
public bool useRigidBody;
|
||||
|
||||
public bool visualize;
|
||||
|
||||
public ushort maxNumVisualizations;
|
||||
|
||||
public float visualizationScale;
|
||||
|
||||
public static Parameters Default => new Parameters
|
||||
{
|
||||
useSmoothDeltaTime = true,
|
||||
|
@ -34,6 +40,9 @@ namespace SanAndreasUnity.Net
|
|||
constantVelocityMultiplier = 1f,
|
||||
lerpFactor = 30f,
|
||||
useRigidBody = true,
|
||||
visualize = false,
|
||||
maxNumVisualizations = 10,
|
||||
visualizationScale = 0.2f,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -72,6 +81,8 @@ namespace SanAndreasUnity.Net
|
|||
|
||||
private readonly NetworkBehaviour m_networkBehaviour;
|
||||
|
||||
private readonly Queue<GameObject> m_visualizationQueue = new Queue<GameObject>();
|
||||
|
||||
|
||||
|
||||
public TransformSyncer(Transform tr, Parameters parameters, NetworkBehaviour networkBehaviour)
|
||||
|
@ -119,6 +130,37 @@ namespace SanAndreasUnity.Net
|
|||
syncData.CalculatedAngularVelocityMagnitude = Quaternion.Angle(syncData.Rotation, m_currentSyncData.Rotation) / m_networkBehaviour.syncInterval;
|
||||
|
||||
m_nextSyncData = syncData;
|
||||
|
||||
this.AddToVisualization(syncData);
|
||||
}
|
||||
}
|
||||
|
||||
void AddToVisualization(SyncData syncData)
|
||||
{
|
||||
if (!m_parameters.visualize || m_parameters.maxNumVisualizations <= 0)
|
||||
{
|
||||
while (m_visualizationQueue.Count > 0)
|
||||
Object.Destroy(m_visualizationQueue.Dequeue());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
while (m_visualizationQueue.Count >= m_parameters.maxNumVisualizations)
|
||||
Object.Destroy(m_visualizationQueue.Dequeue());
|
||||
|
||||
var newGo = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
||||
newGo.transform.SetPositionAndRotation(syncData.Position, syncData.Rotation);
|
||||
newGo.transform.localScale = Vector3.one * m_parameters.visualizationScale;
|
||||
Object.DestroyImmediate(newGo.GetComponent<Collider>());
|
||||
|
||||
m_visualizationQueue.Enqueue(newGo);
|
||||
|
||||
int i = 0;
|
||||
foreach (var go in m_visualizationQueue)
|
||||
{
|
||||
go.name = $"{m_networkBehaviour.name} - sync visualization {i}";
|
||||
go.GetComponent<Renderer>().material.color = Color.Lerp(Color.white, Color.black, i / (float)m_visualizationQueue.Count);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue