Skip to content

Commit 2e1805a

Browse files
committed
Improved TrackedObject statistics and fixed NullException
1 parent 37c10bb commit 2e1805a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

MLAPI/MonoBehaviours/Core/TrackedObject.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ public class TrackedObject : MonoBehaviour
1919
private Vector3 savedPosition;
2020
private Quaternion savedRotation;
2121

22+
/// <summary>
23+
/// Gets the total amount of points stored in the component
24+
/// </summary>
25+
public int TotalPoints
26+
{
27+
get
28+
{
29+
return Framekeys.Count;
30+
}
31+
}
32+
33+
/// <summary>
34+
/// Gets the average amount of time between the points in miliseconds
35+
/// </summary>
36+
public float AvgTimeBetweenPointsMs
37+
{
38+
get
39+
{
40+
float totalSpan = Framekeys.Last.Value - Framekeys.First.Value;
41+
return (totalSpan / Framekeys.Count) * 1000f;
42+
}
43+
}
44+
2245
internal void ReverseTransform(float secondsAgo)
2346
{
2447
savedPosition = transform.position;
@@ -75,7 +98,7 @@ internal void AddFrame()
7598
float currentTime = Time.time;
7699
LinkedListNode<float> node = Framekeys.First;
77100
LinkedListNode<float> nextNode = node.Next;
78-
while (currentTime - node.Value >= NetworkingManager.singleton.NetworkConfig.SecondsHistory)
101+
while (node != null && currentTime - node.Value >= NetworkingManager.singleton.NetworkConfig.SecondsHistory)
79102
{
80103
nextNode = node.Next;
81104
FrameData.Remove(node.Value);

0 commit comments

Comments
 (0)