diff --git a/Assets/Scenes/WebView.unity b/Assets/Scenes/WebView.unity index 3bac556..9c1198b 100644 --- a/Assets/Scenes/WebView.unity +++ b/Assets/Scenes/WebView.unity @@ -4119,7 +4119,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &721930530 MonoBehaviour: m_ObjectHideFlags: 0 @@ -10104,7 +10104,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &2137857638 RectTransform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/EndpointLoader.cs b/Assets/Scripts/EndpointLoader.cs index 90643c0..810ed39 100644 --- a/Assets/Scripts/EndpointLoader.cs +++ b/Assets/Scripts/EndpointLoader.cs @@ -14,6 +14,9 @@ public class EndpointLoader : MonoBehaviour [SerializeField] private WebView webView2; + [SerializeField] + private GameObject dynamicItem; + [SerializeField] private ServiceDiscovery serviceDiscovery; @@ -23,6 +26,7 @@ public class EndpointLoader : MonoBehaviour private string apiUrl; private bool triedMulticast = false; private bool defaultEndpointLoaded = false; + private List instantiatedItems = new List(); private HashSet availableServices = new HashSet(); private const string defaultApiUrl = "http://windows.local:5000/api/endpoints"; @@ -35,6 +39,56 @@ public class EndpointLoader : MonoBehaviour StartCoroutine(LoadEndpoints()); } + private Vector3 CalculateNextPosition() + { + if (instantiatedItems.Count == 0) + { + // return dynamicItem.transform.position; + return new Vector3(-0.4f, 0.1f, 1); + } + + GameObject lastItem = instantiatedItems[instantiatedItems.Count - 1]; + + Vector3 lastPosition = lastItem.transform.position; + float itemWidth = GetItemWidth(lastItem); + return new Vector3(lastPosition.x + itemWidth, lastPosition.y, lastPosition.z); + } + + private float GetItemWidth(GameObject item) + { + Renderer renderer = item.GetComponent(); + if (renderer != null) + { + return renderer.bounds.size.x; + } + + return 1.0f; + } + + public void SpawnItem(string url) + { + if (dynamicItem != null) + { + Vector3 nextPosition = CalculateNextPosition(); + + GameObject newItem = Instantiate(dynamicItem, nextPosition, dynamicItem.transform.rotation, dynamicItem.transform.parent); + newItem.SetActive(true); + + instantiatedItems.Add(newItem); + + var webView = newItem.GetComponentInChildren(); + + if (webView != null) + { + webView.Load(url); + } + } + else + { + Debug.LogError("Dynamic item is not assigned."); + } + } + private IEnumerator TryLoadingFromDefaultEndpoints() { using (UnityWebRequest request = UnityWebRequest.Get(defaultEndpoint1)) @@ -110,8 +164,15 @@ public class EndpointLoader : MonoBehaviour } else { - webView1.Load(endpoints[0].url ?? defaultEndpoint1); - webView2.Load(endpoints[1].url ?? defaultEndpoint2); + foreach (var endpoint in endpoints) + { + if (endpoint.url == null || endpoint.url.Length == 0) + { + Debug.LogWarning($"Endpoint URL is null for endpoint"); + continue; + } + SpawnItem(endpoint.url); + } } } @@ -153,8 +214,8 @@ public class EndpointLoader : MonoBehaviour private void UseDefaultEndpoints() { - webView1.Load(defaultEndpoint1); - webView2.Load(defaultEndpoint2); + // webView1.Load(defaultEndpoint1); + // webView2.Load(defaultEndpoint2); } [Serializable]