Wait for correct screen orientation
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Collections;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Playables;
|
||||
using AppleHills.Core.Settings;
|
||||
using Utility;
|
||||
|
||||
namespace Minigames.DivingForPictures
|
||||
{
|
||||
@@ -56,9 +57,15 @@ namespace Minigames.DivingForPictures
|
||||
private bool isGameOver = false;
|
||||
private bool _isSurfacing = false;
|
||||
|
||||
// Initialization state
|
||||
private bool _isGameInitialized = false;
|
||||
|
||||
// Used to track if we're currently surfacing
|
||||
public bool IsSurfacing => _isSurfacing;
|
||||
|
||||
// Event for game components to subscribe to
|
||||
public event Action OnGameInitialized;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Get settings from GameManager
|
||||
@@ -74,6 +81,42 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Subscribe to SceneOrientationEnforcer's event
|
||||
if (SceneOrientationEnforcer.Instance != null)
|
||||
{
|
||||
SceneOrientationEnforcer.Instance.OnOrientationCorrect += InitializeGame;
|
||||
|
||||
// If orientation is already correct, initialize right away
|
||||
// This prevents issues if the orientation was already correct before subscription
|
||||
if (SceneOrientationEnforcer.Instance.IsOrientationCorrect())
|
||||
{
|
||||
InitializeGame();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[DivingGameManager] SceneOrientationEnforcer not found. Initializing game immediately.");
|
||||
InitializeGame();
|
||||
}
|
||||
|
||||
// Subscribe to player damage events (this doesn't depend on initialization)
|
||||
PlayerCollisionBehavior.OnDamageTaken += OnPlayerDamageTaken;
|
||||
|
||||
// Validate rope references (this doesn't depend on initialization)
|
||||
ValidateRopeReferences();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the game components once the orientation is correct.
|
||||
/// This is called by SceneOrientationEnforcer when the device is properly oriented.
|
||||
/// </summary>
|
||||
public void InitializeGame()
|
||||
{
|
||||
// Prevent double initialization
|
||||
if (_isGameInitialized) return;
|
||||
|
||||
Debug.Log("[DivingGameManager] Initializing game");
|
||||
|
||||
// Subscribe to tile spawned event
|
||||
TrenchTileSpawner tileSpawner = FindFirstObjectByType<TrenchTileSpawner>();
|
||||
if (tileSpawner != null)
|
||||
@@ -85,17 +128,22 @@ namespace Minigames.DivingForPictures
|
||||
Debug.LogWarning("No TrenchTileSpawner found in scene. Monster spawning won't work.");
|
||||
}
|
||||
|
||||
// Subscribe to player damage events
|
||||
PlayerCollisionBehavior.OnDamageTaken += OnPlayerDamageTaken;
|
||||
// Mark as initialized
|
||||
_isGameInitialized = true;
|
||||
|
||||
// Validate rope references
|
||||
ValidateRopeReferences();
|
||||
// Notify all listeners that the game is initialized
|
||||
OnGameInitialized?.Invoke();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Unsubscribe from events when the manager is destroyed
|
||||
PlayerCollisionBehavior.OnDamageTaken -= OnPlayerDamageTaken;
|
||||
|
||||
if (SceneOrientationEnforcer.Instance != null)
|
||||
{
|
||||
SceneOrientationEnforcer.Instance.OnOrientationCorrect -= InitializeGame;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
||||
Reference in New Issue
Block a user