Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Linq;
  5. using System.Text;
  6. using System.IO;
  7. using System.Runtime.Serialization;
  8. using System.Runtime.Serialization.Formatters.Binary;
  9.  
  10. [Serializable()]
  11. public class GameData
  12. {
  13.     #region Fields
  14.  
  15.         private GameManager manager;
  16.         private int score;
  17.  
  18.     #endregion
  19.  
  20.     #region Properties
  21.  
  22.     #endregion
  23.  
  24.     #region functions
  25.  
  26.         void Start()
  27.         {
  28.             manager = (GameManager)GameObject.FindObjectOfType(typeof(GameManager));
  29.             score = manager.score;
  30.         }
  31.  
  32.         public static void SaveThisGameData()
  33.         {
  34.             //serialize the game data here
  35.             FileStream fs = new FileStream("Game.Data", FileMode.Create);
  36.             BinaryFormatter bf = new BinaryFormatter();
  37.             bf.Serialize(fs, manager.score);
  38.             fs.Close();
  39.  
  40.         }
  41.  
  42.         public static void LoadThisGameData()
  43.         {
  44.             //deserialize the game data here
  45.  
  46.             FileStream fs = new FileStream("Game.Data", FileMode.Create);
  47.             BinaryFormatter bf = new BinaryFormatter();
  48.              score = (int) bf.Deserialize(fs);
  49.             fs.Close();
  50.  
  51.         }
  52.  
  53.     #endregion
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement