text
stringlengths
0
1.11k
}
});
}
}
/******************* Load Anchor Methods **********************/
public void LoadAllAnchors()
{
OVRSpatialAnchor.LoadOptions options = new OVRSpatialAnchor.LoadOptions
{
Timeout = 0,
StorageLocation = OVRSpace.StorageLocation.Local,
Uuids = GetSavedAnchorsUuids() //GetAnchorsUuidsFromExternalStore()
};
//load and localize
OVRSpatialAnchor.LoadUnboundAnchors(options, _anchorSavedUUIDList =>
{
if (_anchorSavedUUIDList == null)
{
//Debug.Log("Anchor list is null!");
return;
}
foreach (var anchor in _anchorSavedUUIDList)
{
if (anchor.Localized)
{
_onLoadAnchor(anchor, true);
}
else if (!anchor.Localizing)
{
anchor.Localize(_onLoadAnchor);
}
}
});
}
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);
}
/*
* Get all spatial anchor UUIDs 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;
}
/******************* Erase Anchor Methods *****************/
/*
* If the Y button is pressed, erase all anchors saved
* in the headset, but don't destroy them. They should remain
* displayed.
*/
public void EraseAllAnchors()
{
foreach (var tmpAnchor in _allSavedAnchors)
{
//use a Unity coroutine to manage the async save
StartCoroutine(anchorErased(tmpAnchor));
}
//we also erase our reference lists
_allSavedAnchors.Clear();
RemoveAllAnchorsUuidsInExternalStore();
return;
}
/*
* Unity Coroutine
* We need to make sure the anchor is ready to use before we erase it.
*/