Exemplo n.º 1
0
    public void Start()
    {
        ProgressIndicator.Instance.Open("Loading application config...");

#if WINDOWS_UWP
        // On UWP platform, try and scan for QR code for 60 seconds.
        // If a QR code is found, make a request to its encoded URL
        // to see if it contains configuration JSON.
        TextToSpeech textToSpeech = GetComponent <TextToSpeech>();
        textToSpeech.StartSpeaking("Please scan a QR code with your session configuration.");
        ProgressIndicator.Instance.SetMessage("Scanning for QR code with configuration URL...");
        Debug.Log("Activating QR code scanning for 60 seconds");
        try
        {
            MediaFrameQrProcessing.Wrappers.ZXingQrCodeScanner.ScanFirstCameraForQrCode(
                result =>
            {
                Debug.Log("Result of QR code scanning: " + (result ?? "<none>"));
                UnityEngine.WSA.Application.InvokeOnAppThread(() => { StartCoroutine(ParseConfigurationFromURL(result)); }, false);
            },
                TimeSpan.FromSeconds(60)
                );
        }
        catch (Exception e)
        {
            ProgressIndicator.Instance.Close();
            Debug.Log("Error when activating QR code scanning: " + e.ToString());
        }
#else
        // On non-UWP platforms, immediately notify other components
        // that the configuration is ready.
        OnConfigReady?.Invoke();
#endif
    }
Exemplo n.º 2
0
    async void ParseConfigurationFromFile(string filename)
    {
        try
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            Debug.Log("Local folder path: " + folder.Path);
            StorageFile file = await folder.GetFileAsync(filename);

            string json = await FileIO.ReadTextAsync(file);

            Debug.Log("Config file found: " + json);
            Configuration config = Configuration.CreateFromJSON(json);
            demoServerURL = config.host;
        }
        catch (Exception)
        {
            Debug.Log("Config file not found.");
        }
        finally
        {
            OnConfigReady?.Invoke();
        }
    }
Exemplo n.º 3
0
    IEnumerator ParseConfigurationFromURL(string url)
    {
        ProgressIndicator.Instance.SetMessage("Loading application configuration...");
        using (UnityWebRequest req = UnityWebRequest.Get(url))
        {
            yield return(req.SendWebRequest());

            if (req.isNetworkError || req.isHttpError)
            {
                ProgressIndicator.Instance.Close();
                Debug.LogError(req.downloadHandler.text);
            }
            else
            {
                Debug.Log("Loaded configuration: " + req.downloadHandler.text);
                Configuration config = Configuration.CreateFromJSON(req.downloadHandler.text);
                demoServerURL = config.host;
                modelID       = config.model;
                accessToken   = config.access_token;
                OnConfigReady?.Invoke();
            }
        }
    }