Removed TOTU 103
This commit is contained in:
		
							
								
								
									
										79
									
								
								Assets/Rendering/Scripts/BackButtonHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								Assets/Rendering/Scripts/BackButtonHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| using Assets.Resources.Scripts.Constants; | ||||
| using UnityEngine; | ||||
| using UnityEngine.SceneManagement; | ||||
|  | ||||
| public class BackButtonHandler : MonoBehaviour | ||||
| { | ||||
|     private bool isExitPromptVisible = false; | ||||
|     public GameObject exitPromptUI; // Una referencia a un panel de UI para confirmar la salida | ||||
|  | ||||
|     void Start() | ||||
|     { | ||||
|         if (exitPromptUI != null) | ||||
|         { | ||||
|             exitPromptUI.SetActive(false);  // Desactivar el panel al inicio | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Update is called once per frame | ||||
|     void Update() | ||||
|     { | ||||
|         // Detecta si el bot<6F>n "back" es presionado | ||||
|         if (Input.GetKeyDown(KeyCode.Escape)) | ||||
|         { | ||||
|             HandleBackButton(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // M<>todo que maneja la l<>gica del bot<6F>n "back" | ||||
|     void HandleBackButton() | ||||
|     { | ||||
|         string currentScene = SceneManager.GetActiveScene().name; | ||||
|  | ||||
|         if (currentScene == ScreenNames.AR) | ||||
|         { | ||||
|             // Si estamos en la escena AR, cargar la escena principal | ||||
|             SceneManager.LoadScene(ScreenNames.Main); | ||||
|         } | ||||
|         else if (currentScene == ScreenNames.Main) | ||||
|         { | ||||
|             // Si ya estamos en la escena principal, preguntar si quiere salir | ||||
|             if (isExitPromptVisible) | ||||
|             { | ||||
|                 // Si el cuadro de confirmaci<63>n ya est<73> visible, salir de la aplicaci<63>n | ||||
|                 Application.Quit(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 // Mostrar el cuadro de confirmaci<63>n para salir | ||||
|                 ShowExitPrompt(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Mostrar el cuadro de confirmaci<63>n para salir | ||||
|     private void ShowExitPrompt() | ||||
|     { | ||||
|         isExitPromptVisible = true; | ||||
|         if (exitPromptUI != null) | ||||
|         { | ||||
|             exitPromptUI.SetActive(true);  // Mostrar el panel de confirmaci<63>n | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Llamar a este m<>todo si el usuario confirma la salida | ||||
|     public void ConfirmExit() | ||||
|     { | ||||
|         Application.Quit(); | ||||
|     } | ||||
|  | ||||
|     // Llamar a este m<>todo si el usuario cancela la salida | ||||
|     public void CancelExit() | ||||
|     { | ||||
|         isExitPromptVisible = false; | ||||
|         if (exitPromptUI != null) | ||||
|         { | ||||
|             exitPromptUI.SetActive(false); // Ocultar el panel de confirmaci<63>n | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Ignacio Gómez Puga
					Ignacio Gómez Puga