Wait for correct screen orientation
This commit is contained in:
@@ -1732,14 +1732,14 @@ MonoBehaviour:
|
|||||||
- m_Target: {fileID: 7928661763020144797}
|
- m_Target: {fileID: 7928661763020144797}
|
||||||
m_TargetAssemblyTypeName: UI.PauseMenu, AppleHillsScripts
|
m_TargetAssemblyTypeName: UI.PauseMenu, AppleHillsScripts
|
||||||
m_MethodName: HidePauseMenu
|
m_MethodName: HidePauseMenu
|
||||||
m_Mode: 1
|
m_Mode: 6
|
||||||
m_Arguments:
|
m_Arguments:
|
||||||
m_ObjectArgument: {fileID: 0}
|
m_ObjectArgument: {fileID: 0}
|
||||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||||
m_IntArgument: 0
|
m_IntArgument: 0
|
||||||
m_FloatArgument: 0
|
m_FloatArgument: 0
|
||||||
m_StringArgument:
|
m_StringArgument:
|
||||||
m_BoolArgument: 0
|
m_BoolArgument: 1
|
||||||
m_CallState: 2
|
m_CallState: 2
|
||||||
--- !u!1 &5544888797992325527
|
--- !u!1 &5544888797992325527
|
||||||
GameObject:
|
GameObject:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Collections;
|
|||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using UnityEngine.Playables;
|
using UnityEngine.Playables;
|
||||||
using AppleHills.Core.Settings;
|
using AppleHills.Core.Settings;
|
||||||
|
using Utility;
|
||||||
|
|
||||||
namespace Minigames.DivingForPictures
|
namespace Minigames.DivingForPictures
|
||||||
{
|
{
|
||||||
@@ -56,9 +57,15 @@ namespace Minigames.DivingForPictures
|
|||||||
private bool isGameOver = false;
|
private bool isGameOver = false;
|
||||||
private bool _isSurfacing = false;
|
private bool _isSurfacing = false;
|
||||||
|
|
||||||
|
// Initialization state
|
||||||
|
private bool _isGameInitialized = false;
|
||||||
|
|
||||||
// Used to track if we're currently surfacing
|
// Used to track if we're currently surfacing
|
||||||
public bool IsSurfacing => _isSurfacing;
|
public bool IsSurfacing => _isSurfacing;
|
||||||
|
|
||||||
|
// Event for game components to subscribe to
|
||||||
|
public event Action OnGameInitialized;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
// Get settings from GameManager
|
// Get settings from GameManager
|
||||||
@@ -74,6 +81,42 @@ namespace Minigames.DivingForPictures
|
|||||||
|
|
||||||
private void Start()
|
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
|
// Subscribe to tile spawned event
|
||||||
TrenchTileSpawner tileSpawner = FindFirstObjectByType<TrenchTileSpawner>();
|
TrenchTileSpawner tileSpawner = FindFirstObjectByType<TrenchTileSpawner>();
|
||||||
if (tileSpawner != null)
|
if (tileSpawner != null)
|
||||||
@@ -85,17 +128,22 @@ namespace Minigames.DivingForPictures
|
|||||||
Debug.LogWarning("No TrenchTileSpawner found in scene. Monster spawning won't work.");
|
Debug.LogWarning("No TrenchTileSpawner found in scene. Monster spawning won't work.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe to player damage events
|
// Mark as initialized
|
||||||
PlayerCollisionBehavior.OnDamageTaken += OnPlayerDamageTaken;
|
_isGameInitialized = true;
|
||||||
|
|
||||||
// Validate rope references
|
// Notify all listeners that the game is initialized
|
||||||
ValidateRopeReferences();
|
OnGameInitialized?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
// Unsubscribe from events when the manager is destroyed
|
// Unsubscribe from events when the manager is destroyed
|
||||||
PlayerCollisionBehavior.OnDamageTaken -= OnPlayerDamageTaken;
|
PlayerCollisionBehavior.OnDamageTaken -= OnPlayerDamageTaken;
|
||||||
|
|
||||||
|
if (SceneOrientationEnforcer.Instance != null)
|
||||||
|
{
|
||||||
|
SceneOrientationEnforcer.Instance.OnOrientationCorrect -= InitializeGame;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
|||||||
@@ -74,9 +74,38 @@ namespace Minigames.DivingForPictures
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
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();
|
CalculateScreenBounds();
|
||||||
StartSpawning();
|
StartSpawning();
|
||||||
|
Debug.Log("[ObstacleSpawner] Initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ namespace Minigames.DivingForPictures
|
|||||||
private float _tapImpulseStrength = 0f;
|
private float _tapImpulseStrength = 0f;
|
||||||
private float _tapDirection = 0f;
|
private float _tapDirection = 0f;
|
||||||
|
|
||||||
|
// Initialization flag
|
||||||
|
private bool _isInitialized = false;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
_originY = transform.position.y;
|
_originY = transform.position.y;
|
||||||
@@ -35,11 +38,53 @@ namespace Minigames.DivingForPictures
|
|||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
// Register as default consumer for input
|
|
||||||
InputManager.Instance?.SetDefaultConsumer(this);
|
|
||||||
// Initialize target to current position
|
// Initialize target to current position
|
||||||
_targetFingerX = transform.position.x;
|
_targetFingerX = transform.position.x;
|
||||||
_isTouchActive = false;
|
_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>
|
/// <summary>
|
||||||
|
|||||||
@@ -107,13 +107,44 @@ namespace Minigames.DivingForPictures
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
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();
|
CalculateScreenBounds();
|
||||||
|
// Spawn initial tiles to fill the screen
|
||||||
SpawnInitialTiles();
|
SpawnInitialTiles();
|
||||||
|
|
||||||
// Initialize velocity and start the velocity calculation coroutine
|
// Initialize velocity and start the velocity calculation coroutine
|
||||||
_currentVelocity = _baseMoveSpeed * Time.fixedDeltaTime;
|
_currentVelocity = _baseMoveSpeed * Time.fixedDeltaTime;
|
||||||
StartCoroutine(VelocityCalculationRoutine());
|
StartCoroutine(VelocityCalculationRoutine());
|
||||||
|
|
||||||
|
Debug.Log("[TrenchTileSpawner] Initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace UI
|
|||||||
SetPauseMenuByLevel(SceneManager.GetActiveScene().name);
|
SetPauseMenuByLevel(SceneManager.GetActiveScene().name);
|
||||||
|
|
||||||
// Initialize pause menu state
|
// Initialize pause menu state
|
||||||
HidePauseMenu();
|
HidePauseMenu(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
@@ -45,7 +45,7 @@ namespace UI
|
|||||||
gameObject.SetActive(!isMainMenu);
|
gameObject.SetActive(!isMainMenu);
|
||||||
|
|
||||||
if(!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}");
|
Debug.Log($"[PauseMenu] Setting pause menu active: {!isMainMenu} for scene: {levelName}");
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ namespace UI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Hides the pause menu and shows the pause button. Sets input mode to Game.
|
/// Hides the pause menu and shows the pause button. Sets input mode to Game.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void HidePauseMenu()
|
public void HidePauseMenu(bool resetInput = true)
|
||||||
{
|
{
|
||||||
if (pauseMenuPanel != null)
|
if (pauseMenuPanel != null)
|
||||||
pauseMenuPanel.SetActive(false);
|
pauseMenuPanel.SetActive(false);
|
||||||
@@ -77,6 +77,7 @@ namespace UI
|
|||||||
pauseButton.SetActive(true);
|
pauseButton.SetActive(true);
|
||||||
|
|
||||||
// Change input mode back to Game when menu is closed
|
// Change input mode back to Game when menu is closed
|
||||||
|
if(resetInput)
|
||||||
InputManager.Instance.SetInputMode(InputMode.Game);
|
InputManager.Instance.SetInputMode(InputMode.Game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
using System;
|
using System;
|
||||||
|
using Input;
|
||||||
using Settings;
|
using Settings;
|
||||||
|
|
||||||
namespace Utility
|
namespace Utility
|
||||||
@@ -66,6 +67,7 @@ namespace Utility
|
|||||||
orientationCorrect = IsOrientationCorrect();
|
orientationCorrect = IsOrientationCorrect();
|
||||||
if (!orientationCorrect)
|
if (!orientationCorrect)
|
||||||
{
|
{
|
||||||
|
InputManager.Instance.SetInputMode(InputMode.UI);
|
||||||
ShowPrompt();
|
ShowPrompt();
|
||||||
orientationCheckCoroutine = StartCoroutine(OrientationCheckRoutine());
|
orientationCheckCoroutine = StartCoroutine(OrientationCheckRoutine());
|
||||||
}
|
}
|
||||||
@@ -77,7 +79,11 @@ namespace Utility
|
|||||||
return scene.name == "Main Menu" || scene.name == "MainMenu";
|
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)
|
switch (requiredOrientation)
|
||||||
{
|
{
|
||||||
@@ -121,6 +127,8 @@ namespace Utility
|
|||||||
StopCoroutine(orientationCheckCoroutine);
|
StopCoroutine(orientationCheckCoroutine);
|
||||||
orientationCheckCoroutine = null;
|
orientationCheckCoroutine = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InputManager.Instance.SetInputMode(InputMode.Game);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CleanupPromptAndCoroutine()
|
private void CleanupPromptAndCoroutine()
|
||||||
|
|||||||
Reference in New Issue
Block a user