| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | /// <summary> |
| | 5 | | /// Handle user position changes to let other handler or controller to react appropriately |
| | 6 | | /// </summary> |
| | 7 | | internal class UserPositionHandler : IDisposable |
| | 8 | | { |
| 0 | 9 | | public Vector2Int playerCoords { private set; get; } |
| | 10 | | public event Action<Vector2Int> OnPlayerCoordsChanged; |
| | 11 | |
|
| 11 | 12 | | public UserPositionHandler() |
| | 13 | | { |
| 11 | 14 | | playerCoords = CommonScriptableObjects.playerCoords.Get(); |
| 11 | 15 | | CommonScriptableObjects.playerCoords.OnChange += OnPlayerCoords; |
| 11 | 16 | | } |
| | 17 | |
|
| 26 | 18 | | public void Dispose() { CommonScriptableObjects.playerCoords.OnChange -= OnPlayerCoords; } |
| | 19 | |
|
| | 20 | | private void OnPlayerCoords(Vector2Int current, Vector2Int prev) |
| | 21 | | { |
| 2 | 22 | | playerCoords = current; |
| 2 | 23 | | OnPlayerCoordsChanged?.Invoke(playerCoords); |
| 0 | 24 | | } |
| | 25 | | } |