| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Helpers |
| | 6 | | { |
| | 7 | | public class CrashPayloadPositionTracker : IDisposable |
| | 8 | | { |
| 0 | 9 | | public List<Vector3> movePositions = new List<Vector3>(); |
| 0 | 10 | | public List<Vector3> teleportPositions = new List<Vector3>(); |
| | 11 | |
|
| | 12 | | private float lastPositionUpdate; |
| 0 | 13 | | private float positionUpdateInterval = 30.0f; |
| 0 | 14 | | private int maxQueueSize = 50; |
| | 15 | |
|
| 0 | 16 | | public CrashPayloadPositionTracker () |
| | 17 | | { |
| 0 | 18 | | CommonScriptableObjects.playerWorldPosition.OnChange += OnPositionChange; |
| 0 | 19 | | DataStore.i.player.lastTeleportPosition.OnChange += OnTeleport; |
| 0 | 20 | | } |
| | 21 | |
|
| | 22 | | public void Dispose() |
| | 23 | | { |
| 0 | 24 | | CommonScriptableObjects.playerWorldPosition.OnChange -= OnPositionChange; |
| 0 | 25 | | DataStore.i.player.lastTeleportPosition.OnChange -= OnTeleport; |
| 0 | 26 | | } |
| | 27 | |
|
| | 28 | | private void OnTeleport(Vector3 current, Vector3 previous) |
| | 29 | | { |
| 0 | 30 | | teleportPositions.Add( current ); |
| | 31 | |
|
| 0 | 32 | | if ( teleportPositions.Count > maxQueueSize ) |
| 0 | 33 | | teleportPositions.RemoveAt(0); |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | private void OnPositionChange(Vector3 current, Vector3 previous) |
| | 37 | | { |
| 0 | 38 | | if ( lastPositionUpdate + positionUpdateInterval > Time.time ) |
| | 39 | | { |
| 0 | 40 | | movePositions.Add( current ); |
| 0 | 41 | | lastPositionUpdate = Time.time; |
| | 42 | |
|
| 0 | 43 | | if ( movePositions.Count > maxQueueSize ) |
| 0 | 44 | | movePositions.RemoveAt(0); |
| | 45 | | } |
| 0 | 46 | | } |
| | 47 | | } |
| | 48 | | } |