Wait for correct screen orientation
This commit is contained in:
@@ -1732,14 +1732,14 @@ MonoBehaviour:
|
||||
- m_Target: {fileID: 7928661763020144797}
|
||||
m_TargetAssemblyTypeName: UI.PauseMenu, AppleHillsScripts
|
||||
m_MethodName: HidePauseMenu
|
||||
m_Mode: 1
|
||||
m_Mode: 6
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_BoolArgument: 1
|
||||
m_CallState: 2
|
||||
--- !u!1 &5544888797992325527
|
||||
GameObject:
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -74,9 +74,38 @@ namespace Minigames.DivingForPictures
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
|
||||
// Find DivingGameManager and subscribe to its initialization event
|
||||
DivingGameManager gameManager = FindFirstObjectByType<DivingGameManager>();
|
||||
if (gameManager != null)
|
||||
{
|
||||
gameManager.OnGameInitialized += Initialize;
|
||||
|
||||
// If game is already initialized, initialize immediately
|
||||
if (gameManager.GetType().GetField("_isGameInitialized",
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Instance)?.GetValue(gameManager) is bool isInitialized && isInitialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[ObstacleSpawner] DivingGameManager not found. Initializing immediately.");
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the obstacle spawner when triggered by DivingGameManager
|
||||
/// </summary>
|
||||
private void Initialize()
|
||||
{
|
||||
CalculateScreenBounds();
|
||||
StartSpawning();
|
||||
Debug.Log("[ObstacleSpawner] Initialized");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
|
||||
@@ -21,6 +21,9 @@ namespace Minigames.DivingForPictures
|
||||
private float _tapImpulseStrength = 0f;
|
||||
private float _tapDirection = 0f;
|
||||
|
||||
// Initialization flag
|
||||
private bool _isInitialized = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_originY = transform.position.y;
|
||||
@@ -35,11 +38,53 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Register as default consumer for input
|
||||
InputManager.Instance?.SetDefaultConsumer(this);
|
||||
// Initialize target to current position
|
||||
_targetFingerX = transform.position.x;
|
||||
_isTouchActive = false;
|
||||
|
||||
// Find DivingGameManager and subscribe to its initialization event
|
||||
DivingGameManager gameManager = FindFirstObjectByType<DivingGameManager>();
|
||||
if (gameManager != null)
|
||||
{
|
||||
gameManager.OnGameInitialized += Initialize;
|
||||
|
||||
// If game is already initialized, initialize immediately
|
||||
if (gameManager.GetType().GetField("_isGameInitialized",
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Instance)?.GetValue(gameManager) is bool isInitialized && isInitialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[PlayerController] DivingGameManager not found. Initializing immediately.");
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the player controller when triggered by DivingGameManager
|
||||
/// </summary>
|
||||
private void Initialize()
|
||||
{
|
||||
if (_isInitialized) return;
|
||||
|
||||
// Register as default consumer for input
|
||||
InputManager.Instance?.SetDefaultConsumer(this);
|
||||
|
||||
_isInitialized = true;
|
||||
Debug.Log("[PlayerController] Initialized");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Unsubscribe from events to prevent memory leaks
|
||||
DivingGameManager gameManager = FindFirstObjectByType<DivingGameManager>();
|
||||
if (gameManager != null)
|
||||
{
|
||||
gameManager.OnGameInitialized -= Initialize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -107,13 +107,44 @@ namespace Minigames.DivingForPictures
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
|
||||
// Find DivingGameManager and subscribe to its initialization event
|
||||
DivingGameManager gameManager = FindFirstObjectByType<DivingGameManager>();
|
||||
if (gameManager != null)
|
||||
{
|
||||
gameManager.OnGameInitialized += Initialize;
|
||||
|
||||
// If game is already initialized, initialize immediately
|
||||
if (gameManager.GetType().GetField("_isGameInitialized",
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Instance)?.GetValue(gameManager) is bool isInitialized && isInitialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[TrenchTileSpawner] DivingGameManager not found. Initializing immediately.");
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the tile spawner when triggered by DivingGameManager
|
||||
/// </summary>
|
||||
private void Initialize()
|
||||
{
|
||||
CalculateScreenBounds();
|
||||
// Spawn initial tiles to fill the screen
|
||||
SpawnInitialTiles();
|
||||
|
||||
// Initialize velocity and start the velocity calculation coroutine
|
||||
_currentVelocity = _baseMoveSpeed * Time.fixedDeltaTime;
|
||||
StartCoroutine(VelocityCalculationRoutine());
|
||||
|
||||
Debug.Log("[TrenchTileSpawner] Initialized");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace UI
|
||||
SetPauseMenuByLevel(SceneManager.GetActiveScene().name);
|
||||
|
||||
// Initialize pause menu state
|
||||
HidePauseMenu();
|
||||
HidePauseMenu(false);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -45,7 +45,7 @@ namespace UI
|
||||
gameObject.SetActive(!isMainMenu);
|
||||
|
||||
if(!isMainMenu)
|
||||
HidePauseMenu(); // Ensure menu is hidden when switching to a game level
|
||||
HidePauseMenu(false); // Ensure menu is hidden when switching to a game level
|
||||
|
||||
Debug.Log($"[PauseMenu] Setting pause menu active: {!isMainMenu} for scene: {levelName}");
|
||||
}
|
||||
@@ -68,7 +68,7 @@ namespace UI
|
||||
/// <summary>
|
||||
/// Hides the pause menu and shows the pause button. Sets input mode to Game.
|
||||
/// </summary>
|
||||
public void HidePauseMenu()
|
||||
public void HidePauseMenu(bool resetInput = true)
|
||||
{
|
||||
if (pauseMenuPanel != null)
|
||||
pauseMenuPanel.SetActive(false);
|
||||
@@ -77,7 +77,8 @@ namespace UI
|
||||
pauseButton.SetActive(true);
|
||||
|
||||
// Change input mode back to Game when menu is closed
|
||||
InputManager.Instance.SetInputMode(InputMode.Game);
|
||||
if(resetInput)
|
||||
InputManager.Instance.SetInputMode(InputMode.Game);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System;
|
||||
using Input;
|
||||
using Settings;
|
||||
|
||||
namespace Utility
|
||||
@@ -66,6 +67,7 @@ namespace Utility
|
||||
orientationCorrect = IsOrientationCorrect();
|
||||
if (!orientationCorrect)
|
||||
{
|
||||
InputManager.Instance.SetInputMode(InputMode.UI);
|
||||
ShowPrompt();
|
||||
orientationCheckCoroutine = StartCoroutine(OrientationCheckRoutine());
|
||||
}
|
||||
@@ -77,7 +79,11 @@ namespace Utility
|
||||
return scene.name == "Main Menu" || scene.name == "MainMenu";
|
||||
}
|
||||
|
||||
private bool IsOrientationCorrect()
|
||||
/// <summary>
|
||||
/// Checks if the current device orientation matches the required orientation for the scene
|
||||
/// </summary>
|
||||
/// <returns>True if the orientation is correct, false otherwise</returns>
|
||||
public bool IsOrientationCorrect()
|
||||
{
|
||||
switch (requiredOrientation)
|
||||
{
|
||||
@@ -121,6 +127,8 @@ namespace Utility
|
||||
StopCoroutine(orientationCheckCoroutine);
|
||||
orientationCheckCoroutine = null;
|
||||
}
|
||||
|
||||
InputManager.Instance.SetInputMode(InputMode.Game);
|
||||
}
|
||||
|
||||
private void CleanupPromptAndCoroutine()
|
||||
|
||||
Reference in New Issue
Block a user