Strip debug logging from the game, fix screen weirdness

This commit is contained in:
Michal Pikulski
2025-10-14 15:53:58 +02:00
parent 18be597424
commit e8180b21bf
65 changed files with 768 additions and 411 deletions

View File

@@ -4,6 +4,7 @@ using AppleHills.Core.Settings;
using Pooling;
using Utils;
using AppleHills.Core.Interfaces;
using Core;
namespace Minigames.DivingForPictures
{
@@ -84,7 +85,7 @@ namespace Minigames.DivingForPictures
_settings = GameManager.GetSettingsObject<IDivingMinigameSettings>();
if (_settings == null)
{
Debug.LogWarning("[FloatingObstacle] Could not retrieve settings, using default values");
Logging.Warning("[FloatingObstacle] Could not retrieve settings, using default values");
_baseMoveSpeed = moveSpeed; // Use the serialized value as fallback
}
else
@@ -95,7 +96,7 @@ namespace Minigames.DivingForPictures
// For variety, randomly assign a speed between min and max
_baseMoveSpeed = Random.Range(minSpeed, maxSpeed);
Debug.Log($"[FloatingObstacle] Initialized with normalized speed: {_baseMoveSpeed} (range: {minSpeed}-{maxSpeed})");
Logging.Debug($"[FloatingObstacle] Initialized with normalized speed: {_baseMoveSpeed} (range: {minSpeed}-{maxSpeed})");
}
// Calculate screen normalization factor
@@ -117,7 +118,7 @@ namespace Minigames.DivingForPictures
// Calculate normalization factor based on screen height
_screenNormalizationFactor = Screen.height / referenceHeight;
Debug.Log($"[FloatingObstacle] Screen normalization factor: {_screenNormalizationFactor} (Screen height: {Screen.height}, Reference: {referenceHeight})");
Logging.Debug($"[FloatingObstacle] Screen normalization factor: {_screenNormalizationFactor} (Screen height: {Screen.height}, Reference: {referenceHeight})");
}
private void OnEnable()
@@ -147,7 +148,7 @@ namespace Minigames.DivingForPictures
_isPaused = true;
StopObstacleCoroutines();
Debug.Log($"[FloatingObstacle] Paused obstacle: {name}");
Logging.Debug($"[FloatingObstacle] Paused obstacle: {name}");
}
/// <summary>
@@ -160,7 +161,7 @@ namespace Minigames.DivingForPictures
_isPaused = false;
StartObstacleCoroutines();
Debug.Log($"[FloatingObstacle] Resumed obstacle: {name}");
Logging.Debug($"[FloatingObstacle] Resumed obstacle: {name}");
}
/// <summary>
@@ -221,7 +222,7 @@ namespace Minigames.DivingForPictures
_movementCoroutine = StartCoroutine(MovementCoroutine());
}
Debug.Log($"[FloatingObstacle] {gameObject.name} velocity factor updated to {_velocityFactor:F2}, normalized speed: {moveSpeed:F2}");
Logging.Debug($"[FloatingObstacle] {gameObject.name} velocity factor updated to {_velocityFactor:F2}, normalized speed: {moveSpeed:F2}");
}
/// <summary>
@@ -229,7 +230,7 @@ namespace Minigames.DivingForPictures
/// </summary>
private IEnumerator MovementCoroutine()
{
Debug.Log($"[FloatingObstacle] Started movement coroutine with speed: {_baseMoveSpeed:F3}");
Logging.Debug($"[FloatingObstacle] Started movement coroutine with speed: {_baseMoveSpeed:F3}");
while (enabled && gameObject.activeInHierarchy)
{
@@ -273,7 +274,7 @@ namespace Minigames.DivingForPictures
if (_collider != null && _collider.enabled)
{
_collider.enabled = false;
Debug.Log($"[FloatingObstacle] Obstacle {gameObject.name} hit player - collider disabled");
Logging.Debug($"[FloatingObstacle] Obstacle {gameObject.name} hit player - collider disabled");
}
}
@@ -299,12 +300,12 @@ namespace Minigames.DivingForPictures
// Use a larger buffer to ensure obstacles are truly off-screen before returning to pool
if (transform.position.y > _screenTop + 5f)
{
Debug.Log($"[FloatingObstacle] {gameObject.name} off-screen at Y:{transform.position.y:F2}, screen top:{_screenTop:F2}");
Logging.Debug($"[FloatingObstacle] {gameObject.name} off-screen at Y:{transform.position.y:F2}, screen top:{_screenTop:F2}");
ReturnToPool();
}
else if (transform.position.y < _screenBottom - 5f) // Added check for bottom screen edge
{
Debug.Log($"[FloatingObstacle] {gameObject.name} below screen at Y:{transform.position.y:F2}, screen bottom:{_screenBottom:F2}");
Logging.Debug($"[FloatingObstacle] {gameObject.name} below screen at Y:{transform.position.y:F2}, screen bottom:{_screenBottom:F2}");
ReturnToPool();
}
}
@@ -328,14 +329,14 @@ namespace Minigames.DivingForPictures
ObstacleSpawner foundSpawner = FindFirstObjectByType<ObstacleSpawner>();
if (foundSpawner != null)
{
Debug.LogWarning($"[FloatingObstacle] Obstacle {gameObject.name} lost spawner reference, found replacement spawner");
Logging.Warning($"[FloatingObstacle] Obstacle {gameObject.name} lost spawner reference, found replacement spawner");
spawner = foundSpawner;
spawner.ReturnObstacleToPool(gameObject, prefabIndex);
}
else
{
// No spawner found - just deactivate the object instead of destroying it
Debug.LogWarning($"[FloatingObstacle] No spawner found for {gameObject.name}, deactivating safely");
Logging.Warning($"[FloatingObstacle] No spawner found for {gameObject.name}, deactivating safely");
gameObject.SetActive(false);
// Move to a safe location to avoid interference
@@ -368,7 +369,7 @@ namespace Minigames.DivingForPictures
_collider.enabled = true;
}
Debug.Log($"[FloatingObstacle] Obstacle {gameObject.name} spawned from pool");
Logging.Debug($"[FloatingObstacle] Obstacle {gameObject.name} spawned from pool");
// Note: Don't start coroutines here - OnEnable() will handle that when SetActive(true) is called
}
@@ -387,7 +388,7 @@ namespace Minigames.DivingForPictures
_collider.enabled = true;
}
Debug.Log($"[FloatingObstacle] Obstacle {gameObject.name} despawned to pool");
Logging.Debug($"[FloatingObstacle] Obstacle {gameObject.name} despawned to pool");
}
/// <summary>
@@ -427,7 +428,7 @@ namespace Minigames.DivingForPictures
// Reverse movement speed (already handled by ObstacleSpawner, but this ensures consistency)
moveSpeed *= -1;
Debug.Log($"[FloatingObstacle] {gameObject.name} started surfacing with speed: {moveSpeed}");
Logging.Debug($"[FloatingObstacle] {gameObject.name} started surfacing with speed: {moveSpeed}");
}
}
}

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using Core;
using UnityEngine;
using Pooling;
namespace Minigames.DivingForPictures
@@ -21,12 +22,12 @@ namespace Minigames.DivingForPictures
FloatingObstacle obstacleComponent = obstacle.GetComponent<FloatingObstacle>();
if (obstacleComponent != null)
{
Debug.Log($"[ObstaclePool] Returning obstacle {obstacle.name} to pool");
Logging.Debug($"[ObstaclePool] Returning obstacle {obstacle.name} to pool");
Return(obstacleComponent, prefabIndex);
}
else
{
Debug.LogWarning($"Attempted to return a GameObject without a FloatingObstacle component: {obstacle.name}");
Logging.Warning($"Attempted to return a GameObject without a FloatingObstacle component: {obstacle.name}");
Destroy(obstacle);
}
}
@@ -38,7 +39,7 @@ namespace Minigames.DivingForPictures
/// <returns>An obstacle instance ready to use</returns>
public GameObject GetObstacle(int prefabIndex)
{
Debug.Log($"[ObstaclePool] GetObstacle called for prefab index {prefabIndex}");
Logging.Debug($"[ObstaclePool] GetObstacle called for prefab index {prefabIndex}");
FloatingObstacle obstacleComponent = Get(prefabIndex);
if (obstacleComponent == null)
@@ -47,7 +48,7 @@ namespace Minigames.DivingForPictures
return null;
}
Debug.Log($"[ObstaclePool] Get() returned obstacle {obstacleComponent.name}, active state: {obstacleComponent.gameObject.activeInHierarchy}");
Logging.Debug($"[ObstaclePool] Get() returned obstacle {obstacleComponent.name}, active state: {obstacleComponent.gameObject.activeInHierarchy}");
return obstacleComponent.gameObject;
}
}

