Exemple #1
0
    public async Task CreateCloudAnchor(CloudSpatialAnchor cloudSpatialAnchor)
    {
        ARTapToPlace     arTapManager = FindObjectOfType <ARTapToPlace>();
        TextProOnACircle tpoac        = arTapManager.spawnedObject.transform.Find("Anchor Text").GetComponent <TextProOnACircle>();


        debugText.text = "Trying to create Cloud Anchor " + cloudSpatialAnchor.Identifier;
        if (cloudSpatialAnchor is null)
        {
            debugText.text += "Anchor is null, not creating";
            return;
        }

        //while the manager doesn't have enough data to create an Azure anchor, wait for more info
        //TODO: add a better indicator for the user to gather more environmental data
        while (!spatialAnchorManager.IsReadyForCreate)
        {
            await Task.Delay(330);

            float createProgress = spatialAnchorManager.SessionStatus.RecommendedForCreateProgress;
            topText.text = $"Move your device to capture more environment data: {createProgress:0%}";
        }
        debugText.text = "\nMade it out";

        //creates the anchor in the manager
        try
        {
            debugText.text += "\nTrying to call CreateAnchorAsync() with " + cloudSpatialAnchor.Identifier;
            await spatialAnchorManager.Session.CreateAnchorAsync(cloudSpatialAnchor);

            debugText.text += "\nAnchor created with ID: " + cloudSpatialAnchor.Identifier;
        }
        catch (Exception ex)
        {
            debugText.text  = "Exception thrown: " + ex.Message;
            debugText.text += "\nWifi Enabled: " + spatialAnchorManager.Session.LocationProvider.Sensors.WifiEnabled;
            debugText.text += "\nGeo Enabled: " + spatialAnchorManager.Session.LocationProvider.Sensors.GeoLocationEnabled;
            debugText.text += "\nWifi Status: " + spatialAnchorManager.Session.LocationProvider.WifiStatus;
            debugText.text += "\nGeo Status: " + spatialAnchorManager.Session.LocationProvider.GeoLocationStatus;
        }
    }
Exemple #2
0
    public async void PlaceAnchor(string anchorLabel)
    {
        //For some reason, we need to refresh TextProOnACircle component so that it
        //doesn't unravel and just display the text in a straight line.
        //note: this is a total band-aid fix that only kind of works anyway..
        //TODO: find out why this is happening and fix it at the source so we don't
        //      have to destroy and create stuff
        ARTapToPlace     arTapManager = FindObjectOfType <ARTapToPlace>();
        TextProOnACircle tpoac        = arTapManager.spawnedObject.transform.Find("Anchor Text").GetComponent <TextProOnACircle>();
        TMP_Text         targetText   = arTapManager.spawnedObject.transform.Find("Anchor Text").GetComponent <TMP_Text>();

        targetText.text = "";
        Destroy(tpoac);
        arTapManager.spawnedObject.transform.Find("Anchor Text").gameObject.AddComponent <TextProOnACircle>();
        int anchorLabelLength = 0;

        while (anchorLabelLength <= 26)
        {
            targetText.text   += anchorLabel + "    ";
            anchorLabelLength += anchorLabel.Length + 4;
        }

        //End of weird circle text refresh


        //check for the object first
        if (spawnedObject == null)
        {
            //haven't placed
            Debug.Log("Trying to make cloud anchor without local");
            return;
        }

        //gets the CloudNativeAnchor component
        CloudNativeAnchor cna = spawnedObject.GetComponent <CloudNativeAnchor>();

        //if the spawned object doesn't have a cloud anchor associated with it,
        //NativeToCloud will make one with the CloudNativeAnchor component we just got
        if (cna.CloudAnchor == null)
        {
            cna.NativeToCloud();
        }

        //Begin to convert ARFoundation anchor to a CloudSpatialAnchor
        CloudSpatialAnchor cloudAnchor = cna.CloudAnchor;

        //set app property for label
        cloudAnchor.AppProperties["label"] = anchorLabel;
        await cloudAnchorManager.CreateCloudAnchor(cloudAnchor);

        //now the anchor has been created, need to refresh session so it shows up maybe?


        //clean up the local instance of the cube and anchor we just placed
        //so we can reset and render the version from the cloud
        CleaupSpawnedObject();

        await cloudAnchorManager.ResetSession();

        cloudAnchorManager.findAnchorsByLocation();
    }