Merge branch 'main' into diving-outrocinematic

This commit is contained in:
2025-10-16 15:40:08 +02:00
14 changed files with 4063 additions and 3185 deletions

View File

@@ -545,167 +545,6 @@ namespace Minigames.DivingForPictures
_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>
/// Coroutine that handles increasing the movement speed over time
/// </summary>
@@ -1260,6 +1099,9 @@ namespace Minigames.DivingForPictures
if (_stopSpawning)
{
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
@@ -1296,6 +1138,9 @@ namespace Minigames.DivingForPictures
if (isLastTileLeaving)
{
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;
}
}
}