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 | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/BackButtonHandler.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/BackButtonHandler.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 2ce274ab6a871954cb0f52ec039d4f32 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										8
									
								
								Assets/Rendering/Scripts/Constants.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assets/Rendering/Scripts/Constants.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: eeade5e792a186a41888c159d0cb1110 | ||||
| folderAsset: yes | ||||
| DefaultImporter: | ||||
|   externalObjects: {} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										9
									
								
								Assets/Rendering/Scripts/Constants/ScreenNames.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								Assets/Rendering/Scripts/Constants/ScreenNames.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| namespace Assets.Resources.Scripts.Constants | ||||
| { | ||||
|     public static class ScreenNames | ||||
|     { | ||||
|         public const string Main = "MainScreen"; | ||||
|  | ||||
|         public const string AR = "ARScreen"; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/Constants/ScreenNames.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/Constants/ScreenNames.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: efa64e266c18eaa47aefc59f9dd1a3f9 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										16
									
								
								Assets/Rendering/Scripts/DropdownMenu.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Assets/Rendering/Scripts/DropdownMenu.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| using System.Collections; | ||||
| using UnityEngine; | ||||
|  | ||||
| namespace Assets.Scripts | ||||
| { | ||||
|     public class DropdownMenu : MonoBehaviour | ||||
|     { | ||||
|  | ||||
|         public GameObject panel; | ||||
|  | ||||
|         public void ToggleMenu() | ||||
|         { | ||||
|             panel.SetActive(!panel.activeSelf); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/DropdownMenu.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/DropdownMenu.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: c60006937c555944697e0652023f3535 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										8
									
								
								Assets/Rendering/Scripts/Furniture.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assets/Rendering/Scripts/Furniture.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: b2d6bdbff63e9d541b72e1e566008ec8 | ||||
| folderAsset: yes | ||||
| DefaultImporter: | ||||
|   externalObjects: {} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										13
									
								
								Assets/Rendering/Scripts/Furniture/Furniture.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Assets/Rendering/Scripts/Furniture/Furniture.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| using JetBrains.Annotations; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.XR.ARFoundation; | ||||
| using UnityEngine.XR.ARSubsystems; | ||||
|  | ||||
| public class Furniture : MonoBehaviour | ||||
| { | ||||
|     public void PlaceFurniture([CanBeNull] ARTrackable aRTrackable) | ||||
|     { | ||||
|         transform.SetParent(aRTrackable != null ? aRTrackable.transform : null); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/Furniture.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/Furniture.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 17e788a765b8a8540a245deee922b393 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										19
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureButton.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureButton.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| using System.Collections; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| namespace Assets.Scripts.Furniture | ||||
| { | ||||
|     public class FurnitureButton : MonoBehaviour | ||||
|     { | ||||
|         public GameObject furniturePrefab; | ||||
|         private FurnitureManager _furnitureManager; | ||||
|  | ||||
|         private void Start() | ||||
|         { | ||||
|             _furnitureManager = FindFirstObjectByType<FurnitureManager>(); | ||||
|  | ||||
|             GetComponent<Button>().onClick.AddListener(() => _furnitureManager.SetSelectedFurniture(furniturePrefab)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureButton.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureButton.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 8c4072d6f1c55d34bb1bcdd573b0db96 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										90
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureDragger.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureDragger.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.XR.ARFoundation; | ||||
| using UnityEngine.XR.ARSubsystems; | ||||
|  | ||||
| namespace Assets.Scripts.Furniture | ||||
| { | ||||
|     public class FurnitureDragger : MonoBehaviour | ||||
|     { | ||||
|         private Camera _mainCamera; | ||||
|         private ARRaycastManager _arRaycastManager; | ||||
|  | ||||
|         private bool _isDragging; | ||||
|         private bool _isRotating; | ||||
|         private Vector2 _initialTouchPosition; | ||||
|         private float _initialRotation; | ||||
|  | ||||
|         private void Start() | ||||
|         { | ||||
|             _mainCamera = Camera.main; | ||||
|             _arRaycastManager = FindFirstObjectByType<ARRaycastManager>(); | ||||
|         } | ||||
|  | ||||
|         private void Update() | ||||
|         { | ||||
|             if (Input.touchCount == 1) | ||||
|             { | ||||
|                 HandleDrag(); | ||||
|             } | ||||
|             else if (Input.touchCount == 2) | ||||
|             { | ||||
|                 HandleRotate(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private void HandleRotate() | ||||
|         { | ||||
|             Touch touch = Input.GetTouch(0); | ||||
|  | ||||
|             if (touch.phase == TouchPhase.Began) | ||||
|             { | ||||
|                 Ray ray = _mainCamera.ScreenPointToRay(touch.position); | ||||
|                 if (Physics.Raycast(ray, out RaycastHit hit) && hit.transform == transform) | ||||
|                 { | ||||
|                     _isDragging = true; | ||||
|                 } | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Moved && _isDragging) | ||||
|             { | ||||
|                 List<ARRaycastHit> hits = new(); | ||||
|                 if (_arRaycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon)) | ||||
|                 { | ||||
|                     Pose hitPose = hits[0].pose; | ||||
|                     transform.position = hitPose.position; | ||||
|                 } | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { } | ||||
|             { | ||||
|                 _isDragging = false; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private void HandleDrag() | ||||
|         { | ||||
|             Touch touch1 = Input.GetTouch(0); | ||||
|             Touch touch2 = Input.GetTouch(1); | ||||
|  | ||||
|             if (touch1.phase == TouchPhase.Began || touch2.phase == TouchPhase.Began) | ||||
|             { | ||||
|                 // Registrar el ángulo inicial para la rotación | ||||
|                 Vector2 initialVector = touch2.position - touch1.position; | ||||
|                 _initialRotation = Mathf.Atan2(initialVector.y, initialVector.x) * Mathf.Rad2Deg; | ||||
|             } | ||||
|             else if (touch1.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Moved) | ||||
|             { | ||||
|                 // Calcular el ángulo actual | ||||
|                 Vector2 currentVector = touch2.position - touch1.position; | ||||
|                 float currentRotation = Mathf.Atan2(currentVector.y, currentVector.x) * Mathf.Rad2Deg; | ||||
|  | ||||
|                 // Calcular la diferencia de ángulo y aplicar la rotación | ||||
|                 float deltaRotation = currentRotation - _initialRotation; | ||||
|                 transform.Rotate(Vector3.up, deltaRotation, Space.World); | ||||
|  | ||||
|                 // Actualizar el ángulo inicial | ||||
|                 _initialRotation = currentRotation; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureDragger.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureDragger.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: f762d4bce59928241a92c04ffe468dfe | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										94
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureManager.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,94 @@ | ||||
| using Assets.Scripts.Furniture; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.XR.ARFoundation; | ||||
| using UnityEngine.XR.ARSubsystems; | ||||
|  | ||||
| public class FurnitureManager : MonoBehaviour | ||||
| { | ||||
|     [SerializeField] private ARRaycastManager arRaycastManager; // Para detectar superficies | ||||
|     [SerializeField] private List<GameObject> furniturePrefabs; // Lista de prefabs de muebles | ||||
|     [SerializeField] private GameObject furniturePreviewPrefab; // Prefab para previsualizaci<63>n | ||||
|  | ||||
|     private GameObject _currentPreview; | ||||
|     private GameObject _currentFurniturePrefab; | ||||
|     private Vector3 _detectedPosition = Vector3.zero; | ||||
|     private Quaternion _detectedRotation = Quaternion.identity; | ||||
|     private bool _canAddFurniture = false; | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         // Establece el primer mueble como predeterminado | ||||
|         if (furniturePrefabs.Count > 0) | ||||
|         { | ||||
|             SetSelectedFurniture(furniturePrefabs[0]); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void Update() | ||||
|     { | ||||
|         DetectPlaneAndUpdatePreview(); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// M<>todo para detectar planos y actualizar la posici<63>n de previsualizaci<63>n. | ||||
|     /// </summary> | ||||
|     private void DetectPlaneAndUpdatePreview() | ||||
|     { | ||||
|         if (_currentPreview == null) return; | ||||
|  | ||||
|         var hits = new List<ARRaycastHit>(); | ||||
|         var middleScreen = new Vector2(Screen.width / 2, Screen.height / 2); | ||||
|  | ||||
|         if (arRaycastManager.Raycast(middleScreen, hits, TrackableType.PlaneWithinPolygon)) | ||||
|         { | ||||
|             _detectedPosition = hits[0].pose.position; | ||||
|             _detectedRotation = hits[0].pose.rotation; | ||||
|  | ||||
|             _currentPreview.transform.SetPositionAndRotation(_detectedPosition, _detectedRotation); | ||||
|             _currentPreview.SetActive(true); | ||||
|  | ||||
|             _canAddFurniture = true; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             _currentPreview.SetActive(false); | ||||
|             _canAddFurniture = false; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// M<>todo para colocar un mueble en la posici<63>n detectada. | ||||
|     /// </summary> | ||||
|     public void PlaceFurniture() | ||||
|     { | ||||
|         if (!_canAddFurniture || _currentFurniturePrefab == null) return; | ||||
|  | ||||
|         var newFurniture = Instantiate(_currentFurniturePrefab); | ||||
|         newFurniture.transform.SetPositionAndRotation(_detectedPosition, _detectedRotation); | ||||
|  | ||||
|         // A<>adir funcionalidad de manipulaci<63>n (rotar, mover, etc.) | ||||
|         newFurniture.AddComponent<FurnitureDragger>(); | ||||
|  | ||||
|         Debug.Log("Mueble colocado en la posici<63>n detectada."); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Cambiar el prefab del mueble seleccionado. | ||||
|     /// </summary> | ||||
|     /// <param name="furniturePrefab">Prefab del mueble seleccionado.</param> | ||||
|     public void SetSelectedFurniture(GameObject furniturePrefab) | ||||
|     { | ||||
|         _currentFurniturePrefab = furniturePrefab; | ||||
|  | ||||
|         // Actualizar el preview | ||||
|         if (_currentPreview != null) | ||||
|         { | ||||
|             Destroy(_currentPreview); | ||||
|         } | ||||
|  | ||||
|         _currentPreview = Instantiate(furniturePreviewPrefab ?? furniturePrefab); | ||||
|         _currentPreview.SetActive(false); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureManager.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureManager.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 4754f676fdfa9f0418689553f7af213f | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										63
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureSpawner.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureSpawner.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,63 @@ | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.XR.ARFoundation; | ||||
| using UnityEngine.XR.ARSubsystems; | ||||
|  | ||||
| public class FurnitureSpawner : MonoBehaviour | ||||
| { | ||||
|     [SerializeField] private ARRaycastManager arRaycastManager; | ||||
|     [SerializeField] private GameObject furniturePrefab; | ||||
|  | ||||
|     private bool _canAddFurniture; | ||||
|     private GameObject _furniturePreview; | ||||
|     private Vector3 _detectedPosition = new(); | ||||
|     private Quaternion _detectedRotation = Quaternion.identity; | ||||
|     private ARTrackable _currentTrackable = null; | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         InputHandler.OnTap += SpawnFurniture; | ||||
|         _furniturePreview = Instantiate(furniturePrefab); | ||||
|         SetCanAddFurniture(true); | ||||
|     } | ||||
|  | ||||
|     private void SpawnFurniture() | ||||
|     { | ||||
|         if (!_canAddFurniture) return; | ||||
|  | ||||
|         var furniture = Instantiate(furniturePrefab); | ||||
|  | ||||
|         furniture.GetComponent<Furniture>().PlaceFurniture(_currentTrackable); | ||||
|         furniture.transform.SetPositionAndRotation(_detectedPosition, _detectedRotation); | ||||
|     } | ||||
|  | ||||
|     private void Update() | ||||
|     { | ||||
|         // Detect a position and rotation over the detected surface | ||||
|         GetRaycastHitTransform(); | ||||
|     } | ||||
|  | ||||
|     private void GetRaycastHitTransform() | ||||
|     { | ||||
|         var hits = new List<ARRaycastHit>(); | ||||
|         var middleScreen = new Vector2(Screen.width / 2, Screen.height / 2); | ||||
|         if (arRaycastManager.Raycast(middleScreen, hits, TrackableType.PlaneWithinPolygon)) | ||||
|         { | ||||
|             _detectedPosition = hits[0].pose.position; | ||||
|             _detectedRotation = hits[0].pose.rotation; | ||||
|             _furniturePreview.transform.SetPositionAndRotation(_detectedPosition, _detectedRotation); | ||||
|             _currentTrackable = hits[0].trackable; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void OnDestroy() | ||||
|     { | ||||
|         InputHandler.OnTap -= SpawnFurniture; | ||||
|     } | ||||
|  | ||||
|     private void SetCanAddFurniture(bool canAddFurniture) | ||||
|     { | ||||
|         _canAddFurniture = canAddFurniture; | ||||
|         _furniturePreview.SetActive(canAddFurniture); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureSpawner.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/Furniture/FurnitureSpawner.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: bc7cde5cab4e5c6409f75a3825da5fa5 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										8
									
								
								Assets/Rendering/Scripts/Input.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assets/Rendering/Scripts/Input.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: a7693a63861599743b8f69ecdce9bd68 | ||||
| folderAsset: yes | ||||
| DefaultImporter: | ||||
|   externalObjects: {} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										48
									
								
								Assets/Rendering/Scripts/Input/AnimationsUI.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								Assets/Rendering/Scripts/Input/AnimationsUI.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| using UnityEngine; | ||||
|  | ||||
| public class AnimationsUI : MonoBehaviour | ||||
| { | ||||
|     [SerializeField] private GameObject extraMenu; | ||||
|     private bool isMenuActive = false; | ||||
|  | ||||
|     void Start() | ||||
|     { | ||||
|         // Asegurarse de que el men<65> est<73> en la posici<63>n fuera de la pantalla al inicio | ||||
|         extraMenu.GetComponent<RectTransform>().anchoredPosition = new Vector2(extraMenu.GetComponent<RectTransform>().anchoredPosition.x, 550); | ||||
|         extraMenu.SetActive(false); // El men<65> empieza desactivado | ||||
|     } | ||||
|  | ||||
|     public void ToggleExtraMenu() | ||||
|     { | ||||
|         if (isMenuActive) | ||||
|         { | ||||
|             DeactivateExtraMenu(); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             ActivateExtraMenu(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void ActivateExtraMenu() | ||||
|     { | ||||
|         // Colocar el men<65> en la posici<63>n fuera de la vista antes de activarlo | ||||
|         extraMenu.GetComponent<RectTransform>().anchoredPosition = new Vector2(extraMenu.GetComponent<RectTransform>().anchoredPosition.x, 550); | ||||
|         extraMenu.SetActive(true);  // Activar el men<65> inmediatamente | ||||
|         LeanTween.moveY(extraMenu.GetComponent<RectTransform>(), -400, 0.5f) // Reducir tiempo de animaci<63>n | ||||
|                  .setEase(LeanTweenType.easeOutExpo) | ||||
|                  .setOnComplete(() => isMenuActive = true);  // Cambiar el estado del men<65> | ||||
|     } | ||||
|  | ||||
|     public void DeactivateExtraMenu() | ||||
|     { | ||||
|         // Animar el men<65> para ocultarlo y desactivarlo al terminar la animaci<63>n | ||||
|         LeanTween.moveY(extraMenu.GetComponent<RectTransform>(), 550, 0.5f) // Reducir tiempo de animaci<63>n | ||||
|                  .setEase(LeanTweenType.easeInExpo) | ||||
|                  .setOnComplete(() => | ||||
|                  { | ||||
|                      extraMenu.SetActive(false);  // Desactivar el men<65> despu<70>s de la animaci<63>n | ||||
|                      isMenuActive = false;  // Cambiar el estado del men<65> | ||||
|                  }); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/Input/AnimationsUI.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/Input/AnimationsUI.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: d34713073cfff8e449751aa3cdb33704 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										31
									
								
								Assets/Rendering/Scripts/Input/InputHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								Assets/Rendering/Scripts/Input/InputHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| using System; | ||||
| using UnityEngine; | ||||
| using UnityEngine.InputSystem; | ||||
|  | ||||
| public class InputHandler : MonoBehaviour | ||||
| { | ||||
|     public static event Action OnTap; | ||||
|     private UserInput _userInput; | ||||
|  | ||||
|     private void Awake() | ||||
|     { | ||||
|         _userInput = new UserInput(); | ||||
|         _userInput.Enable(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         _userInput.MobileTouch.Tap.performed += OnTapPerformed; | ||||
|     } | ||||
|  | ||||
|     private void OnTapPerformed(InputAction.CallbackContext context) | ||||
|     { | ||||
|         OnTap?.Invoke(); | ||||
|     } | ||||
|  | ||||
|     private void OnDestroy() | ||||
|     { | ||||
|         _userInput.MobileTouch.Tap.performed -= OnTapPerformed; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/Input/InputHandler.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/Input/InputHandler.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 1e43702aefc12384a940b0cc2439dcb3 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										183
									
								
								Assets/Rendering/Scripts/Input/UserInput.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										183
									
								
								Assets/Rendering/Scripts/Input/UserInput.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,183 @@ | ||||
| //------------------------------------------------------------------------------ | ||||
| // <auto-generated> | ||||
| //     This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator | ||||
| //     version 1.11.0 | ||||
| //     from Assets/Rendering/Scripts/Input/UserInput.inputactions | ||||
| // | ||||
| //     Changes to this file may cause incorrect behavior and will be lost if | ||||
| //     the code is regenerated. | ||||
| // </auto-generated> | ||||
| //------------------------------------------------------------------------------ | ||||
|  | ||||
| using System; | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine.InputSystem; | ||||
| using UnityEngine.InputSystem.Utilities; | ||||
|  | ||||
| public partial class @UserInput: IInputActionCollection2, IDisposable | ||||
| { | ||||
|     public InputActionAsset asset { get; } | ||||
|     public @UserInput() | ||||
|     { | ||||
|         asset = InputActionAsset.FromJson(@"{ | ||||
|     ""name"": ""UserInput"", | ||||
|     ""maps"": [ | ||||
|         { | ||||
|             ""name"": ""MobileTouch"", | ||||
|             ""id"": ""61b9d527-e568-4d9a-b29c-76c81e318c30"", | ||||
|             ""actions"": [ | ||||
|                 { | ||||
|                     ""name"": ""Tap"", | ||||
|                     ""type"": ""Button"", | ||||
|                     ""id"": ""cc2f4409-7610-4448-8159-a64fcf617dcc"", | ||||
|                     ""expectedControlType"": """", | ||||
|                     ""processors"": """", | ||||
|                     ""interactions"": """", | ||||
|                     ""initialStateCheck"": false | ||||
|                 } | ||||
|             ], | ||||
|             ""bindings"": [ | ||||
|                 { | ||||
|                     ""name"": """", | ||||
|                     ""id"": ""77adbad9-9a21-48ad-b3ed-9c05bb6b8080"", | ||||
|                     ""path"": ""<Touchscreen>/primaryTouch/tap"", | ||||
|                     ""interactions"": ""Tap"", | ||||
|                     ""processors"": """", | ||||
|                     ""groups"": """", | ||||
|                     ""action"": ""Tap"", | ||||
|                     ""isComposite"": false, | ||||
|                     ""isPartOfComposite"": false | ||||
|                 }, | ||||
|                 { | ||||
|                     ""name"": """", | ||||
|                     ""id"": ""d2bc1807-065d-4e50-bb15-4c59d514aee2"", | ||||
|                     ""path"": ""<Mouse>/leftButton"", | ||||
|                     ""interactions"": ""Tap"", | ||||
|                     ""processors"": """", | ||||
|                     ""groups"": """", | ||||
|                     ""action"": ""Tap"", | ||||
|                     ""isComposite"": false, | ||||
|                     ""isPartOfComposite"": false | ||||
|                 } | ||||
|             ] | ||||
|         } | ||||
|     ], | ||||
|     ""controlSchemes"": [] | ||||
| }"); | ||||
|         // MobileTouch | ||||
|         m_MobileTouch = asset.FindActionMap("MobileTouch", throwIfNotFound: true); | ||||
|         m_MobileTouch_Tap = m_MobileTouch.FindAction("Tap", throwIfNotFound: true); | ||||
|     } | ||||
|  | ||||
|     ~@UserInput() | ||||
|     { | ||||
|         UnityEngine.Debug.Assert(!m_MobileTouch.enabled, "This will cause a leak and performance issues, UserInput.MobileTouch.Disable() has not been called."); | ||||
|     } | ||||
|  | ||||
|     public void Dispose() | ||||
|     { | ||||
|         UnityEngine.Object.Destroy(asset); | ||||
|     } | ||||
|  | ||||
|     public InputBinding? bindingMask | ||||
|     { | ||||
|         get => asset.bindingMask; | ||||
|         set => asset.bindingMask = value; | ||||
|     } | ||||
|  | ||||
|     public ReadOnlyArray<InputDevice>? devices | ||||
|     { | ||||
|         get => asset.devices; | ||||
|         set => asset.devices = value; | ||||
|     } | ||||
|  | ||||
|     public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes; | ||||
|  | ||||
|     public bool Contains(InputAction action) | ||||
|     { | ||||
|         return asset.Contains(action); | ||||
|     } | ||||
|  | ||||
|     public IEnumerator<InputAction> GetEnumerator() | ||||
|     { | ||||
|         return asset.GetEnumerator(); | ||||
|     } | ||||
|  | ||||
|     IEnumerator IEnumerable.GetEnumerator() | ||||
|     { | ||||
|         return GetEnumerator(); | ||||
|     } | ||||
|  | ||||
|     public void Enable() | ||||
|     { | ||||
|         asset.Enable(); | ||||
|     } | ||||
|  | ||||
|     public void Disable() | ||||
|     { | ||||
|         asset.Disable(); | ||||
|     } | ||||
|  | ||||
|     public IEnumerable<InputBinding> bindings => asset.bindings; | ||||
|  | ||||
|     public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false) | ||||
|     { | ||||
|         return asset.FindAction(actionNameOrId, throwIfNotFound); | ||||
|     } | ||||
|  | ||||
|     public int FindBinding(InputBinding bindingMask, out InputAction action) | ||||
|     { | ||||
|         return asset.FindBinding(bindingMask, out action); | ||||
|     } | ||||
|  | ||||
|     // MobileTouch | ||||
|     private readonly InputActionMap m_MobileTouch; | ||||
|     private List<IMobileTouchActions> m_MobileTouchActionsCallbackInterfaces = new List<IMobileTouchActions>(); | ||||
|     private readonly InputAction m_MobileTouch_Tap; | ||||
|     public struct MobileTouchActions | ||||
|     { | ||||
|         private @UserInput m_Wrapper; | ||||
|         public MobileTouchActions(@UserInput wrapper) { m_Wrapper = wrapper; } | ||||
|         public InputAction @Tap => m_Wrapper.m_MobileTouch_Tap; | ||||
|         public InputActionMap Get() { return m_Wrapper.m_MobileTouch; } | ||||
|         public void Enable() { Get().Enable(); } | ||||
|         public void Disable() { Get().Disable(); } | ||||
|         public bool enabled => Get().enabled; | ||||
|         public static implicit operator InputActionMap(MobileTouchActions set) { return set.Get(); } | ||||
|         public void AddCallbacks(IMobileTouchActions instance) | ||||
|         { | ||||
|             if (instance == null || m_Wrapper.m_MobileTouchActionsCallbackInterfaces.Contains(instance)) return; | ||||
|             m_Wrapper.m_MobileTouchActionsCallbackInterfaces.Add(instance); | ||||
|             @Tap.started += instance.OnTap; | ||||
|             @Tap.performed += instance.OnTap; | ||||
|             @Tap.canceled += instance.OnTap; | ||||
|         } | ||||
|  | ||||
|         private void UnregisterCallbacks(IMobileTouchActions instance) | ||||
|         { | ||||
|             @Tap.started -= instance.OnTap; | ||||
|             @Tap.performed -= instance.OnTap; | ||||
|             @Tap.canceled -= instance.OnTap; | ||||
|         } | ||||
|  | ||||
|         public void RemoveCallbacks(IMobileTouchActions instance) | ||||
|         { | ||||
|             if (m_Wrapper.m_MobileTouchActionsCallbackInterfaces.Remove(instance)) | ||||
|                 UnregisterCallbacks(instance); | ||||
|         } | ||||
|  | ||||
|         public void SetCallbacks(IMobileTouchActions instance) | ||||
|         { | ||||
|             foreach (var item in m_Wrapper.m_MobileTouchActionsCallbackInterfaces) | ||||
|                 UnregisterCallbacks(item); | ||||
|             m_Wrapper.m_MobileTouchActionsCallbackInterfaces.Clear(); | ||||
|             AddCallbacks(instance); | ||||
|         } | ||||
|     } | ||||
|     public MobileTouchActions @MobileTouch => new MobileTouchActions(this); | ||||
|     public interface IMobileTouchActions | ||||
|     { | ||||
|         void OnTap(InputAction.CallbackContext context); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/Input/UserInput.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/Input/UserInput.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 6fdf824f953584842baff9a570fcfea8 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										45
									
								
								Assets/Rendering/Scripts/Input/UserInput.inputactions
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								Assets/Rendering/Scripts/Input/UserInput.inputactions
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| { | ||||
|     "name": "UserInput", | ||||
|     "maps": [ | ||||
|         { | ||||
|             "name": "MobileTouch", | ||||
|             "id": "61b9d527-e568-4d9a-b29c-76c81e318c30", | ||||
|             "actions": [ | ||||
|                 { | ||||
|                     "name": "Tap", | ||||
|                     "type": "Button", | ||||
|                     "id": "cc2f4409-7610-4448-8159-a64fcf617dcc", | ||||
|                     "expectedControlType": "", | ||||
|                     "processors": "", | ||||
|                     "interactions": "", | ||||
|                     "initialStateCheck": false | ||||
|                 } | ||||
|             ], | ||||
|             "bindings": [ | ||||
|                 { | ||||
|                     "name": "", | ||||
|                     "id": "77adbad9-9a21-48ad-b3ed-9c05bb6b8080", | ||||
|                     "path": "<Touchscreen>/primaryTouch/tap", | ||||
|                     "interactions": "Tap", | ||||
|                     "processors": "", | ||||
|                     "groups": "", | ||||
|                     "action": "Tap", | ||||
|                     "isComposite": false, | ||||
|                     "isPartOfComposite": false | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "", | ||||
|                     "id": "d2bc1807-065d-4e50-bb15-4c59d514aee2", | ||||
|                     "path": "<Mouse>/leftButton", | ||||
|                     "interactions": "Tap", | ||||
|                     "processors": "", | ||||
|                     "groups": "", | ||||
|                     "action": "Tap", | ||||
|                     "isComposite": false, | ||||
|                     "isPartOfComposite": false | ||||
|                 } | ||||
|             ] | ||||
|         } | ||||
|     ], | ||||
|     "controlSchemes": [] | ||||
| } | ||||
							
								
								
									
										14
									
								
								Assets/Rendering/Scripts/Input/UserInput.inputactions.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Assets/Rendering/Scripts/Input/UserInput.inputactions.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 116a31151feae794ab271c090458bf17 | ||||
| ScriptedImporter: | ||||
|   internalIDToNameTable: [] | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
|   script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} | ||||
|   generateWrapperCode: 1 | ||||
|   wrapperCodePath:  | ||||
|   wrapperClassName:  | ||||
|   wrapperCodeNamespace:  | ||||
							
								
								
									
										8
									
								
								Assets/Rendering/Scripts/New.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assets/Rendering/Scripts/New.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 9f73149bbc806c74486060c2a88d9572 | ||||
| folderAsset: yes | ||||
| DefaultImporter: | ||||
|   externalObjects: {} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										79
									
								
								Assets/Rendering/Scripts/New/DragAndDropManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								Assets/Rendering/Scripts/New/DragAndDropManager.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.EventSystems; | ||||
| using UnityEngine.XR.ARFoundation; | ||||
| using UnityEngine.XR.ARSubsystems; | ||||
|  | ||||
| public class DragAndDropManager : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler | ||||
| { | ||||
|     public GameObject prefabToInstance; | ||||
|  | ||||
|     private ARRaycastManager arRaycastManager; // Asignable din<69>micamente | ||||
|     private Camera arCamera; // Asignable din<69>micamente | ||||
|     private GameObject draggedObject; | ||||
|  | ||||
|     // M<>todo para asignar la c<>mara desde MeasuringSystem | ||||
|     public void SetCamera(Camera camera) | ||||
|     { | ||||
|         if (camera == null) | ||||
|         { | ||||
|             Debug.LogError("C<>mara proporcionada es nula."); | ||||
|             return; | ||||
|         } | ||||
|         arCamera = camera; | ||||
|         Debug.Log($"C<>mara asignada: {arCamera.name}"); | ||||
|     } | ||||
|  | ||||
|     // M<>todo para asignar el ARRaycastManager desde MeasuringSystem | ||||
|     public void SetARRaycastManager(ARRaycastManager raycastManager) | ||||
|     { | ||||
|         if (raycastManager == null) | ||||
|         { | ||||
|             Debug.LogError("ARRaycastManager proporcionado es nulo."); | ||||
|             return; | ||||
|         } | ||||
|         arRaycastManager = raycastManager; | ||||
|         Debug.Log($"ARRaycastManager asignado: {arRaycastManager.name}"); | ||||
|     } | ||||
|  | ||||
|     public void OnBeginDrag(PointerEventData eventData) | ||||
|     { | ||||
|         if (prefabToInstance != null) | ||||
|         { | ||||
|             draggedObject = Instantiate(prefabToInstance); | ||||
|             draggedObject.SetActive(false); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void OnDrag(PointerEventData eventData) | ||||
|     { | ||||
|         if (draggedObject != null) | ||||
|         { | ||||
|             if (arRaycastManager == null || arCamera == null) | ||||
|             { | ||||
|                 Debug.LogWarning("ARRaycastManager o c<>mara no asignados. No se puede realizar el raycast."); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             List<ARRaycastHit> hits = new List<ARRaycastHit>(); | ||||
|             if (arRaycastManager.Raycast(eventData.position, hits, TrackableType.Planes)) | ||||
|             { | ||||
|                 var hitPose = hits[0].pose; | ||||
|  | ||||
|                 // Colocar el objeto en la posici<63>n AR detectada | ||||
|                 draggedObject.transform.position = hitPose.position; | ||||
|                 draggedObject.transform.rotation = hitPose.rotation; | ||||
|                 draggedObject.SetActive(true); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void OnEndDrag(PointerEventData eventData) | ||||
|     { | ||||
|         if (draggedObject != null) | ||||
|         { | ||||
|             draggedObject = null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/New/DragAndDropManager.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/New/DragAndDropManager.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 6bcac7e483a825d48bb0e327d618f0ce | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										215
									
								
								Assets/Rendering/Scripts/New/ObjectSelector.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										215
									
								
								Assets/Rendering/Scripts/New/ObjectSelector.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,215 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.XR.ARFoundation; | ||||
| using UnityEngine.XR.ARSubsystems; | ||||
|  | ||||
| public class ObjectSelector : MonoBehaviour | ||||
| { | ||||
|     public LayerMask interactableLayer; | ||||
|  | ||||
|     private ARRaycastManager arRaycastManager; // Asignable din<69>micamente | ||||
|     private Camera arCamera; // Asignable din<69>micamente | ||||
|     private GameObject selectedObject; | ||||
|  | ||||
|     private readonly float longTapTreshold = 1f; | ||||
|     private readonly float doubleTapMaxDelay = 0.5f; | ||||
|     private float tapTimer = 0f; | ||||
|     private float lastTapTime = 0f; | ||||
|     private bool isRelocating = false; | ||||
|  | ||||
|     // M<>todo para asignar la c<>mara desde MeasuringSystem | ||||
|     public void SetCamera(Camera camera) | ||||
|     { | ||||
|         arCamera = camera; | ||||
|         Debug.Log($"C<>mara asignada: {arCamera.name}"); | ||||
|     } | ||||
|  | ||||
|     // M<>todo para asignar el ARRaycastManager desde MeasuringSystem | ||||
|     public void SetARRaycastManager(ARRaycastManager raycastManager) | ||||
|     { | ||||
|         arRaycastManager = raycastManager; | ||||
|         Debug.Log($"ARRaycastManager asignado: {arRaycastManager.name}"); | ||||
|         FindObjectOfType<DebugLoggerUI>().AddMessage($"ARRaycastManager asignado: {arRaycastManager.name}"); | ||||
|     } | ||||
|  | ||||
|     private void Update() | ||||
|     { | ||||
|         if (arCamera == null || arRaycastManager == null) | ||||
|         { | ||||
|             Debug.LogWarning("La c<>mara o el ARRaycastManager no han sido asignados."); | ||||
|             FindObjectOfType<DebugLoggerUI>().AddMessage("La c<>mara o el ARRaycastManager no han sido asignados."); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         HandleTouchInput(); | ||||
|         HandleRotation(); | ||||
|         UpdateOutline(); | ||||
|     } | ||||
|  | ||||
|     private void HandleTouchInput() | ||||
|     { | ||||
|         if (Input.touchCount == 1) | ||||
|         { | ||||
|             Touch touch = Input.GetTouch(0); | ||||
|  | ||||
|             if (touch.phase == TouchPhase.Began) | ||||
|             { | ||||
|                 Ray ray = arCamera.ScreenPointToRay(touch.position); | ||||
|                 if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, interactableLayer)) | ||||
|                 { | ||||
|                     if (selectedObject == hit.collider.gameObject) | ||||
|                     { | ||||
|                         if (Time.time - lastTapTime <= doubleTapMaxDelay) | ||||
|                         { | ||||
|                             DeleteObject(); | ||||
|                             lastTapTime = 0f; | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             lastTapTime = Time.time; | ||||
|                             StartCoroutine(CheckLongTap()); | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         SelectObject(hit.collider.gameObject); | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     DeselectObject(); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if (touch.phase == TouchPhase.Moved && isRelocating) | ||||
|             { | ||||
|                 RelocateObject(touch.position); | ||||
|             } | ||||
|  | ||||
|             if (touch.phase == TouchPhase.Ended) | ||||
|             { | ||||
|                 isRelocating = false; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private IEnumerator CheckLongTap() | ||||
|     { | ||||
|         tapTimer = 0f; | ||||
|         while (tapTimer < longTapTreshold) | ||||
|         { | ||||
|             if (Input.touchCount == 0 || Input.GetTouch(0).phase == TouchPhase.Ended) | ||||
|             { | ||||
|                 yield break; | ||||
|             } | ||||
|  | ||||
|             tapTimer += Time.deltaTime; | ||||
|             yield return null; | ||||
|         } | ||||
|  | ||||
|         isRelocating = true; | ||||
|     } | ||||
|  | ||||
|     private void RelocateObject(Vector2 screenPosition) | ||||
|     { | ||||
|         if (selectedObject != null) | ||||
|         { | ||||
|             List<ARRaycastHit> hits = new(); | ||||
|             if (arRaycastManager.Raycast(screenPosition, hits, TrackableType.Planes)) | ||||
|             { | ||||
|                 Pose hitPose = hits[0].pose; | ||||
|  | ||||
|                 selectedObject.transform.SetPositionAndRotation(Vector3.Lerp( | ||||
|                     selectedObject.transform.position, | ||||
|                     hitPose.position, | ||||
|                     Time.deltaTime * 10f | ||||
|                 ), Quaternion.Lerp( | ||||
|                     selectedObject.transform.rotation, | ||||
|                     selectedObject.transform.rotation, | ||||
|                     Time.deltaTime * 10f | ||||
|                 )); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void HandleRotation() | ||||
|     { | ||||
|         if (selectedObject != null && Input.touchCount == 1) | ||||
|         { | ||||
|             Touch touch = Input.GetTouch(0); | ||||
|  | ||||
|             if (touch.phase == TouchPhase.Moved) | ||||
|             { | ||||
|                 Vector2 touchDelta = touch.deltaPosition; | ||||
|                 float rotationAmount = touchDelta.x * 0.1f; | ||||
|  | ||||
|                 selectedObject.transform.Rotate(0, -rotationAmount, 0, Space.World); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void SelectObject(GameObject gameObject) | ||||
|     { | ||||
|         if (selectedObject != null) | ||||
|         { | ||||
|             DeselectObject(); | ||||
|         } | ||||
|  | ||||
|         selectedObject = gameObject; | ||||
|  | ||||
|         if (selectedObject != null) | ||||
|         { | ||||
|             EnableOutline(selectedObject); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void DeselectObject() | ||||
|     { | ||||
|         if (selectedObject != null) | ||||
|         { | ||||
|             DisableOutline(selectedObject); | ||||
|         } | ||||
|  | ||||
|         selectedObject = null; | ||||
|     } | ||||
|  | ||||
|     private void DeleteObject() | ||||
|     { | ||||
|         if (selectedObject != null) | ||||
|         { | ||||
|             Destroy(selectedObject); | ||||
|             selectedObject = null; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void EnableOutline(GameObject obj) | ||||
|     { | ||||
|         if (obj.TryGetComponent<Outline>(out var outline)) | ||||
|         { | ||||
|             outline.enabled = true; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             var newOutline = obj.AddComponent<Outline>(); | ||||
|             newOutline.OutlineColor = Color.cyan; | ||||
|             newOutline.OutlineWidth = 10f; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void DisableOutline(GameObject obj) | ||||
|     { | ||||
|         if (obj.TryGetComponent<Outline>(out var outline)) | ||||
|         { | ||||
|             outline.enabled = false; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void UpdateOutline() | ||||
|     { | ||||
|         if (selectedObject != null) | ||||
|         { | ||||
|             EnableOutline(selectedObject); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										12
									
								
								Assets/Rendering/Scripts/New/ObjectSelector.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Assets/Rendering/Scripts/New/ObjectSelector.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: ec9fc900a2729c041a9c5a00765afc67 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: | ||||
|   - selectionIndicatorPrefab: {instanceID: 0} | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										88
									
								
								Assets/Rendering/Scripts/RotateAndMoveObject.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								Assets/Rendering/Scripts/RotateAndMoveObject.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| using UnityEngine; | ||||
|  | ||||
| public class RotateAndMoveObjectAR : MonoBehaviour | ||||
| { | ||||
|     public GameObject furniture; | ||||
|     public Camera arCamera; | ||||
|     public float rotationSpeed = 100f; | ||||
|     public float moveSpeed = 0.01f; | ||||
|  | ||||
|     private bool isRotating; | ||||
|     private bool isMoving; | ||||
|     private Vector2 lastTouchPosition; | ||||
|  | ||||
|     // Update is called once per frame | ||||
|     void Update() | ||||
|     { | ||||
|         HandleRotation(); | ||||
|         HandleMovement(); | ||||
|     } | ||||
|  | ||||
|     void HandleRotation() | ||||
|     { | ||||
|         // Comprobar si hay un segundo dedo en la pantalla (para rotaci<63>n) | ||||
|         if (Input.touchCount == 1) | ||||
|         { | ||||
|             Touch touch = Input.GetTouch(0); | ||||
|  | ||||
|             if (touch.phase == TouchPhase.Began) | ||||
|             { | ||||
|                 lastTouchPosition = touch.position; | ||||
|                 isRotating = true; | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Moved && isRotating) | ||||
|             { | ||||
|                 Vector2 touchDelta = touch.position - lastTouchPosition; | ||||
|                 float rotationAmount = touchDelta.x * rotationSpeed * Time.deltaTime; | ||||
|  | ||||
|                 // Rotar el objeto sobre el eje Y | ||||
|                 furniture.transform.Rotate(0, -rotationAmount, 0); | ||||
|  | ||||
|                 lastTouchPosition = touch.position; | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) | ||||
|             { | ||||
|                 isRotating = false; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     void HandleMovement() | ||||
|     { | ||||
|         // Comprobar si hay un toque en la pantalla para mover el objeto | ||||
|         if (Input.touchCount == 1) | ||||
|         { | ||||
|             Touch touch = Input.GetTouch(0); | ||||
|  | ||||
|             if (touch.phase == TouchPhase.Began) | ||||
|             { | ||||
|                 Ray ray = arCamera.ScreenPointToRay(touch.position); | ||||
|                 if (Physics.Raycast(ray, out RaycastHit hit)) | ||||
|                 { | ||||
|                     if (hit.collider.gameObject == furniture) | ||||
|                     { | ||||
|                         isMoving = true; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Moved && isMoving) | ||||
|             { | ||||
|                 // Calcular la nueva posici<63>n en el mundo | ||||
|                 Ray ray = arCamera.ScreenPointToRay(touch.position); | ||||
|                 if (Physics.Raycast(ray, out RaycastHit hit)) | ||||
|                 { | ||||
|                     // Mueve el mueble al punto donde toca el rayo | ||||
|                     furniture.transform.position = Vector3.Lerp( | ||||
|                         furniture.transform.position, | ||||
|                         hit.point, | ||||
|                         moveSpeed | ||||
|                     ); | ||||
|                 } | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) | ||||
|             { | ||||
|                 isMoving = false; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/RotateAndMoveObject.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/RotateAndMoveObject.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 19f18e429efebeb419ca31e26c506bb7 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										49
									
								
								Assets/Rendering/Scripts/ScalateAndRotateObjectAR.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								Assets/Rendering/Scripts/ScalateAndRotateObjectAR.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| using UnityEngine; | ||||
|  | ||||
| public class ScalateAndRotateObjectAR : MonoBehaviour | ||||
| { | ||||
|     public GameObject furniture; | ||||
|     public Camera arCamera; | ||||
|     public float rotationSpeed = 100f; | ||||
|  | ||||
|     private bool isRotating; | ||||
|     private Vector2 lastTouchPosition; | ||||
|  | ||||
|     // Update is called once per frame | ||||
|     void Update() | ||||
|     { | ||||
|         HandleRotation(); | ||||
|     } | ||||
|  | ||||
|     void HandleRotation() | ||||
|     { | ||||
|         // Comprobar si hay un toque en la pantalla | ||||
|         if (Input.touchCount > 0) | ||||
|         { | ||||
|             Touch touch = Input.GetTouch(0); | ||||
|  | ||||
|             // Si el toque ha comenzado | ||||
|             if (touch.phase == TouchPhase.Began) | ||||
|             { | ||||
|                 lastTouchPosition = touch.position; | ||||
|                 isRotating = true; | ||||
|             } | ||||
|             // Mientras se arrastra el dedo en la pantalla | ||||
|             else if (touch.phase == TouchPhase.Moved && isRotating) | ||||
|             { | ||||
|                 Vector2 touchDelta = touch.position - lastTouchPosition; | ||||
|                 float rotatiorAmount = touchDelta.x * rotationSpeed * Time.deltaTime; | ||||
|  | ||||
|                 // Rotar el mueble sobre el eje Y | ||||
|                 furniture.transform.Rotate(0, -rotatiorAmount, 0); | ||||
|  | ||||
|                 lastTouchPosition = touch.position; | ||||
|             } | ||||
|             // Cuando el toque termina | ||||
|             else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) | ||||
|             { | ||||
|                 isRotating = false; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/ScalateAndRotateObjectAR.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/ScalateAndRotateObjectAR.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 20102c103a6368046b860b5b8d1f7769 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										17
									
								
								Assets/Rendering/Scripts/SceneSwitcher.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Assets/Rendering/Scripts/SceneSwitcher.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| using UnityEngine; | ||||
| using UnityEngine.SceneManagement; | ||||
|  | ||||
| public class SceneSwitcher : MonoBehaviour | ||||
| { | ||||
|     public void LoadScene(string sceneName) | ||||
|     { | ||||
|         if (!string.IsNullOrEmpty(sceneName)) | ||||
|         { | ||||
|             SceneManager.LoadScene(sceneName); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             Debug.LogError("El nombre de la escena no ha sido proporcionado."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/SceneSwitcher.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/SceneSwitcher.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: a76adfc926dfcd4418ce1de84fc6848f | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										196
									
								
								Assets/Rendering/Scripts/ShareScreenshotButton.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										196
									
								
								Assets/Rendering/Scripts/ShareScreenshotButton.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,196 @@ | ||||
| using System; | ||||
| using System.Collections; | ||||
| using System.IO; | ||||
| using UnityEngine; | ||||
| using UnityEngine.Android; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| public class ShareScreenshotButton : MonoBehaviour | ||||
| { | ||||
|     public Button screenshotButton; | ||||
|     private string fileName; | ||||
|  | ||||
|     // Start is called before the first frame update | ||||
|     void Start() | ||||
|     { | ||||
|         if (!AndroidVersionIs11OrAbove() && !Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite)) | ||||
|         { | ||||
|             // Si no tiene permisos, solicitarlos | ||||
|             Permission.RequestUserPermission(Permission.ExternalStorageWrite); | ||||
|         } | ||||
|  | ||||
|         // Asignar la funci<63>n al evento onClick del bot<6F>n | ||||
|         screenshotButton.onClick.AddListener(TakeScreenshotAndShare); | ||||
|     } | ||||
|  | ||||
|     public void CheckPermissions() | ||||
|     { | ||||
|         // Este m<>todo puede ser llamado en cualquier momento para verificar permisos | ||||
|         if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite)) | ||||
|         { | ||||
|             Debug.Log("Permiso concedido para escribir en almacenamiento."); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             Debug.Log("Permiso denegado para escribir en almacenamiento."); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void TakeScreenshotAndShare() | ||||
|     { | ||||
|         fileName = "Screenshot_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".png"; | ||||
|         // Iniciar la rutina para capturar y compartir la pantalla | ||||
|         StartCoroutine(CaptureAndShareScreenshot()); | ||||
|     } | ||||
|  | ||||
|     private IEnumerator CaptureAndShareScreenshot() | ||||
|     { | ||||
|         // Esperar al final del frame para asegurarse de que todo est<73> dibujado | ||||
|         yield return new WaitForEndOfFrame(); | ||||
|  | ||||
|         // Tomar la captura de pantalla y guardarla en la carpeta temporal del dispositivo | ||||
|         Texture2D screenshot = new(Screen.width, Screen.height, TextureFormat.RGB24, false); | ||||
|         screenshot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); | ||||
|         screenshot.Apply(); | ||||
|  | ||||
|         byte[] imageBytes = screenshot.EncodeToPNG(); | ||||
|  | ||||
|         if (AndroidVersionIs11OrAbove()) | ||||
|         { | ||||
|             SaveImageToGalleryAndShare(imageBytes, fileName); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             SaveImageToExternalStorageAndShare(imageBytes, fileName); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private bool AndroidVersionIs11OrAbove() | ||||
|     { | ||||
|         return (Application.platform == RuntimePlatform.Android && SystemInfo.operatingSystem.StartsWith("Android OS") && int.Parse(SystemInfo.operatingSystem.Split(' ')[2]) >= 11); | ||||
|     } | ||||
|  | ||||
|     // Guardar en MediaStore (Android 11 o superior) y compartir | ||||
|     private void SaveImageToGalleryAndShare(byte[] imageBytes, string fileName) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             AndroidJavaClass mediaStoreClass = new("android.provider.MediaStore$Images$Media"); | ||||
|             AndroidJavaObject contentResolver = GetContentResolver(); | ||||
|             AndroidJavaObject contentValues = new("android.content.ContentValues"); | ||||
|  | ||||
|             contentValues.Call("put", "title", fileName); | ||||
|             contentValues.Call("put", "mime_type", "image/png"); | ||||
|             contentValues.Call("put", "relative_path", "Pictures/Screenshots"); | ||||
|  | ||||
|             AndroidJavaObject uri = contentResolver.Call<AndroidJavaObject>("insert", mediaStoreClass.GetStatic<AndroidJavaObject>("EXTERNAL_CONTENT_URI"), contentValues); | ||||
|             if (uri != null) | ||||
|             { | ||||
|                 AndroidJavaObject outputStream = contentResolver.Call<AndroidJavaObject>("openOutputStream", uri); | ||||
|                 outputStream.Call("write", imageBytes); | ||||
|                 outputStream.Call("flush"); | ||||
|                 outputStream.Call("close"); | ||||
|  | ||||
|                 Debug.Log("Captura guardada en la galer<65>a."); | ||||
|                 ShareScreenshot(uri); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 Debug.LogError("No se pudo guardar la imagen en MediaStore."); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             Debug.LogError("Error al guardar la captura en MediaStore: " + ex.Message); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Guardar en almacenamiento externo (para Android 8 a 10) y compartir | ||||
|     private void SaveImageToExternalStorageAndShare(byte[] imageBytes, string fileName) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             string directory = GetExternalStorageDirectory(); | ||||
|  | ||||
|             if (!Directory.Exists(directory)) | ||||
|             { | ||||
|                 Directory.CreateDirectory(directory); | ||||
|             } | ||||
|  | ||||
|             string filePath = Path.Combine(directory, fileName); | ||||
|             File.WriteAllBytes(filePath, imageBytes); | ||||
|             Debug.Log("Captura guardada en: " + filePath); | ||||
|  | ||||
|             ShareScreenshot(new AndroidJavaObject("java.io.File", filePath)); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             Debug.LogError("Error al guardar la captura: " + ex.Message); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // M<>todo para obtener la ruta del almacenamiento externo | ||||
|     private string GetExternalStorageDirectory() | ||||
|     { | ||||
|         AndroidJavaClass environment = new("android.os.Environment"); | ||||
|         string directory = environment.CallStatic<AndroidJavaObject>("getExternalStoragePublicDirectory", environment.GetStatic<string>("DIRECTORY_PICTURES")).Call<string>("getAbsolutePath"); | ||||
|  | ||||
|         return directory; | ||||
|     } | ||||
|  | ||||
|     // Compartir la captura de pantalla | ||||
|     private void ShareScreenshot(AndroidJavaObject fileOrUri) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             AndroidJavaClass intentClass = new("android.content.Intent"); | ||||
|             AndroidJavaObject intentObject = new("android.content.Intent"); | ||||
|  | ||||
|             intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND")); | ||||
|             intentObject.Call<AndroidJavaObject>("setType", "image/png"); | ||||
|  | ||||
|             // Obtener el contexto de Unity | ||||
|             AndroidJavaClass unityPlayer = new("com.unity3d.player.UnityPlayer"); | ||||
|             AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); | ||||
|  | ||||
|             // Si es Android 11 o superior, usa el URI; si es anterior, usa FileProvider | ||||
|             if (AndroidVersionIs11OrAbove()) | ||||
|             { | ||||
|                 intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), fileOrUri); | ||||
|                 intentObject.Call<AndroidJavaObject>("addFlags", 1 << 1); // FLAG_GRANT_READ_URI_PERMISSION | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 AndroidJavaClass fileProviderClass = new AndroidJavaClass("androidx.core.content.FileProvider"); | ||||
|  | ||||
|                 AndroidJavaObject uri = fileProviderClass.CallStatic<AndroidJavaObject>( | ||||
|                     "getUriForFile", | ||||
|                     currentActivity, | ||||
|                     currentActivity.Call<string>("getPackageName") + ".fileprovider", | ||||
|                     fileOrUri | ||||
|                 ); | ||||
|  | ||||
|                 intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uri); | ||||
|                 intentObject.Call("addFlags", intentClass.GetStatic<int>("FLAG_GRANT_READ_URI_PERMISSION")); | ||||
|                 //intentObject.Call<AndroidJavaObject>("addFlags", 1 << 1); // FLAG_GRANT_READ_URI_PERMISSION | ||||
|             } | ||||
|  | ||||
|             AndroidJavaObject chooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Share Screenshot"); | ||||
|             currentActivity.Call("startActivity", chooser); | ||||
|  | ||||
|             Debug.Log("Cuadro de di<64>logo de compartir lanzado."); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             Debug.LogError("Error al compartir la captura: " + ex.Message); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Obtener ContentResolver para Android | ||||
|     private AndroidJavaObject GetContentResolver() | ||||
|     { | ||||
|         AndroidJavaClass unityPlayer = new("com.unity3d.player.UnityPlayer"); | ||||
|         AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); | ||||
|         return currentActivity.Call<AndroidJavaObject>("getContentResolver"); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Rendering/Scripts/ShareScreenshotButton.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Rendering/Scripts/ShareScreenshotButton.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: db859f4c6b3759c48bfa5e7bed44ccd6 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
		Reference in New Issue
	
	Block a user
	 Ignacio Gómez Puga
					Ignacio Gómez Puga