Skip to content

Commit 7ae9041

Browse files
Fix setting hovered map tile on Standalone platform when a map tile is hovered while pathfinding ends processing
1 parent 211dc95 commit 7ae9041

13 files changed

Lines changed: 164 additions & 22 deletions

Assets/Project/Scenes/VisualiserScene.unity

Lines changed: 89 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Project/Scripts/Game Objects/Managers/Map Tile/HoveredMapTileManager.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ public class HoveredMapTileManager : MonoBehaviour, IPrimaryWindowElement, IMapE
77

88
private bool mapTilesCanBeHovered = true;
99
private MapTile mapTile;
10+
#if !UNITY_ANDROID
11+
private MapPathManager mapPathManager;
12+
private MapTileRaycaster mapTileRaycaster;
13+
#endif
1014
private VisualiserEventsManager visualiserEventsManager;
1115

1216
public void SetPrimaryWindowElementActive(bool active)
@@ -24,6 +28,10 @@ public void SetMapEditingElementActive(bool active)
2428

2529
private void Awake()
2630
{
31+
#if !UNITY_ANDROID
32+
mapPathManager = ObjectMethods.FindComponentOfType<MapPathManager>();
33+
mapTileRaycaster = ObjectMethods.FindComponentOfType<MapTileRaycaster>();
34+
#endif
2735
visualiserEventsManager = ObjectMethods.FindComponentOfType<VisualiserEventsManager>();
2836

2937
RegisterToListeners(true);
@@ -38,20 +46,44 @@ private void RegisterToListeners(bool register)
3846
{
3947
if(register)
4048
{
49+
#if !UNITY_ANDROID
50+
if(mapPathManager != null)
51+
{
52+
mapPathManager.pathfindingProcessStateWasChangedEvent.AddListener(OnPathfindingProcessStateWasChanged);
53+
}
54+
#endif
55+
4156
if(visualiserEventsManager != null)
4257
{
4358
visualiserEventsManager.eventWasSentEvent.AddListener(OnEventWasSent);
4459
}
4560
}
4661
else
4762
{
63+
#if !UNITY_ANDROID
64+
if(mapPathManager != null)
65+
{
66+
mapPathManager.pathfindingProcessStateWasChangedEvent.RemoveListener(OnPathfindingProcessStateWasChanged);
67+
}
68+
#endif
69+
4870
if(visualiserEventsManager != null)
4971
{
5072
visualiserEventsManager.eventWasSentEvent.RemoveListener(OnEventWasSent);
5173
}
5274
}
5375
}
5476

77+
#if !UNITY_ANDROID
78+
private void OnPathfindingProcessStateWasChanged(bool started)
79+
{
80+
if(!started && mapTileRaycaster != null && mapTileRaycaster.ComponentWasDetected(MouseMethods.GetMousePosition(), out var mapTile))
81+
{
82+
SetMapTile(mapTile);
83+
}
84+
}
85+
#endif
86+
5587
private void OnEventWasSent(VisualiserEvent visualiserEvent)
5688
{
5789
if(mapTilesCanBeHovered && visualiserEvent is MapTileBoolVisualiserEvent mapTileBoolVisualiserEvent && mapTileBoolVisualiserEvent.GetVisualiserEventType() == VisualiserEventType.MapTileHoverStateWasChanged)

Assets/Project/Scripts/Game Objects/Managers/Map Tile/SelectedMapTileMovementManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Linq;
22
using UnityEngine;
3-
using UnityEngine.InputSystem;
43

54
public class SelectedMapTileMovementManager : MonoBehaviour, IPrimaryWindowElement, IMapEditingElement
65
{
@@ -107,7 +106,7 @@ private void Update()
107106

108107
private Vector3 GetMousePositionToWorldPoint()
109108
{
110-
var position = mainSceneCamera != null ? (Vector2)mainSceneCamera.GetScreenToWorldPointFrom(Mouse.current.position.ReadValue()) : Vector2.zero;
109+
var position = mainSceneCamera != null ? (Vector2)mainSceneCamera.GetScreenToWorldPointFrom(MouseMethods.GetMousePosition()) : Vector2.zero;
111110

112111
return position.ToVector3();
113112
}

Assets/Project/Scripts/Game Objects/Managers/Platform Specific/Android/AndroidMapTileSelectionManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AndroidMapTileSelectionManager : MonoBehaviour, IPrimaryWindowEleme
1717
private bool panelUIHoverWasDetected;
1818
private Timer timer;
1919
private UserInputController userInputController;
20-
private AndroidMapTileRaycaster androidMapTileRaycaster;
20+
private MapTileStateControllerRaycaster mapTileStateControllerRaycaster;
2121
private PanelUIHoverDetectionManager panelUIHoverDetectionManager;
2222
private UnityEngine.InputSystem.EnhancedTouch.Touch touch;
2323
private MapTileStateController mapTileStateController;
@@ -43,7 +43,7 @@ private void Awake()
4343
#if UNITY_ANDROID
4444
timer = GetComponent<Timer>();
4545
userInputController = ObjectMethods.FindComponentOfType<UserInputController>();
46-
androidMapTileRaycaster = ObjectMethods.FindComponentOfType<AndroidMapTileRaycaster>();
46+
mapTileStateControllerRaycaster = ObjectMethods.FindComponentOfType<MapTileStateControllerRaycaster>();
4747
panelUIHoverDetectionManager = ObjectMethods.FindComponentOfType<PanelUIHoverDetectionManager>();
4848

4949
RemoveRaycasterFromMainCameraIfPossible();
@@ -105,15 +105,15 @@ private void RegisterToListeners(bool register)
105105

106106
private void OnTimerStarted()
107107
{
108-
if(androidMapTileRaycaster != null && (!androidMapTileRaycaster.MapTileWasTapped(touch.screenPosition, out var mapTileStateController) || !MapTileStateControllersAreEqual(mapTileStateController)))
108+
if(mapTileStateControllerRaycaster != null && (!mapTileStateControllerRaycaster.ComponentWasDetected(touch.screenPosition, out var mapTileStateController) || !MapTileStateControllersAreEqual(mapTileStateController)))
109109
{
110110
UnassignMapTileCompletelyIfNeeded();
111111
}
112112
}
113113

114114
private void OnTimerFinished()
115115
{
116-
if(androidMapTileRaycaster != null && androidMapTileRaycaster.MapTileWasTapped(touch.screenPosition, out var mapTileStateController))
116+
if(mapTileStateControllerRaycaster != null && mapTileStateControllerRaycaster.ComponentWasDetected(touch.screenPosition, out var mapTileStateController))
117117
{
118118
HandleTappedMapTile(mapTileStateController);
119119
}

Assets/Project/Scripts/Game Objects/Raycasters.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public class MapTileRaycaster : Raycaster<MapTile>
2+
{
3+
4+
}

Assets/Project/Scripts/Game Objects/Raycasters/MapTileRaycaster.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public class MapTileStateControllerRaycaster : Raycaster<MapTileStateController>
2+
{
3+
4+
}

Assets/Project/Scripts/Game Objects/Platform Specific/Android/AndroidMapTileRaycaster.cs.meta renamed to Assets/Project/Scripts/Game Objects/Raycasters/MapTileStateControllerRaycaster.cs.meta

File renamed without changes.

Assets/Project/Scripts/Game Objects/Platform Specific/Android/AndroidMapTileRaycaster.cs renamed to Assets/Project/Scripts/Game Objects/Raycasters/Raycaster.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
using UnityEngine;
22

3-
public class AndroidMapTileRaycaster : MonoBehaviour
3+
public abstract class Raycaster<T> : MonoBehaviour
44
{
55
[SerializeField] private LayerMask detectableGameObjects;
66

7-
#if UNITY_ANDROID
87
private MainSceneCamera mainSceneCamera;
98

10-
public bool MapTileWasTapped(Vector3 position, out MapTileStateController mapTileStateController)
9+
public bool ComponentWasDetected(Vector3 position, out T component)
1110
{
1211
var raycastHitCollider = GetRaycastHitCollider(position);
1312

14-
mapTileStateController = raycastHitCollider != null && raycastHitCollider.TryGetComponent<MapTileStateController>(out var foundMapTileStateController) ? foundMapTileStateController : null;
13+
component = raycastHitCollider != null && raycastHitCollider.TryGetComponent<T>(out var foundMapTileStateController) ? foundMapTileStateController : default;
1514

16-
return mapTileStateController != null;
15+
return component != null;
1716
}
18-
#endif
19-
17+
2018
private void Awake()
2119
{
22-
#if UNITY_ANDROID
2320
mainSceneCamera = ObjectMethods.FindComponentOfType<MainSceneCamera>();
24-
#else
25-
Destroy(gameObject);
26-
#endif
2721
}
2822

29-
#if UNITY_ANDROID
3023
private Collider2D GetRaycastHitCollider(Vector3 position)
3124
{
3225
if(mainSceneCamera == null)
@@ -39,5 +32,4 @@ private Collider2D GetRaycastHitCollider(Vector3 position)
3932

4033
return raycastHit.collider;
4134
}
42-
#endif
4335
}

0 commit comments

Comments
 (0)