Example #1
0
    public void StartSnapPhoto()
    {
        textmesh.text             = "Verifying...";
        cameraButton.interactable = false;

        LoadingCircle.Show();

        StartCoroutine(controller.SnapPhoto(async tex =>
        {
            try
            {
                audioSource.PlayOneShot(clipCamera);

                // encode the image from the camera as a PNG to send to the Computer Vision API
                byte[] pngBuff  = tex.EncodeToPNG();
                MemoryStream ms = new MemoryStream(pngBuff);

                // call the vision service and get the image analysis
                VisionServiceClient client = new VisionServiceClient(Globals.VisionKey, Globals.VisionEndpoint);
                AnalysisResult result      = await client.DescribeAsync(ms);

                // send the tag list to the debug log
                string tags = result.Description.Tags.Aggregate((x, y) => $"{x}, {y}");
                Debug.Log(tags);

                foreach (string itemTag in Globals.CurrentItem.Tags)
                {
                    if (result.Description.Tags.Contains(itemTag.ToLower()))
                    {
                        audioSource.PlayOneShot(clipFound);
                        textmesh.text = "You found it!";

                        PlayFabEvents.WriteEvent(PlayFabEventType.ItemFound);

                        // if the image matches, call the ItemFound function to record it
                        string s = JsonConvert.SerializeObject(Globals.CurrentItem);
                        await Globals.HttpClient.PostAsync("ItemFound", new StringContent(s, Encoding.UTF8, "application/json"));
                        LoadingCircle.Dismiss();
                        SceneManager.LoadScene("ItemList");
                        return;
                    }
                }

                audioSource.PlayOneShot(clipNotFound);
                textmesh.text = "Not a match, please try again.";

                PlayFabEvents.WriteEvent(PlayFabEventType.ItemNotFound);

                controller.StartStream();
                cameraButton.interactable = true;
                LoadingCircle.Dismiss();
            }
            catch (Exception e)
            {
                LoadingCircle.Dismiss();
                Debug.Log(e);
                DialogBox.Show(e.Message);
            }
        }));
    }