Implementing Cloud Save and Load
1. CloudSaveAnchor
namespace NRKernal.Persistence
{
// ... Other codes ...
public class NRWorldAnchorStore : IDisposable
{
// ... Other codes ...
public const string CloudAnchor2ObjectFile = "cloud_anchor2object.json";
/// <summary>save an anchor to firebase cloud server</summary>
public async Task<bool> CloudSaveAnchor(NRWorldAnchor anchor)
{
NRDebugger.Info("[NRWorldAnchorStore] Cloud save Anchor: {0}", anchor.UserDefinedKey);
string localFilename = Path.Combine(MapPath, anchor.UUID);
Debug.LogError("UploadFile: "+localFilename);
NRDebugger.Info("[NRWorldAnchorStore] UploadFile:" + localFilename);
FirebaseStorageManager storageManager = FirebaseStorageManager.Instance;
await storageManager.UploadFile(anchor.UUID, localFilename);
// Update the cloud anchor to object dictionary
// Save the dictionary to a JSON file
string json = LitJson.JsonMapper.ToJson(m_Anchor2ObjectDict);
string path = Path.Combine(MapPath, CloudAnchor2ObjectFile);
NRDebugger.Info("[NRWorldAnchorStore] Save to the path for next upload:" + path + " json:" + json);
File.WriteAllText(path, json);
// Upload the JSON file to the cloud
await storageManager.UploadFile(CloudAnchor2ObjectFile, path);
return true;
}
}
// ... Other codes ...
}
}
2. CloudSave
3. CloudLoad
Test
CloudSave:





Firebase Console
CloudLoad
Last updated
Was this helpful?
