public async Task <ISpatialCoordinate> CreateCoordinateAsync(string id, Vector3 worldPosition, Quaternion worldRotation, CancellationToken cancellationToken) { #if UNITY_WSA await TryDeleteCoordinateAsync(id, cancellationToken); GameObject gameObject = new GameObject(id); gameObject.transform.position = worldPosition; gameObject.transform.rotation = worldRotation; WorldAnchor anchor = gameObject.AddComponent <WorldAnchor>(); if (anchor.isLocated) { WorldAnchorStore store = await GetWorldAnchorStoreAsync(); store.Save(id, anchor); } else { anchor.OnTrackingChanged += Anchor_OnTrackingChanged; } WorldAnchorSpatialCoordinate coordinate = new WorldAnchorSpatialCoordinate(id, anchor); OnNewCoordinate(id, coordinate); return(coordinate); #else Debug.LogError("Current platform does not support creating WorldAnchor coordinates"); return(await Task.FromResult <ISpatialCoordinate>(null)); #endif }
public override async Task <bool> TryDeleteCoordinateAsync(string key, CancellationToken cancellationToken) { #if UNITY_WSA if (TryGetKnownCoordinate(key, out ISpatialCoordinate coordinate)) { WorldAnchorSpatialCoordinate worldAnchorCoordinate = (WorldAnchorSpatialCoordinate)coordinate; WorldAnchorStore anchorStore = await GetWorldAnchorStoreAsync(); anchorStore.Delete(key); worldAnchorCoordinate.Destroy(); } #endif return(await base.TryDeleteCoordinateAsync(key, cancellationToken)); }