View File

@@ -5,6 +5,7 @@ using UnityEngine.Events;
using Pooling;
using AppleHills.Core.Settings;
using AppleHills.Core.Interfaces;
using Core;
namespace Minigames.DivingForPictures
{
@@ -119,7 +120,7 @@ namespace Minigames.DivingForPictures
StartMoveCoroutine();
StartDespawnCoroutine();
Debug.Log("[ObstacleSpawner] Initialized");
Logging.Debug("[ObstacleSpawner] Initialized");
}
/// <summary>
@@ -151,7 +152,7 @@ namespace Minigames.DivingForPictures
}
}
Debug.Log($"[ObstacleSpawner] Paused with {_activeObstacles.Count} active obstacles");
Logging.Debug($"[ObstacleSpawner] Paused with {_activeObstacles.Count} active obstacles");
}
/// <summary>
@@ -182,7 +183,7 @@ namespace Minigames.DivingForPictures
}
}
Debug.Log($"[ObstacleSpawner] Resumed with {_activeObstacles.Count} active obstacles");
Logging.Debug($"[ObstacleSpawner] Resumed with {_activeObstacles.Count} active obstacles");
}
/// <summary>
@@ -232,14 +233,14 @@ namespace Minigames.DivingForPictures
// Check if the prefab has a FloatingObstacle component
if (obstaclePrefabs[i].GetComponent<FloatingObstacle>() == null)
{
Debug.LogWarning($"Obstacle prefab {obstaclePrefabs[i].name} does not have a FloatingObstacle component. Adding one automatically.");
Logging.Warning($"Obstacle prefab {obstaclePrefabs[i].name} does not have a FloatingObstacle component. Adding one automatically.");
obstaclePrefabs[i].AddComponent<FloatingObstacle>();
}
// Ensure the prefab is on the correct layer (using configurable obstacleLayer)
if (obstaclePrefabs[i].layer != _devSettings.ObstacleLayer)
{
Debug.LogWarning($"Obstacle prefab {obstaclePrefabs[i].name} is not on the configured obstacle layer ({_devSettings.ObstacleLayer}). Setting layer automatically.");
Logging.Warning($"Obstacle prefab {obstaclePrefabs[i].name} is not on the configured obstacle layer ({_devSettings.ObstacleLayer}). Setting layer automatically.");
SetLayerRecursively(obstaclePrefabs[i], _devSettings.ObstacleLayer);
}
}
@@ -319,7 +320,7 @@ namespace Minigames.DivingForPictures
// Calculate spawn range based on 80% of screen width (40% on each side from center)
_spawnRangeX = (screenWidth * 0.8f) / 2f;
Debug.Log($"[ObstacleSpawner] Screen calculated - Width: {screenWidth:F2}, Bottom: {_screenBottom:F2}, Spawn Range X: ±{_spawnRangeX:F2}");
Logging.Debug($"[ObstacleSpawner] Screen calculated - Width: {screenWidth:F2}, Bottom: {_screenBottom:F2}, Spawn Range X: ±{_spawnRangeX:F2}");
}
/// <summary>
@@ -330,7 +331,7 @@ namespace Minigames.DivingForPictures
if (_spawnCoroutine == null)
{
_spawnCoroutine = StartCoroutine(SpawnObstaclesCoroutine());
Debug.Log("[ObstacleSpawner] Started spawning obstacles");
Logging.Debug("[ObstacleSpawner] Started spawning obstacles");
}
}
@@ -343,7 +344,7 @@ namespace Minigames.DivingForPictures
{
StopCoroutine(_spawnCoroutine);
_spawnCoroutine = null;
Debug.Log("[ObstacleSpawner] Stopped spawning obstacles");
Logging.Debug("[ObstacleSpawner] Stopped spawning obstacles");
}
}
@@ -375,15 +376,15 @@ namespace Minigames.DivingForPictures
// Don't spawn new obstacles when surfacing
if (_isSurfacing)
{
Debug.Log("[ObstacleSpawner] Skipping obstacle spawn - currently surfacing");
Logging.Debug("[ObstacleSpawner] Skipping obstacle spawn - currently surfacing");
return;
}
Debug.Log($"[ObstacleSpawner] TrySpawnObstacle called at {Time.time:F2}");
Logging.Debug($"[ObstacleSpawner] TrySpawnObstacle called at {Time.time:F2}");
if (obstaclePrefabs == null || obstaclePrefabs.Count == 0)
{
Debug.LogWarning("[ObstacleSpawner] No obstacle prefabs available for spawning!");
Logging.Warning("[ObstacleSpawner] No obstacle prefabs available for spawning!");
return;
}
@@ -397,20 +398,20 @@ namespace Minigames.DivingForPictures
if (IsValidSpawnPosition(spawnPosition))
{
Debug.Log($"[ObstacleSpawner] Found valid position at {spawnPosition} after {attempts + 1} attempts");
Logging.Debug($"[ObstacleSpawner] Found valid position at {spawnPosition} after {attempts + 1} attempts");
SpawnObstacleAt(spawnPosition);
foundValidPosition = true;
break;
}
else
{
Debug.Log($"[ObstacleSpawner] Position {spawnPosition} invalid (attempt {attempts + 1}/{_settings.ObstacleMaxSpawnAttempts})");
Logging.Debug($"[ObstacleSpawner] Position {spawnPosition} invalid (attempt {attempts + 1}/{_settings.ObstacleMaxSpawnAttempts})");
}
}
if (!foundValidPosition)
{
Debug.LogWarning($"[ObstacleSpawner] SPAWN MISSED: Could not find valid spawn position after {_settings.ObstacleMaxSpawnAttempts} attempts at {Time.time:F2}");
Logging.Warning($"[ObstacleSpawner] SPAWN MISSED: Could not find valid spawn position after {_settings.ObstacleMaxSpawnAttempts} attempts at {Time.time:F2}");
}
}
@@ -443,7 +444,7 @@ namespace Minigames.DivingForPictures
/// </summary>
private void SpawnObstacleAt(Vector3 position)
{
Debug.Log($"[ObstacleSpawner] SpawnObstacleAt called for position {position}");
Logging.Debug($"[ObstacleSpawner] SpawnObstacleAt called for position {position}");
// Select random prefab
int prefabIndex = Random.Range(0, obstaclePrefabs.Count);
@@ -460,7 +461,7 @@ namespace Minigames.DivingForPictures
// Spawn using pool or instantiate directly
if (_devSettings.ObstacleUseObjectPooling && _obstaclePool != null)
{
Debug.Log($"[ObstacleSpawner] Requesting obstacle from pool (prefab index {prefabIndex})");
Logging.Debug($"[ObstacleSpawner] Requesting obstacle from pool (prefab index {prefabIndex})");
obstacle = _obstaclePool.GetObstacle(prefabIndex);
if (obstacle == null)
{
@@ -473,12 +474,12 @@ namespace Minigames.DivingForPictures
obstacle.transform.rotation = prefab.transform.rotation;
obstacle.transform.SetParent(transform);
Debug.Log($"[ObstacleSpawner] Got obstacle {obstacle.name} from pool, active state: {obstacle.activeInHierarchy}");
Logging.Debug($"[ObstacleSpawner] Got obstacle {obstacle.name} from pool, active state: {obstacle.activeInHierarchy}");
// ENHANCED FORCE ACTIVATION - more robust approach
if (!obstacle.activeInHierarchy)
{
Debug.LogWarning($"[ObstacleSpawner] Pool returned inactive object {obstacle.name}, force activating!");
Logging.Warning($"[ObstacleSpawner] Pool returned inactive object {obstacle.name}, force activating!");
// Configure obstacle BEFORE activation
ConfigureObstacle(obstacle, prefabIndex);
@@ -500,7 +501,7 @@ namespace Minigames.DivingForPictures
}
}
Debug.Log($"[ObstacleSpawner] After force activation, {obstacle.name} active state: {obstacle.activeInHierarchy}");
Logging.Debug($"[ObstacleSpawner] After force activation, {obstacle.name} active state: {obstacle.activeInHierarchy}");
}
else
{
@@ -510,7 +511,7 @@ namespace Minigames.DivingForPictures
}
else
{
Debug.Log($"[ObstacleSpawner] Instantiating new obstacle (pooling disabled)");
Logging.Debug($"[ObstacleSpawner] Instantiating new obstacle (pooling disabled)");
obstacle = Instantiate(prefab, position, prefab.transform.rotation, transform);
// Configure the newly instantiated obstacle
@@ -521,16 +522,16 @@ namespace Minigames.DivingForPictures
_obstacleCounter++;
string oldName = obstacle.name;
obstacle.name = $"Obstacle{_obstacleCounter:D3}";
Debug.Log($"[ObstacleSpawner] Renamed obstacle from '{oldName}' to '{obstacle.name}', active state: {obstacle.activeInHierarchy}");
Logging.Debug($"[ObstacleSpawner] Renamed obstacle from '{oldName}' to '{obstacle.name}', active state: {obstacle.activeInHierarchy}");
// Track active obstacles
_activeObstacles.Add(obstacle);
// Invoke events
onObstacleSpawned?.Invoke(obstacle);
Debug.Log($"[ObstacleSpawner] After events, obstacle {obstacle.name} active state: {obstacle.activeInHierarchy}");
Logging.Debug($"[ObstacleSpawner] After events, obstacle {obstacle.name} active state: {obstacle.activeInHierarchy}");
Debug.Log($"[ObstacleSpawner] Successfully spawned obstacle {obstacle.name} at {position}. Active count: {_activeObstacles.Count}, Final active state: {obstacle.activeInHierarchy}");
Logging.Debug($"[ObstacleSpawner] Successfully spawned obstacle {obstacle.name} at {position}. Active count: {_activeObstacles.Count}, Final active state: {obstacle.activeInHierarchy}");
}
/// <summary>
@@ -567,7 +568,7 @@ namespace Minigames.DivingForPictures
{
if (obstacle == null) return;
Debug.Log($"[ObstacleSpawner] ReturnObstacleToPool called for {obstacle.name}, active state: {obstacle.activeInHierarchy}");
Logging.Debug($"[ObstacleSpawner] ReturnObstacleToPool called for {obstacle.name}, active state: {obstacle.activeInHierarchy}");
// Remove from active list
_activeObstacles.Remove(obstacle);
@@ -578,12 +579,12 @@ namespace Minigames.DivingForPictures
// Return to pool or destroy
if (_devSettings.ObstacleUseObjectPooling && _obstaclePool != null)
{
Debug.Log($"[ObstacleSpawner] Returning {obstacle.name} to pool");
Logging.Debug($"[ObstacleSpawner] Returning {obstacle.name} to pool");
_obstaclePool.ReturnObstacle(obstacle, prefabIndex);
}
else
{
Debug.Log($"[ObstacleSpawner] Destroying {obstacle.name} (pooling disabled)");
Logging.Debug($"[ObstacleSpawner] Destroying {obstacle.name} (pooling disabled)");
Destroy(obstacle);
}
}
@@ -595,7 +596,7 @@ namespace Minigames.DivingForPictures
{
// This method can no longer directly modify the settings
// Consider implementing a runtime settings override system if needed
Debug.LogWarning("[ObstacleSpawner] SetSpawnInterval no longer modifies settings directly. Settings are now centralized.");
Logging.Warning("[ObstacleSpawner] SetSpawnInterval no longer modifies settings directly. Settings are now centralized.");
}
/// <summary>
@@ -605,7 +606,7 @@ namespace Minigames.DivingForPictures
{
// This method can no longer directly modify the settings
// Consider implementing a runtime settings override system if needed
Debug.LogWarning("[ObstacleSpawner] SetSpeedRange no longer modifies settings directly. Settings are now centralized.");
Logging.Warning("[ObstacleSpawner] SetSpeedRange no longer modifies settings directly. Settings are now centralized.");
}
/// <summary>
@@ -636,7 +637,7 @@ namespace Minigames.DivingForPictures
}
}
Debug.Log($"[ObstacleSpawner] Velocity factor updated to {_velocityFactor:F2}, propagated to {_activeObstacles.Count} active obstacles");
Logging.Debug($"[ObstacleSpawner] Velocity factor updated to {_velocityFactor:F2}, propagated to {_activeObstacles.Count} active obstacles");
}
/// <summary>
@@ -662,7 +663,7 @@ namespace Minigames.DivingForPictures
}
}
Debug.Log($"[ObstacleSpawner] Started surfacing mode for {_activeObstacles.Count} active obstacles");
Logging.Debug($"[ObstacleSpawner] Started surfacing mode for {_activeObstacles.Count} active obstacles");
}
/// <summary>
@@ -675,7 +676,7 @@ namespace Minigames.DivingForPictures
/// </summary>
private IEnumerator SpawnObstacleRoutine()
{
Debug.Log("[ObstacleSpawner] Started spawning coroutine");
Logging.Debug("[ObstacleSpawner] Started spawning coroutine");
while (enabled && gameObject.activeInHierarchy && !_isPaused && !_isSurfacing)
{
@@ -694,7 +695,7 @@ namespace Minigames.DivingForPictures
// Clear coroutine reference when stopped
_spawnCoroutine = null;
Debug.Log("[ObstacleSpawner] Spawning coroutine ended");
Logging.Debug("[ObstacleSpawner] Spawning coroutine ended");
}
/// <summary>
@@ -704,7 +705,7 @@ namespace Minigames.DivingForPictures
/// </summary>
private IEnumerator MoveObstaclesRoutine()
{
Debug.Log("[ObstacleSpawner] Started obstacle monitoring coroutine");
Logging.Debug("[ObstacleSpawner] Started obstacle monitoring coroutine");
// This coroutine now just monitors obstacles, not moves them
while (enabled && gameObject.activeInHierarchy && !_isPaused)
@@ -718,7 +719,7 @@ namespace Minigames.DivingForPictures
// Clear coroutine reference when stopped
_moveCoroutine = null;
Debug.Log("[ObstacleSpawner] Obstacle monitoring coroutine ended");
Logging.Debug("[ObstacleSpawner] Obstacle monitoring coroutine ended");
}
/// <summary>
@@ -727,7 +728,7 @@ namespace Minigames.DivingForPictures
private IEnumerator DespawnObstaclesRoutine()
{
const float checkInterval = 0.5f; // Check every half second
Debug.Log("[ObstacleSpawner] Started despawn coroutine with interval: " + checkInterval);
Logging.Debug("[ObstacleSpawner] Started despawn coroutine with interval: " + checkInterval);
while (enabled && gameObject.activeInHierarchy && !_isPaused)
{
@@ -808,7 +809,7 @@ namespace Minigames.DivingForPictures
// Clear coroutine reference when stopped
_despawnCoroutine = null;
Debug.Log("[ObstacleSpawner] Despawn coroutine ended");
Logging.Debug("[ObstacleSpawner] Despawn coroutine ended");
}
#if UNITY_EDITOR