CloudSaveManager
using System.Collections.Generic; using Unity.Services.Authentication; using Unity.Services.CloudSave; using UnityEngine; public class CloudSaveManager : MonoBehaviour { public static CloudSaveManager Instance; private void Awake() { if (Instance == null) { Instance = this; } else { Destroy(this); } } public async void SaveData() { var playerData = new Dictionary<string, object>{ {"playerID", AuthenticationService.Instance.PlayerId}, {"uc", 5000} }; await CloudSaveService.Instance.Data.Player.SaveAsync(playerData); Debug.Log($"Saved data {string.Join(',', playerData)}"); } public async void LoadData() { var playerData = await CloudSaveService.Instance.Data.Player.LoadAsync(new HashSet<string> { "playerID", "uc" }); if (playerData.TryGetValue("playerID", out var playerID)) { Debug.Log($"firstKeyName value: {playerID.Value.GetAs<string>()}"); } if (playerData.TryGetValue("uc", out var uc)) { Debug.Log($"secondKey value: {uc.Value.GetAs<int>()}"); } } }
Leave a Comment