Exemplo n.º 1
0
        private async Task <bool> TryDeleteCoordinateImplAsync(string id, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            await EnsureInitializedAsync().Unless(cancellationToken);

            RequestSessionStart();

            try
            {
                SpatialAnchorsCoordinate spatialAnchorsCoordinate;
                if (!knownCoordinates.TryGetValue(id, out ISpatialCoordinate spatialCoordinate))
                {
                    return(false);
                }

                spatialAnchorsCoordinate = (SpatialAnchorsCoordinate)spatialCoordinate;

                await session.DeleteAnchorAsync(spatialAnchorsCoordinate.CloudSpatialAnchor);

                // Dispose in case of success only
                OnRemoveCoordinate(id);
                spatialAnchorsCoordinate.Destroy();
                return(true);
            }
            finally
            {
                ReleaseSessionStartRequest();
            }
        }
Exemplo n.º 2
0
 public async Task DeleteAnchorAsync(CloudSpatialAnchor cloudSpatialAnchor)
 {
     if (SessionValid())
     {
         await cloudSpatialAnchorSession.DeleteAnchorAsync(cloudSpatialAnchor);
     }
 }
Exemplo n.º 3
0
    private void CloudSpatialAnchorSession_AnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        switch (args.Status)
        {
        case LocateAnchorStatus.Located:
            DispatcherQueue.Enqueue(async() =>
            {
                // Instantiate the Prefab
                _prefabInstance = GameObject.Instantiate(Prefab, Vector3.zero, Quaternion.identity) as GameObject;
                var localAnchor = _prefabInstance.AddComponent <WorldAnchor>();

                // Get the WorldAnchor from the CloudSpatialAnchor and assign it to the local anchor
                localAnchor.SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);

                // Delete the ASA anchor Clean up state so that we can start over and create a new anchor.
                await _cloudSpatialAnchorSession.DeleteAnchorAsync(args.Anchor);
                _currentCloudAnchorId = String.Empty;
                _wasTapped            = false;
                Log($"Anchor located: {args.Identifier}\r\nGaze and tap to place a new anchor.", Color.green);
            });
            break;

        case LocateAnchorStatus.AlreadyTracked:
            Log($"ASA Anchor already tracked: {args.Identifier}", Color.magenta);
            break;

        case LocateAnchorStatus.NotLocated:
            Log($"ASA Anchor not located : {args.Identifier}", Color.magenta);
            break;

        case LocateAnchorStatus.NotLocatedAnchorDoesNotExist:
            Log($"ASA Anchor not located -> Does not exist: {args.Identifier}", Color.red);
            break;
        }
    }
Exemplo n.º 4
0
    private void OnAnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        UnityEngine.WSA.Application.InvokeOnAppThread(
            async() =>
        {
            if (isDeleteProcess)
            {
                await cloudAnchorSession.DeleteAnchorAsync(args.Anchor);
            }
            else
            {
                var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

                cube.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

                cube.GetComponent <Renderer>().material = this.relocalizedCubeMaterial;

                var worldAnchor = cube.AddComponent <WorldAnchor>();

                worldAnchor.SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);

                cube.name = args.Identifier;

                cubes.Add(cube);
            }
        },
            false
            );
    }
