| | 1 | | using System.Collections.Generic; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public class SimpleOverlappingTracker |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// How much overlapping is allowed |
| | 8 | | /// </summary> |
| | 9 | | internal readonly float sqrTooCloseDistance; |
| 651 | 10 | | internal readonly List<Vector2> positions = new List<Vector2>(); |
| | 11 | |
|
| 1953 | 12 | | public SimpleOverlappingTracker(float tooCloseDistance) { sqrTooCloseDistance = tooCloseDistance * tooCloseDistance; |
| | 13 | |
|
| 20 | 14 | | public void Reset() { positions.Clear(); } |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Add a position to the cluster, returns true if the position is allowed |
| | 18 | | /// </summary> |
| | 19 | | /// <returns></returns> |
| | 20 | | public bool RegisterPosition (Vector2 position) |
| | 21 | | { |
| 16 | 22 | | for (var i = 0; i < positions.Count; i++) |
| | 23 | | { |
| 3 | 24 | | Vector2 toCompare = positions[i]; |
| 3 | 25 | | if ((toCompare - position).sqrMagnitude < sqrTooCloseDistance) |
| 1 | 26 | | return false; |
| | 27 | | } |
| 5 | 28 | | positions.Add(position); |
| 5 | 29 | | return true; |
| | 30 | | } |
| | 31 | | } |