Beispiel #1
0
        public void ClearData(string userId, bool overrideFiles = true)
        {
            loadedUserId = userId;
            cachedStoredData.Clear();

            if (overrideFiles)
            {
                Save();
            }
            else
            {
                string path = GetSavePath(userId);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }

            hasLoaded = true;
            OnUserPersistanceReloaded?.Invoke();
        }
Beispiel #2
0
        public void LoadUser(string userId)
        {
            if (userId == null || string.Empty.CompareTo(userId) == 0)
            {
                Debug.LogError("Trying to load Empty User, fallbacking to defaultUser");
                userId = DEFAULT_USER;
            }

            string path = GetSavePath(userId);

            if (!File.Exists(path))
            {
                Debug.Log("No Save file found in " + path);
                ClearData(userId, false);
                return;
            }

            FileStream             stream  = new FileStream(path, FileMode.Open);
            UserPersistanceStorage storage = formatter.Deserialize(stream) as UserPersistanceStorage;

            stream.Close();

            if (storage == null)
            {
                Debug.LogError("Invalid format stored in path " + path);
                ClearData(userId, false);
                return;
            }

            cachedStoredData.Clear();
            for (int i = 0; i < storage.keys.Length; i++)
            {
                cachedStoredData.Add(storage.keys[i], storage.values[i]);
            }
            loadedUserId = userId;
            hasLoaded    = true;
            OnUserPersistanceReloaded?.Invoke();
        }