Fix issue with event triggering multiple times at the end of the minigame
This commit is contained in:
@@ -545,167 +545,6 @@ namespace Minigames.DivingForPictures
|
|||||||
_movementCoroutine = null;
|
_movementCoroutine = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Coroutine that checks for tiles to destroy periodically
|
|
||||||
/// </summary>
|
|
||||||
private IEnumerator TileDestructionRoutine()
|
|
||||||
{
|
|
||||||
const float checkInterval = 0.5f; // Check every half second
|
|
||||||
Logging.Debug($"[TrenchTileSpawner] Started tile destruction coroutine with interval: {checkInterval}s");
|
|
||||||
|
|
||||||
while (enabled && gameObject.activeInHierarchy && !_isPaused)
|
|
||||||
{
|
|
||||||
// Check and handle tile destruction
|
|
||||||
if (_activeTiles.Count > 0)
|
|
||||||
{
|
|
||||||
GameObject topTile = _activeTiles[0];
|
|
||||||
if (topTile == null)
|
|
||||||
{
|
|
||||||
_activeTiles.RemoveAt(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float tileHeight = GetTileHeight(topTile);
|
|
||||||
|
|
||||||
bool shouldDestroy;
|
|
||||||
if (_isSurfacing)
|
|
||||||
{
|
|
||||||
// When surfacing, destroy tiles at the bottom
|
|
||||||
shouldDestroy = topTile.transform.position.y + tileHeight / 2 < _screenBottom - _settings.TileSpawnBuffer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// When descending, destroy tiles at the top
|
|
||||||
shouldDestroy = topTile.transform.position.y - tileHeight / 2 > _screenTop + _settings.TileSpawnBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldDestroy)
|
|
||||||
{
|
|
||||||
_activeTiles.RemoveAt(0);
|
|
||||||
onTileDestroyed?.Invoke(topTile);
|
|
||||||
|
|
||||||
if (_devSettings != null && _devSettings.TrenchTileUseObjectPooling && _tilePool != null)
|
|
||||||
{
|
|
||||||
// Find the prefab index for this tile
|
|
||||||
int prefabIndex = GetPrefabIndex(topTile);
|
|
||||||
if (prefabIndex >= 0)
|
|
||||||
{
|
|
||||||
_tilePool.ReturnTile(topTile, prefabIndex);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Destroy(topTile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Destroy(topTile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the next check interval
|
|
||||||
yield return new WaitForSeconds(checkInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear coroutine reference when stopped
|
|
||||||
_tileDestructionCoroutine = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Coroutine that checks if new tiles need to be spawned periodically
|
|
||||||
/// </summary>
|
|
||||||
private IEnumerator TileSpawningRoutine()
|
|
||||||
{
|
|
||||||
const float checkInterval = 0.2f; // Check every fifth of a second
|
|
||||||
Logging.Debug($"[TrenchTileSpawner] Started tile spawning coroutine with interval: {checkInterval}s");
|
|
||||||
|
|
||||||
while (enabled && gameObject.activeInHierarchy && !_isPaused && !_stopSpawning)
|
|
||||||
{
|
|
||||||
// Check if we need to spawn new tiles
|
|
||||||
if (_activeTiles.Count == 0)
|
|
||||||
{
|
|
||||||
// If we have no active tiles and spawning is stopped, trigger the event
|
|
||||||
if (_stopSpawning)
|
|
||||||
{
|
|
||||||
onLastTileLeft.Invoke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GameObject bottomTile = _activeTiles[^1];
|
|
||||||
if (bottomTile == null)
|
|
||||||
{
|
|
||||||
_activeTiles.RemoveAt(_activeTiles.Count - 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Get the tile height once to use in all calculations
|
|
||||||
float tileHeight = GetTileHeight(bottomTile);
|
|
||||||
|
|
||||||
// If we're in stop spawning mode, check if last tile is leaving
|
|
||||||
if (_stopSpawning)
|
|
||||||
{
|
|
||||||
// Check if this is the last tile, and if it's about to leave the screen
|
|
||||||
if (_activeTiles.Count == 1)
|
|
||||||
{
|
|
||||||
bool isLastTileLeaving;
|
|
||||||
|
|
||||||
if (_isSurfacing)
|
|
||||||
{
|
|
||||||
// When surfacing, check if bottom of tile is above top of screen
|
|
||||||
isLastTileLeaving = bottomTile.transform.position.y - tileHeight / 2 > _screenTop + _settings.TileSpawnBuffer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// When descending, check if top of tile is below bottom of screen
|
|
||||||
isLastTileLeaving = bottomTile.transform.position.y + tileHeight / 2 < _screenBottom - _settings.TileSpawnBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isLastTileLeaving)
|
|
||||||
{
|
|
||||||
onLastTileLeft.Invoke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Normal spawning mode
|
|
||||||
bool shouldSpawn;
|
|
||||||
float newY;
|
|
||||||
|
|
||||||
if (_isSurfacing)
|
|
||||||
{
|
|
||||||
// When surfacing, spawn new tiles at the top
|
|
||||||
float topEdge = bottomTile.transform.position.y + tileHeight / 2;
|
|
||||||
shouldSpawn = topEdge < _screenTop + _settings.TileSpawnBuffer;
|
|
||||||
newY = bottomTile.transform.position.y + tileHeight;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// When descending, spawn new tiles at the bottom
|
|
||||||
float bottomEdge = bottomTile.transform.position.y - tileHeight / 2;
|
|
||||||
shouldSpawn = bottomEdge > _screenBottom - _settings.TileSpawnBuffer;
|
|
||||||
newY = bottomTile.transform.position.y - tileHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldSpawn)
|
|
||||||
{
|
|
||||||
SpawnTileAtY(newY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the next check interval
|
|
||||||
yield return new WaitForSeconds(checkInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear coroutine reference when stopped
|
|
||||||
_tileSpawningCoroutine = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Coroutine that handles increasing the movement speed over time
|
/// Coroutine that handles increasing the movement speed over time
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1260,6 +1099,9 @@ namespace Minigames.DivingForPictures
|
|||||||
if (_stopSpawning)
|
if (_stopSpawning)
|
||||||
{
|
{
|
||||||
onLastTileLeft.Invoke();
|
onLastTileLeft.Invoke();
|
||||||
|
// Stop the coroutine since all tiles are gone and no new ones will spawn
|
||||||
|
Logging.Debug("[TrenchTileSpawner] No active tiles and spawning stopped - ending tile spawning coroutine");
|
||||||
|
yield break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1296,6 +1138,9 @@ namespace Minigames.DivingForPictures
|
|||||||
if (isLastTileLeaving)
|
if (isLastTileLeaving)
|
||||||
{
|
{
|
||||||
onLastTileLeft.Invoke();
|
onLastTileLeft.Invoke();
|
||||||
|
// Stop the coroutine since the last tile has left and no new ones will spawn
|
||||||
|
Logging.Debug("[TrenchTileSpawner] Last tile left screen and spawning stopped - ending tile spawning coroutine");
|
||||||
|
yield break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ MonoBehaviour:
|
|||||||
smoothMoveSpeed: 8
|
smoothMoveSpeed: 8
|
||||||
blockInputDuringBump: 0
|
blockInputDuringBump: 0
|
||||||
viewfinderPrefab: {fileID: 3191012273289593430, guid: 99666bddf27a652479c2a3e0007a94dc, type: 3}
|
viewfinderPrefab: {fileID: 3191012273289593430, guid: 99666bddf27a652479c2a3e0007a94dc, type: 3}
|
||||||
viewfinderShrinkDuration: 2
|
viewfinderShrinkDuration: 1
|
||||||
viewfinderMoveSpeed: 2
|
viewfinderMoveSpeed: 3
|
||||||
viewfinderShrinkCurve:
|
viewfinderShrinkCurve:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Curve:
|
m_Curve:
|
||||||
@@ -77,7 +77,7 @@ MonoBehaviour:
|
|||||||
m_PostInfinity: 2
|
m_PostInfinity: 2
|
||||||
m_RotationOrder: 4
|
m_RotationOrder: 4
|
||||||
photoInputMode: 1
|
photoInputMode: 1
|
||||||
paddingFactor: 2
|
paddingFactor: 1
|
||||||
minSizePercent: 0.15
|
minSizePercent: 0.15
|
||||||
maxSizePercent: 1
|
maxSizePercent: 1
|
||||||
viewfinderStartScale: 1
|
viewfinderStartScale: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user