public async Task DeleteAnchor(GameObject anchorObject, GameObject relatedObject, CloudSpatialAnchor cloudAnchor) { try { var url = string.Format("{0}/{1}/{2}/{3}", Globals.ServiceBaseUrl, AnchorSetsRoute, AnchorSetManager.Instance.SelectedAnchorSet.id, cloudAnchor.Identifier); #if !UNITY_EDITOR using (HttpClient client = new HttpClient()) { client.AddApiKeyHeader(Globals.ApiKey); var result = await client.DeleteAsync(url); if (result.IsSuccessStatusCode) { Debug.Log("AnchorManager::DeleteAnchor - Deleting cloud anchor..."); await AzureSpatialAnchorManager.Instance.DeleteAnchorAsync(cloudAnchor); Debug.Log("AnchorManager::DeleteAnchor - Cloud anchor deleted"); lock (_dispatchQueue) { _dispatchQueue.Enqueue(new Action(() => { Destroy(anchorObject); if (relatedObject != null) { Destroy(relatedObject); } BroadcastMessage("OnAnchorDeleted"); })); } } else { Debug.LogError("AnchorManager::DeleteAnchor Failed - " + result.StatusCode + result.ReasonPhrase); } } #endif } catch (Exception ex) { Debug.LogError("AnchorManager::DeleteAnchor Failed - " + ex.ToString()); } }
private async Task <string> GenerateToken() { try { #if !UNITY_EDITOR using (HttpClient client = new HttpClient()) { client.AddApiKeyHeader(Globals.ApiKey); return(await client.GetStringAsync(Globals.ServiceBaseUrl + "/apptoken")); } #endif } catch (Exception ex) { Debug.LogError(ex.ToString()); } return(""); }
private async Task <bool> SaveAnchor(string url, string body = null) { try { #if !UNITY_EDITOR using (HttpClient client = new HttpClient()) { client.AddApiKeyHeader(Globals.ApiKey); var result = await client.PutAsync(url, string.IsNullOrWhiteSpace(body)?null : new StringContent(JsonConvert.SerializeObject(body), System.Text.Encoding.UTF8, "application/json")); return(result.IsSuccessStatusCode); } #endif } catch (Exception ex) { Debug.LogError(ex.ToString()); } return(false); }