Removed TOTU 103
This commit is contained in:
		
							
								
								
									
										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); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Ignacio Gómez Puga
					Ignacio Gómez Puga