private void UpdatePendingCloudAnchors() { foreach (var cloudAnchor in _pendingCloudAnchors) { if (cloudAnchor.cloudAnchorState == CloudAnchorState.Success) { if (Controller.Mode == PersistentCloudAnchorsController.ApplicationMode.Hosting) { Debug.LogFormat("Succeed to host the Cloud Anchor: {0}.", cloudAnchor.cloudAnchorId); int count = Controller.LoadCloudAnchorHistory().Collection.Count; _hostedCloudAnchor = new CloudAnchorHistory("CloudAnchor" + count, cloudAnchor.cloudAnchorId); OnAnchorHostedFinished(true, cloudAnchor.cloudAnchorId); } else if (Controller.Mode == PersistentCloudAnchorsController.ApplicationMode.Resolving) { Debug.LogFormat("Succeed to resolve the Cloud Anchor: {0}", cloudAnchor.cloudAnchorId); OnAnchorResolvedFinished(true, cloudAnchor.cloudAnchorId); Instantiate(CloudAnchorPrefab, cloudAnchor.transform); } _cachedCloudAnchors.Add(cloudAnchor); } else if (cloudAnchor.cloudAnchorState != CloudAnchorState.TaskInProgress) { if (Controller.Mode == PersistentCloudAnchorsController.ApplicationMode.Hosting) { Debug.LogFormat("Failed to host the Cloud Anchor with error {0}.", cloudAnchor.cloudAnchorState); OnAnchorHostedFinished(false, cloudAnchor.cloudAnchorState.ToString()); } else if (Controller.Mode == PersistentCloudAnchorsController.ApplicationMode.Resolving) { Debug.LogFormat("Failed to resolve the Cloud Anchor {0} with error {1}.", cloudAnchor.cloudAnchorId, cloudAnchor.cloudAnchorState); OnAnchorResolvedFinished(false, cloudAnchor.cloudAnchorId, cloudAnchor.cloudAnchorState.ToString()); } _cachedCloudAnchors.Add(cloudAnchor); } } _pendingCloudAnchors.RemoveAll( x => x.cloudAnchorState != CloudAnchorState.TaskInProgress); }
/// <summary> /// Save the persistent Cloud Anchors history to local storage, /// also remove the oldest data if current storage has met maximal capacity. /// </summary> /// <param name="data">The Cloud Anchor history data needs to be stored.</param> public void SaveCloudAnchorHistory(CloudAnchorHistory data) { var history = LoadCloudAnchorHistory(); // Sort the data from latest record to oldest record which affects the option order in // multiselection dropdown. history.Collection.Add(data); history.Collection.Sort((left, right) => right.CreatedTime.CompareTo(left.CreatedTime)); // Remove the oldest data if the capacity exceeds storage limit. if (history.Collection.Count > _storageLimit) { history.Collection.RemoveRange( _storageLimit, history.Collection.Count - _storageLimit); } PlayerPrefs.SetString(_persistentCloudAnchorsStorageKey, JsonUtility.ToJson(history)); }