# ARAnchorManagerExtensions

Extensions to AR Foundation's `ARAnchorManager` class.

## Summary

|                                                                                                                                                                                                                                                                               ### Public static functions                                                                                                                                                                                                                                                                                ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [GetPersistState](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARAnchorManagerExtensions#getpersiststate)`(this ARAnchorManager anchorManager, ARAnchor anchor, out `[XRAnchorPersistStates](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xranchorpersiststates)` state)`                                                 | `bool` Get persistence state of the given anchor.                                                                                                                           |
| [GetPersistState](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARAnchorManagerExtensions#getpersiststate)`(this ARAnchorManager anchorManager, Guid guid, out `[XRAnchorPersistStates](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xranchorpersiststates)` state)`                                                       | `bool` Get persistence state of the given anchor by GUID.                                                                                                                   |
| [GetPersistentId](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARAnchorManagerExtensions#getpersistentid)`(this ARAnchorManager anchorManager, ARAnchor anchor)`                                                                                                                                                                                                     | `Guid` Gets the persistent id associated with the given anchor, it can be used in TryLoad(ARAnchorManager, Guid) to retrieve the persisted anchor across multiple sessions. |
| [Persist](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARAnchorManagerExtensions#persist)`(this ARAnchorManager anchorManager, ARAnchor anchor)`                                                                                                                                                                                                                     | `bool` Try to save the *anchor* on device's local storage.                                                                                                                  |
| [TryGetAllPersistedIds](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARAnchorManagerExtensions#trygetallpersistedids)`(this ARAnchorManager anchorManager, ref List< Guid > guids)`                                                                                                                                                                                  | `bool` Gets all persisted ids that are currently saved on the device's local storage.                                                                                       |
| [TryLoad](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARAnchorManagerExtensions#tryload)`(this ARAnchorManager anchorManager, Guid guid)`                                                                                                                                                                                                                           | `bool` Try to load a persisted anchor from the given *guid* .                                                                                                               |
| [Unpersist](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARAnchorManagerExtensions#unpersist)`(this ARAnchorManager anchorManager, Guid guid)`                                                                                                                                                                                                                       | `bool` Try to remove a persisted anchor from device's local storage.                                                                                                        |
| [Unpersist](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARAnchorManagerExtensions#unpersist)`(this ARAnchorManager anchorManager, ARAnchor anchor)`                                                                                                                                                                                                                 | `bool` Try to remove a persisted anchor from device's local storage.                                                                                                        |
| [WaitUntilPersistState](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARAnchorManagerExtensions#waituntilpersiststate)`(this ARAnchorManager anchorManager, Guid guid, `[XRAnchorPersistStates](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xranchorpersiststates)` targetState, Action< bool > onComplete, int timeout)` | `IEnumerator` Wait until an anchor has a given persistence state.                                                                                                           |

## Public static functions

### GetPersistState

```c#
bool GetPersistState(
  this ARAnchorManager anchorManager,
  ARAnchor anchor,
  out XRAnchorPersistStates state
)
```  
Get persistence state of the given anchor.


|                                                                                                                               Details                                                                                                                                ||
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Parameters  | |-----------------|-----------------------------------------| | `anchorManager` | The ARAnchorManager instance.           | | `anchor`        | The persisted anchor to get state from. | | `state`         | The state of the anchor.                | |
| **Returns** | Returns a boolean to indicate whether successfully got persistence state.                                                                                                                                                                               |

### GetPersistState

```c#
bool GetPersistState(
  this ARAnchorManager anchorManager,
  Guid guid,
  out XRAnchorPersistStates state
)
```  
Get persistence state of the given anchor by GUID.


|                                                                                                                                                             Details                                                                                                                                                              ||
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Parameters  | |-----------------|--------------------------------------------------------| | `anchorManager` | The ARAnchorManager instance.                          | | `guid`          | The GUID associated with the anchor to get state from. | | `state`         | The state of the anchor.                               | |
| **Returns** | Returns a boolean to indicate whether successfully got persistence state.                                                                                                                                                                                                                                           |

### GetPersistentId

```c#
Guid GetPersistentId(
  this ARAnchorManager anchorManager,
  ARAnchor anchor
)
```  
Gets the persistent id associated with the given anchor, it can be used in TryLoad(ARAnchorManager, Guid) to retrieve the persisted anchor across multiple sessions.

If *anchor* is not a persisted anchor, returns `Guid.Empty`.


|                                                                                      Details                                                                                      ||
|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Parameters  | |-----------------|----------------------------------| | `anchorManager` | The ARAnchorManager instance.    | | `anchor`        | The anchor to get persistent id. | |
| **Returns** | The persistent id of the given anchor.                                                                                                                               |

### Persist

```c#
bool Persist(
  this ARAnchorManager anchorManager,
  ARAnchor anchor
)
```  
Try to save the *anchor* on device's local storage.

If it succeeds, use either ARAnchorExtensions.GetPersistentId(ARAnchor) or GetPersistentId(ARAnchorManager, ARAnchor) to get the associated persistent id, then use TryLoad(ARAnchorManager, Guid) to retrieve the anchor from different sessions.


|                                                                                                         Details                                                                                                          ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Parameters  | |-----------------|-----------------------------------------------| | `anchorManager` | The ARAnchorManager instance.                 | | `anchor`        | The anchor to save on device's local storage. | |
| **Returns** | Returns a boolean to indicate whether the anchor was successfully saved on the device's local storage.                                                                                                      |

### TryGetAllPersistedIds

```c#
bool TryGetAllPersistedIds(
  this ARAnchorManager anchorManager,
  ref List< Guid > guids
)
```  
Gets all persisted ids that are currently saved on the device's local storage.

It can be used in TryLoad(ARAnchorManager, Guid) to retrieve the persisted anchors across multiple sessions or removed by Unpersist(ARAnchorManager, Guid).


|                                                                                 Details                                                                                  ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Parameters  | |-----------------|-------------------------------| | `anchorManager` | The ARAnchorManager instance. | | `guids`         | A list of all persisted ids.  | |
| **Returns** | Returns a boolean to indicate whether all stored ids were retrieved successfully.                                                                           |

### TryLoad

```c#
bool TryLoad(
  this ARAnchorManager anchorManager,
  Guid guid
)
```  
Try to load a persisted anchor from the given *guid* .

If it succeeds, a new ARAnchor will be returned through ARAnchorsChangedEventArgs.added list. Use either ARAnchorExtensions.GetPersistentId(ARAnchor) or GetPersistentId(ARAnchorManager, ARAnchor) to confirm if it's the requested anchor.


|                                                                                                               Details                                                                                                                ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Parameters  | |-----------------|---------------------------------------------------| | `anchorManager` | The ARAnchorManager instance.                     | | `guid`          | The Guid that represents a persisted anchor's id. | |
| **Returns** | Returns a boolean to indicate whether successfully loaded the given *guid* .                                                                                                                                            |

### Unpersist

```c#
bool Unpersist(
  this ARAnchorManager anchorManager,
  Guid guid
)
```  
Try to remove a persisted anchor from device's local storage.


|                                                                                                                        Details                                                                                                                         ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Parameters  | |-----------------|---------------------------------------------------------| | `anchorManager` | The ARAnchorManager instance.                           | | `guid`          | The persistent id associated with the anchor to remove. | |
| **Returns** | Returns a boolean to indicate whether the anchor was removed successfully from the device's local storage.                                                                                                                                |

### Unpersist

```c#
bool Unpersist(
  this ARAnchorManager anchorManager,
  ARAnchor anchor
)
```  
Try to remove a persisted anchor from device's local storage.


|                                                                                    Details                                                                                     ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Parameters  | |-----------------|---------------------------------| | `anchorManager` | The ARAnchorManager instance.   | | `anchor`        | The persisted anchor to remove. | |
| **Returns** | Returns a boolean to indicate whether the anchor was removed successfully from the device's local storage.                                                        |

### WaitUntilPersistState

```c#
IEnumerator WaitUntilPersistState(
  this ARAnchorManager anchorManager,
  Guid guid,
  XRAnchorPersistStates targetState,
  Action< bool > onComplete,
  int timeout
)
```  
Wait until an anchor has a given persistence state.


|                                                                                                                                                                                                                                                                                                                                                                                          Details                                                                                                                                                                                                                                                                                                                                                                                           ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Parameters  | |-----------------|--------------------------------------------------------------------------------------------------------| | `anchorManager` | The ARAnchorManager instance.                                                                          | | `guid`          | The GUID associated with the anchor to get state from.                                                 | | `targetState`   | The target state of the anchor.                                                                        | | `onComplete`    | Action called with "true" if anchor reaches target state. Called with false if the timeout is reached. | | `timeout`       | Optional timeout in seconds. A value of zero indicates no timeout.                                     | |
| **Returns** | A coroutine that waits until the anchor has the target state or the timeout is reached.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |