Add fallback option if there are no services
This commit is contained in:
parent
b5736fa9de
commit
f9b441bb51
|
@ -51,3 +51,10 @@ MonoBehaviour:
|
|||
id: 0
|
||||
description: None
|
||||
axisConstraint: 0
|
||||
- localizationKey:
|
||||
keyword: Select
|
||||
keyCode: 0
|
||||
action:
|
||||
id: 0
|
||||
description: None
|
||||
axisConstraint: 0
|
||||
|
|
|
@ -2299,6 +2299,7 @@ Transform:
|
|||
- {fileID: 1389755617}
|
||||
- {fileID: 4283623065100561231}
|
||||
- {fileID: 2018722011}
|
||||
- {fileID: 501711429}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 3
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
@ -2372,6 +2373,52 @@ MonoBehaviour:
|
|||
dynamicItem: {fileID: 2080231666}
|
||||
serviceDiscovery: {fileID: 1389755618}
|
||||
servicesListPopulator: {fileID: 6339559048287679331}
|
||||
dialogHandler: {fileID: 501711430}
|
||||
--- !u!1 &501711428
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 501711429}
|
||||
- component: {fileID: 501711430}
|
||||
m_Layer: 0
|
||||
m_Name: DialogHandler
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &501711429
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 501711428}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 425776887}
|
||||
m_RootOrder: 9
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &501711430
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 501711428}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c1b75ab140e790045b0eaeae0266d7de, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
dialogPrefab: {fileID: 2680377478557818543, guid: 8e686c90124b8e14cbf8093893109e9a, type: 3}
|
||||
--- !u!1 &504187403
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
using Microsoft.MixedReality.Toolkit.UI;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class DialogHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private GameObject dialogPrefab;
|
||||
|
||||
public void OpenDialog(string title, string question, Action action)
|
||||
{
|
||||
Dialog dialog = Dialog.Open(dialogPrefab, DialogButtonType.Yes | DialogButtonType.No, title, question, true);
|
||||
if (dialog != null)
|
||||
{
|
||||
// myDialog.OnClosed += OnClosedDialogEvent;
|
||||
dialog.OnClosed += (x) =>
|
||||
{
|
||||
if (x.Result == DialogButtonType.Yes)
|
||||
{
|
||||
action?.Invoke();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c1b75ab140e790045b0eaeae0266d7de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -17,11 +17,15 @@ public class EndpointLoader : MonoBehaviour
|
|||
[SerializeField]
|
||||
private ServicesListPopulator servicesListPopulator;
|
||||
|
||||
[SerializeField]
|
||||
private DialogHandler dialogHandler;
|
||||
|
||||
private string apiUrl;
|
||||
private bool triedMulticast = false;
|
||||
private bool defaultEndpointLoaded = false;
|
||||
private List<GameObject> instantiatedItems = new List<GameObject>();
|
||||
private HashSet<MdnsService> availableServices = new HashSet<MdnsService>();
|
||||
private float loadTimeout = 10f;
|
||||
|
||||
private const string defaultApiUrl = "http://windows.local:5000/api/endpoints";
|
||||
private const string defaultEndpoint1 = "http://windows.local:8100/mystream/";
|
||||
|
@ -30,9 +34,30 @@ public class EndpointLoader : MonoBehaviour
|
|||
private void Start()
|
||||
{
|
||||
apiUrl = defaultApiUrl;
|
||||
StartCoroutine(TimeoutFallback());
|
||||
StartCoroutine(LoadEndpoints());
|
||||
}
|
||||
|
||||
private IEnumerator TimeoutFallback()
|
||||
{
|
||||
float timer = 0f;
|
||||
|
||||
while (timer < loadTimeout && availableServices.Count == 0)
|
||||
{
|
||||
yield return new WaitForSeconds(1f);
|
||||
timer += 1f;
|
||||
}
|
||||
|
||||
if (availableServices.Count == 0)
|
||||
{
|
||||
Debug.LogWarning("Timeout reached. Loading default endpoints...");
|
||||
dialogHandler.OpenDialog("Timeout reached", "No services found. Load default endpoints?", () =>
|
||||
{
|
||||
StartCoroutine(TryLoadingFromDefaultEndpoints());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 CalculateNextPosition()
|
||||
{
|
||||
if (instantiatedItems.Count == 0)
|
||||
|
@ -106,6 +131,15 @@ public class EndpointLoader : MonoBehaviour
|
|||
yield return request.SendWebRequest();
|
||||
ProcessEndpointResponse(request, defaultEndpoint2, ref defaultEndpointLoaded);
|
||||
}
|
||||
|
||||
if (!defaultEndpointLoaded)
|
||||
{
|
||||
Debug.LogError("Failed to load default endpoints");
|
||||
dialogHandler.OpenDialog("Failed to load default endpoints", "Do you want to try one more time?", () =>
|
||||
{
|
||||
StartCoroutine(TryLoadingFromDefaultEndpoints());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessEndpointResponse(UnityWebRequest request, string endpoint, ref bool loadedFlag)
|
||||
|
@ -133,6 +167,12 @@ public class EndpointLoader : MonoBehaviour
|
|||
yield break;
|
||||
}
|
||||
|
||||
if (defaultEndpointLoaded)
|
||||
{
|
||||
Debug.Log("Default endpoint already loaded");
|
||||
yield break;
|
||||
}
|
||||
|
||||
var request = new UnityWebRequest(apiUrl, UnityWebRequest.kHttpVerbGET);
|
||||
request.downloadHandler = new DownloadHandlerBuffer();
|
||||
request.SetRequestHeader("Content-Type", "application/json");
|
||||
|
|
Loading…
Reference in New Issue