リローカリゼーションが成功した際の処理
リローカライズに成功した場合は OnRelocalized
イベントを呼ぶことができます。
// ARSharedAnchorManager.cs
// Attach a callback to this event to listen for successful relocalization
public delegate void RelocalizedEvent();
public event RelocalizedEvent OnRelocalized;
// Alternatively, you can attach a callback to specific map relocalization events
public delegate void MapRelocalizationEvent(string mapKey);
public event MapRelocalizationEvent OnMapRelocalizationStarted;
public event ImageRelocalizationEvent OnMapRelocalized;
// or image relocalization events
public delegate void ImageRelocalizationEvent(XRReferenceImage referenceImage);
public event ImageRelocalizationEvent OnImageRelocalizationStarted;
public event ImageRelocalizationEvent OnImageRelocalized;
活用例
[SerializeField]
private ARSharedAnchorManager _sharedAnchorManager;
private void OnEnable()
{
// Subscribe to event
_sharedAnchorManager.OnRelocalized += ShowContent;
_sharedAnchorManager.OnImageRelocalized += ShowContentByReferenceImage;
_sharedAnchorManager.OnMapRelocalized += ShowContentByMapKey;
}
private void OnDisable()
{
// Unsubscribe to event
_sharedAnchorManager.OnRelocalized -= ShowContent;
_sharedAnchorManager.OnImageRelocalized -= ShowContentByReferenceImage;
_sharedAnchorManager.OnMapRelocalized -= ShowContentByMapKey;
}
private void ShowContent()
{
// Do something to show your content e.g.,
// contentGameObject.SetActive(true);
}
private void ShowContentByReferenceImage(XRReferenceImage referenceImage)
{
// Do something to show your content depending on the reference image e.g.,
// contentGameObject.SetActive(true);
}
private void ShowContentByMapKey(string mapKey)
{
// Do something to show your content depending on the map key e.g.,
// contentGameObject.SetActive(true);
}