コード例 #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);
            }
        }));
    }
コード例 #2
0
    // Use this for initialization
    async void Start()
    {
        LoadingCircle.Show();

        GameObject prefab    = Resources.Load("Prefabs/ItemRow") as GameObject;
        GameObject container = GameObject.Find("ItemList");

        try
        {
            string result = await Globals.HttpClient.GetStringAsync("GetDailyItems");

            DailyItems items = JsonConvert.DeserializeObject <DailyItems>(result);

            GameObject.Find("DateText").GetComponent <Text>().text = DateTime.Parse(items.Date).ToShortDateString();

            foreach (Item i in items.Items)
            {
                GameObject item    = Instantiate(prefab);
                ListItem   objItem = item.GetComponent <ListItem>();
                objItem.item = i;

                item.transform.Find("ItemName").gameObject.GetComponent <Text>().text = i.Name;
                item.transform.Find("Checkmark").gameObject.SetActive(i.Found);

                item.transform.SetParent(container.transform, false);
                item.SetActive(true);
            }
        }
        catch (Exception e)
        {
            Debug.Log(e);
            DialogBox.Show(e.Message);
        }
        finally
        {
            LoadingCircle.Dismiss();
        }
    }
コード例 #3
0
    // Use this for initialization
    void Start()
    {
        LoadingCircle.Show();

        GetLeaderboardRequest req = new GetLeaderboardRequest
        {
            MaxResultsCount = 10,
            StatisticName   = "Score"
        };

        PlayFabClientAPI.GetLeaderboard(req,
                                        result =>
        {
            GameObject prefab    = Resources.Load <GameObject>("Prefabs/LeaderboardRow");
            GameObject container = GameObject.Find("ItemList");

            foreach (var li in result.Leaderboard)
            {
                GameObject item = Instantiate(prefab);

                item.transform.Find("DisplayName").gameObject.GetComponent <Text>().text = li.DisplayName;
                item.transform.Find("Score").gameObject.GetComponent <Text>().text       = li.StatValue.ToString();

                item.transform.SetParent(container.transform, false);
                item.SetActive(true);
            }
            LoadingCircle.Dismiss();
        },
                                        error =>
        {
            LoadingCircle.Dismiss();
            Debug.Log("Error getting leaderboard: " + error.GenerateErrorReport());
            DialogBox.Show(error.GenerateErrorReport());
        }
                                        );
    }