text
stringlengths 0
1.11k
|
|---|
}
|
});
|
}
|
The GetSavedAnchorUUIDs() method just returns an array of Guids for the anchors that have been saved to local storage.
|
private System.Guid[] GetSavedAnchorsUuids()
|
{
|
var uuids = new Guid[_allSavedAnchors.Count];
|
using (var enumerator = _allSavedAnchors.GetEnumerator())
|
{
|
int i = 0;
|
while (enumerator.MoveNext())
|
{
|
var currentUuid = enumerator.Current.Uuid;
|
uuids[i] = new Guid(currentUuid.ToByteArray());
|
i++;
|
}
|
}
|
//Debug.Log("Returned All Anchor UUIDs!");
|
return uuids;
|
}
|
Bind Anchors
|
In this tutorial, we use a delegate to bind the anchor and add it back to the scene:
|
private void OnLocalized(OVRSpatialAnchor.UnboundAnchor unboundAnchor, bool success)
|
{
|
var pose = unboundAnchor.Pose;
|
GameObject go = PlaceAnchor(_saveableAnchorPrefab, pose.position, pose.rotation);
|
_workingAnchor = go.AddComponent<OVRSpatialAnchor>();
|
unboundAnchor.BindTo(_workingAnchor);
|
// add the anchor to the running total
|
_allRunningAnchors.Add(_workingAnchor);
|
}
|
Erase Saved Anchors
|
We use the Y button press to erase all the anchors from local storage. This doesn’t remove them from the scene, just from local storage.
|
// erase all saved (green) anchors
|
if (OVRInput.GetDown(OVRInput.Button.Four))
|
{
|
EraseAllAnchors();
|
}
|
OVRSpatialAnchor.Erase() is an asynchronous method, so we will use a Unity coroutine as we did for saving anchors. After we successfully erase an anchor from storage, we also need to remove it from the saved anchors array.
|
public void EraseAllAnchors()
|
{
|
foreach (var tmpAnchor in _allSavedAnchors)
|
{
|
OVRSpatialAnchor spAnchor = enumerator.Current;
|
if (spAnchor)
|
{
|
//use a Unity coroutine to manage the async save
|
StartCoroutine(anchorErased(spAnchor));
|
}
|
}
|
_allSavedAnchors.Clear();
|
//if we were saving to PlayerPrefs, we would alse delete those here
|
return;
|
}
|
The coroutine for erasing saved anchors is simpler than the one for saving them. Here we just send a message to the log if there’s a problem. In this tutorial, we just test if the anchor already exists to comply with the requirements of a coroutine.
|
public IEnumerator anchorErased(OVRSpatialAnchor osAnchor)
|
{
|
while (!osAnchor.Created)
|
{
|
yield return new WaitForEndOfFrame();
|
}
|
osAnchor.Erase((anchor, success) =>
|
{
|
if (!success)
|
{
|
Debug.Log("Anchor " + osAnchor.Uuid.ToString() + " NOT Erased!");
|
}
|
return;
|
});
|
}
|
That’s the end of the script. Save it and return to the Unity editor.
|
Create and Configure a Tutorial Manager Game Object
|
The TutorialManager Game Object connects the anchor prefab with the spatial anchor loader and the script we just wrote.
|
From the Game Object menu, choose Create Empty. Name the new object TutorialManager, and make it a peer of your scene’s OVRCameraRig.
|
In the Hierarchy Window, click the new TutorialManager game object. Then in the Inspector, select Add Component.
|
Search for and select the script you just wrote, AnchorTutorialUIManager. You’ll see the six properties you need to configure.
|
In the Project search box, search for SaveablePrefab. Drag this object to the Inspector, to the Saveable Anchor Prefab field in the Anchor Tutorial U IManager (Script) component.
|
In the Project search box, search for SaveablePlacement. Drag this object to the Inspector, to the Saveable Preview field in the Anchor Tutorial U IManager (Script) component.
|
In the Hierarchy window, expand LeftControllerAnchor > SaveablePlacement. Drag the SaveableTransform to the Inspector, to the Saveable Transform (Transform) field in the Anchor Tutorial U IManager (Script) component.
|
In the Project search box, search for NonSaveablePrefab. Drag this object to the Inspector, to the Non Saveable Anchor Prefab field in the Anchor Tutorial U IManager (Script) component.
|
In the Project search box, search for NonSaveablePlacement. Drag this object to the Inspector, to the Non Saveable Preview field in the Anchor Tutorial U IManager (Script) component.
|
In the Hierarchy window, expand RightControllerAnchor > Non SaveablePlacement. Drag the NonSaveableTransform to the Inspector, to the Non Saveable Transform (Transform) field in the Anchor Tutorial U IManager (Script) component.
|
TutorialManager Game Object
|
Check the Project Setup Tool
|
We are almost done. Before we build, we need to run the project setup tool. This is to make sure that we haven’t introduced any complications with our combination of new and existing game objects.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.