コード例 #1
0
        public IEnumerator AddNewAnchorSet(string anchorSetName)
        {
            IsEnabled = true;

            using (var request = new UnityWebRequest(Globals.ServiceBaseUrl + AnchorSetsUrl))
            {
                request.method          = UnityWebRequest.kHttpVerbPOST;
                request.uploadHandler   = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(anchorSetName)));
                request.downloadHandler = new DownloadHandlerBuffer();
                request.SetRequestHeader("Content-Type", "application/json");
                request.AddApiKeyHeader(Globals.ApiKey);

                yield return(request.SendWebRequest());

                if (request.isNetworkError || request.isHttpError)
                {
                    Debug.Log(request.error);
                    yield break;
                }

                SelectedAnchorSet = JsonUtility.FromJson <AnchorSet>(request.downloadHandler.text);
                OnLoadAnchorSet();
            }
        }
コード例 #2
0
        protected IEnumerator SetCurrentState()
        {
            if (AnchorSetManager.Instance == null || AnchorSetManager.Instance.SelectedAnchorSet == null)
            {
                yield break;
            }

            var url = string.Format("{0}/sharedstate/{1}", Globals.ServiceBaseUrl, AnchorSetManager.Instance.SelectedAnchorSet.id);

            using (var request = new UnityWebRequest(url))
            {
                request.method        = UnityWebRequest.kHttpVerbPUT;
                request.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(JsonUtility.ToJson(CurrentState)));
                request.SetRequestHeader("Content-Type", "application/json");
                request.AddApiKeyHeader(Globals.ApiKey);

                yield return(request.SendWebRequest());

                if (request.isNetworkError || request.isHttpError)
                {
                    Debug.LogError(request.error);
                }
            }
        }