public void CreateAzureAnchor(GameObject theObject)
    {
        DebugWindowMessaging.Clear();
        Debug.Log("Create_Azure_Anchor button is pressed");
        Debug.Log("Wait for sometime and press Share_Azure_Anchor");
        //First we create a local anchor at the location of the object in question
        theObject.AddARAnchor();

        //Then we create a new local cloud anchor
        CloudSpatialAnchor localCloudAnchor = new CloudSpatialAnchor();

        //Now we set the local cloud anchor's position to the local anchor's position
        localCloudAnchor.LocalAnchor = theObject.GetNativeAnchorPointer();

        //Check to see if we got the local anchor pointer
        if (localCloudAnchor.LocalAnchor == IntPtr.Zero)
        {
            Debug.Log("Didn't get the local XR anchor pointer...");
            return;
        }

        // In this sample app we delete the cloud anchor explicitly, but here we show how to set an anchor to expire automatically
        localCloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

        //Save anchor to cloud
        Task.Run(async() =>
        {
            while (!CloudManager.EnoughDataToCreate)
            {
                await Task.Delay(330);
            }

            bool success = false;
            try
            {
                currentCloudAnchor = await CloudManager.StoreAnchorInCloud(localCloudAnchor);

                //Save the Azure Anchor ID
                GenericNetworkManager.instance.AzureAnchorID = currentCloudAnchor.Identifier;
                Debug.Log("Azure anchor ID saved!");

                success          = currentCloudAnchor != null;
                localCloudAnchor = null;

                if (success)
                {
                    Debug.Log("Successfully Created Anchor");
                }
            }
            catch (Exception ex)
            {
                Debug.Log(ex);
                Debug.Log("Anchor creation failure");
            }
        });
    }
Esempio n. 2
0
    public void CreateAzureAnchor(GameObject theObject)
    {
        OnCreateAnchorStarted?.Invoke();
        createAnchorCoroutine = StartCoroutine(CreateAzureAnchorIDCorotuine());

        //First we create a local anchor at the location of the object in question
        theObject.AddARAnchor();

        //Then we create a new local cloud anchor
        CloudSpatialAnchor localCloudAnchor = new CloudSpatialAnchor();

        //Now we set the local cloud anchor's position to the local anchor's position
        localCloudAnchor.LocalAnchor = theObject.GetNativeAnchorPointer();

        //Check to see if we got the local anchor pointer
        if (localCloudAnchor.LocalAnchor == IntPtr.Zero)
        {
            Debug.Log("Didn't get the local XR anchor pointer...");
            return;
        }

        // In this sample app we delete the cloud anchor explicitly, but here we show how to set an anchor to expire automatically
        localCloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

        //Save anchor to cloud
        Task.Run(async() =>
        {
            while (!CloudManager.EnoughDataToCreate)
            {
                await Task.Delay(330);
                float createProgress = CloudManager.GetSessionStatusIndicator(AzureSpatialAnchorsDemoWrapper.SessionStatusIndicatorType.RecommendedForCreate);
                QueueOnUpdate(new Action(() => Debug.Log($"Move your device to capture more environment data: {createProgress:0%}")));
            }

            bool success = false;


            try
            {
                QueueOnUpdate(new Action(() => Debug.Log("Saving...")));

                currentCloudAnchor = await CloudManager.StoreAnchorInCloud(localCloudAnchor);

                //Save the Azure Anchor ID
                AzureAnchorID = currentCloudAnchor.Identifier;

                success = currentCloudAnchor != null;

                localCloudAnchor = null;

                if (success)
                {
                    //OnAnchorCreatedSuccessfully?.Invoke();
                    Debug.Log("Successfully Created Anchor");
                }
                else
                {
                    Debug.Log("Failed to save, but no exception was thrown.");
                }
            }
            catch (Exception ex)
            {
                //OnAnchorCreationfailed?.Invoke();
                Debug.Log(ex.ToString());
            }
        });
    }