Ejemplo n.º 1
0
    IEnumerator GetIssues()
    {
        string url = string.Format("{0}/v2/api/docs/{1}/issues", appConfig.demoServerURL, appConfig.modelID);

        using (UnityWebRequest req = UnityWebRequest.Get(url))
        {
            req.SetRequestHeader("Authorization", "Bearer " + appConfig.accessToken);
            yield return(req.SendWebRequest());

            if (req.isNetworkError || req.isHttpError)
            {
                Debug.LogError(req.error);
            }
            else
            {
                // Clear all previous issue pushpins
                foreach (Transform transform in issuesTarget.transform)
                {
                    Destroy(transform.gameObject);
                }

                // Parse new pushpins and instantiate them in the scene
                string json   = req.downloadHandler.text;
                Issues issues = Issues.CreateFromJSON(json);
                foreach (var issue in issues.issues)
                {
                    GameObject clone = Instantiate(issuePrefab);
                    clone.transform.parent        = issuesTarget.transform;
                    clone.transform.localPosition = new Vector3(issue.pushpin_location.x, issue.pushpin_location.y, issue.pushpin_location.z);
                    clone.transform.localScale    = new Vector3(5f, 5f, 5f);
                    clone.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
                    clone.GetComponentInChildren <Text>().text = issue.title;
                    clone.GetComponent <LookAtSolver>().target = Camera.main.transform;
                    //Debug.Log("Issue: " + issue.title);
                }
            }
        }
    }