private void OnDisable() { if (currActiveGridItem != null) { ExitGrid?.Invoke(); currActiveGridItem = null; } }
public void UpdateCurrActiveGridItem(Vector2 playerPos) { var gridPos = GetGridPosFromMousePos(playerPos); // If position isnt in grid if (!PosIsInGrid(gridPos)) { if (currActiveGridItem != null) { ExitGrid?.Invoke(); currActiveGridItem = null; } return; } // Get grid item currently hovering over var gridItem = gridItems[gridPos]; // If no currently active grid item has been set if (currActiveGridItem == null) { currActiveGridItem = new KeyValuePair <Vector2Int, EditorGridItem>(gridPos, gridItem); EnterGrid?.Invoke(gridPos); return; } // Get last last frame currently hovering grid item var lastGridPos = currActiveGridItem.GetValueOrDefault().Key; var lastGridItem = currActiveGridItem?.Value; if (lastGridPos == gridPos) { return; } // Grid item events EnterGrid?.Invoke(gridPos); currActiveGridItem = new KeyValuePair <Vector2Int, EditorGridItem>(gridPos, gridItem); }