public void Write(UserProgressData userProgress)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(userProgressPath);

        bf.Serialize(file, userProgress);
        file.Close();
    }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            UserProgressData userProgressData = await db.UserProgressData.FindAsync(id);

            db.UserProgressData.Remove(userProgressData);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "UserProgressDataId,UserId,DataReferenceId,DataReferenceType,Progress,Result,DateStarted,DateCompleted")] UserProgressData userProgressData)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userProgressData).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(userProgressData));
        }
        // GET: UserProgressData/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserProgressData userProgressData = await db.UserProgressData.FindAsync(id);

            if (userProgressData == null)
            {
                return(HttpNotFound());
            }
            return(View(userProgressData));
        }
Example #5
0
 public static void LoadFromLocal()
 {
     // Cek apakah ada data yang tersimpan sebagai PROGRESS_KEY
     if (!PlayerPrefs.HasKey(PROGRESS_KEY))
     {
         // Jika tidak ada, maka buat data baru
         //Progress = new UserProgressData();
         Save(true);
     }
     else
     {
         // Jika ada, maka timpa progress dengan yang sebelumnya
         string json = PlayerPrefs.GetString(PROGRESS_KEY);
         Progress = JsonUtility.FromJson <UserProgressData>(json);
     }
 }
Example #6
0
    public static IEnumerator LoadFromCloud(System.Action onComplete)
    {
        StorageReference targetStorage = GetTargetCloudStorage();

        bool       isCompleted    = false;
        bool       isSuccessfull  = false;
        const long maxAllowedSize = 1024 * 1024; // Sama dengan 1 MB

        targetStorage.GetBytesAsync(maxAllowedSize).ContinueWith((Task <byte[]> task) =>
        {
            if (!task.IsFaulted)
            {
                string json   = Encoding.Default.GetString(task.Result);
                Progress      = JsonUtility.FromJson <UserProgressData>(json);
                isSuccessfull = true;
            }

            isCompleted = true;
        });

        while (!isCompleted)
        {
            yield return(null);
        }

        // Jika sukses mendownload, maka simpan data hasil download
        if (isSuccessfull)
        {
            Save();
        }
        else
        {
            // Jika tidak ada data di cloud, maka load data dari local
            LoadFromLocal();
        }
        onComplete?.Invoke();
    }
 public static void Init()
 {
     Data = new UserProgressIO().Read();
     Save();
 }