Removed TOTU 103
This commit is contained in:
		
							
								
								
									
										46
									
								
								Assets/Scripts/ObjectDetection/DrawRect.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								Assets/Scripts/ObjectDetection/DrawRect.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| // Copyright 2022-2024 Niantic. | ||||
|  | ||||
| using System; | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
|  | ||||
| public class DrawRect : MonoBehaviour | ||||
| { | ||||
|     [SerializeField] | ||||
|     private GameObject _rectanglePrefab; | ||||
|      | ||||
|     private List<UIRectObject> _rectangleObjects = new List<UIRectObject>(); | ||||
|     private List<int> _openIndices = new List<int>(); | ||||
|  | ||||
|     public void CreateRect(Rect rect, Color color, string text) | ||||
|     { | ||||
|         if (_openIndices.Count == 0) | ||||
|         { | ||||
|             var newRect = Instantiate(_rectanglePrefab, parent: this.transform).GetComponent<UIRectObject>(); | ||||
|  | ||||
|             _rectangleObjects.Add(newRect); | ||||
|             _openIndices.Add(_rectangleObjects.Count - 1); | ||||
|         } | ||||
|          | ||||
|         // Treat the first index as a queue | ||||
|         int index = _openIndices[0]; | ||||
|         _openIndices.RemoveAt(0); | ||||
|          | ||||
|         UIRectObject rectangle = _rectangleObjects[index]; | ||||
|         rectangle.SetRectTransform(rect); | ||||
|         rectangle.SetColor(color); | ||||
|         rectangle.SetText(text); | ||||
|         rectangle.gameObject.SetActive(true); | ||||
|     } | ||||
|  | ||||
|     public void ClearRects() | ||||
|     { | ||||
|         for (var i = 0; i < _rectangleObjects.Count; i++) | ||||
|         { | ||||
|             _rectangleObjects[i].gameObject.SetActive(false); | ||||
|             _openIndices.Add(i); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Ignacio Gómez Puga
					Ignacio Gómez Puga