Exemplo n.º 5
0
        public async Task DeleteAnchorAsync(CloudSpatialAnchor cloudSpatialAnchor)
        {
            if (SessionValid())
            {
                await cloudSpatialAnchorSession.DeleteAnchorAsync(cloudSpatialAnchor);

                OnAnchorCreationfailed?.Invoke();
                Debug.Log("Anchor Creation Failed...Please try again...");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Deletes the specified anchor.
        /// </summary>
        /// <param name="anchor">
        /// The anchor to delete.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that represents the operation.
        /// </returns>
        /// <remarks>
        /// If there is no active <see cref="Session"/>, calling this method
        /// will result in an exception.
        /// </remarks>
        public async Task DeleteAnchorAsync(CloudSpatialAnchor anchor)
        {
            // Validate
            if (anchor == null)
            {
                throw new ArgumentNullException(nameof(anchor));
            }
            EnsureSessionStarted();

            // Actually delete
            await session.DeleteAnchorAsync(anchor);
        }
Exemplo n.º 7
0
    /// <summary>
    /// Deletes the currently loaded Azure Spatial Anchor. Destroys the slate game object and displays the Litecoin symbol.
    /// </summary>
    public async void DeleteAzureSpatialAnchorAsync()
    {
#if UNITY_EDITOR
        if (IsSlateActive)
        {
            Destroy(GameObject.FindGameObjectWithTag("Slate"));
            IsSlateActive = false;

            // This asynchronous task just prevents a warning due to this method being asynchronous and otherwise lacking an await operator.
            await Task.Delay(300);

            DisplayLitecoinSymbol();
        }

        return;
#else
        if (IsSlateActive && currentCloudAnchor != null)
        {
            Destroy(GameObject.FindGameObjectWithTag("Slate"));
            IsSlateActive = false;

            Instructions.text = $"Deleting Azure Spatial Anchor...\n\nIdentifier: {currentCloudAnchor.Identifier}";
            await Task.Delay(3000);

            try
            {
                await cloudSpatialAnchorSession.DeleteAnchorAsync(currentCloudAnchor);

                Instructions.text = "Azure Spatial Anchor deleted.";
                await Task.Delay(3000);
            }
            catch (Exception ex)
            {
                Instructions.text = $"Error deleting Azure Spatial Anchor.\n\n{ex.Message}";
                await Task.Delay(3000);
            }

            cloudSpatialAnchorId = null;
            currentCloudAnchor   = null;
            PlayerPrefs.SetString("Anchor ID", null);
            DisplayLitecoinSymbol();
        }
        else
        {
            Instructions.text = "No Azure Spatial Anchors exists. Please create an anchor before attempting to delete one.";
            await Task.Delay(3000);

            Instructions.text = "Use the ray coming from either hand to position the Litecoin currency symbol. Air tap to place the symbol. This will be the location where your mining stats will be displayed.\n\nWhen you're ready, turn either hand so that your palm is facing you to access the hand menu. Tap the \"Create Spatial Anchor\" button to save the Azure Spatial Anchor.";
        }
#endif
    }
        private async Task CreateAnchorAsync(Vector3 newPosition)
        {
            var dist = Vector3.Distance(localAnchorPosition, newPosition);

            if (newPosition != Vector3.zero && (localAnchorPosition == Vector3.zero || dist > minPositionChangeDistance))
            {
                // Lock game object. While anchor is saved.
                localAnchorGameObject.GetComponent <DragonAI>().StopPlayerPositionTracking();
                localAnchorGameObject.AddARAnchor();

                if (loadedAnchor != null)
                {
                    // Remove old anchor.
                    await cloudSession.DeleteAnchorAsync(loadedAnchor);
                }

                // Save to server.
                CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();
                cloudAnchor.LocalAnchor             = localAnchorGameObject.GetNativeAnchorPointer();
                cloudAnchor.AppProperties[@"label"] = @"Dragon";
                await cloudSession.CreateAnchorAsync(cloudAnchor);

                await storageService.PostAnchorId(cloudAnchor.Identifier);

                Debug.Log(DEBUG_FILTER + $"Created a cloud anchor with ID={cloudAnchor.Identifier}");

                // Unlock game object.
                localAnchorGameObject.RemoveARAnchor();
                localAnchorGameObject.GetComponent <DragonAI>().ChangePosition(newPosition);
                Debug.Log(DEBUG_FILTER + "saved position" + newPosition + " to server");
                await Task.Delay(5000); // Wait 5 sec before tracking again.

                Debug.Log(DEBUG_FILTER + "continue tracking");
                localAnchorGameObject.GetComponent <DragonAI>().StartPlayerPositionTracking();
                localAnchorPosition = new Vector3(newPosition.x, newPosition.y, newPosition.z);
            }
        }
 public Task DeleteAnchorAsync(CloudSpatialAnchor anchor) => spatialAnchorsSession.DeleteAnchorAsync(anchor);