예제 #1
0
        public static void Save()
        {
            SavedGame       save = CreateSavedGame();
            BinaryFormatter bf   = new BinaryFormatter();

            // GetSurrogateSelector() adds the ability to serialize Vector3, Vector3Int and Quaternion
            bf.SurrogateSelector = GetSurrogateSelector();

            FileStream file = File.Create(Application.persistentDataPath + "/savedGame.bg");

            bf.Serialize(file, save);
            file.Close();

            Debug.Log("Game Saved");
        }
예제 #2
0
 public void Load(SavedGame game)
 {
     place = game.place;
     // I need to initiate the componentList of the group. It doesn't exist as it can't be serialised
     foreach (SavedComponent data in game.components)
     {
         GameObject      go = Instantiate(TemplateController.Instance.templates[data.template].prefab);
         BeyondComponent bc = go.AddComponent <BeyondComponent>();
         bc.LoadComponent(data);
         go.SetActive(false);
         go.transform.position = data.position;
         go.transform.rotation = data.rotation;
         go.name  = data.name;
         go.layer = data.layer;
         go.GetComponent <BoxCollider>().isTrigger = data.isTrigger;
         go.GetComponent <BoxCollider>().enabled   = data.enabled;
         go.SetActive(true);
         place.beyondGroups.Find(group => group == data.group).addBeyondComponent(bc);
     }
 }
예제 #3
0
        public static void Load()
        {
            if (File.Exists(Application.persistentDataPath + "/savedGame.bg"))
            {
                BinaryFormatter bf = new BinaryFormatter();
                // GetSurrogateSelector() adds the ability to serialize Vector3, Vector3Int and Quaternion
                bf.SurrogateSelector = GetSurrogateSelector();

                FileStream file      = File.Open(Application.persistentDataPath + "/savedGame.bg", FileMode.Open);
                SavedGame  savedGame = (SavedGame)bf.Deserialize(file);
                file.Close();

                FirstPersonController.Instance.Load(savedGame);
                FirstPersonMouseLook.Instance.Load(savedGame);
                PlaceController.Instance.Load(savedGame);
                Debug.Log("Game Loaded" + savedGame.ShowMe());
            }
            else
            {
                Debug.Log("No saved game file found.");
            }
        }
예제 #4
0
        public static SavedGame CreateSavedGame()
        {
            SavedGame save = new SavedGame();

            save.place = PlaceController.Instance.place;
            FirstPersonController.Instance.Save(ref save);
            FirstPersonMouseLook.Instance.Save(ref save);
            // Place has a list of BeyondGroup, but they don't save their components (can't serialize monobehaviour)
            // Do it by hand
            save.components = new List <SavedComponent>();
            foreach (BeyondGroup bg in save.place.beyondGroups)
            {
                foreach (BeyondComponent bc in bg.componentList)
                {
                    //TODO : but wait, how can a group have a null BC ? there's something rotten
                    if (bc != null)
                    {
                        SavedComponent sc = new SavedComponent(bc);
                        save.components.Add(sc);
                    }
                }
            }
            return(save);
        }
예제 #5
0
 public void Load(SavedGame game)
 {
     transform.rotation = game.fplook_rotation;
 }
예제 #6
0
 public void Save(ref SavedGame game)
 {
     game.fplook_rotation = transform.rotation;
 }
예제 #7
0
 public void Save(ref SavedGame game)
 {
     game.fp_position = transform.position;
     game.fp_rotation = transform.rotation;
 }
예제 #8
0
 public void LoadGame()
 {
     SavedGame.Load();
 }
예제 #9
0
 public void SaveGame()
 {
     SavedGame.Save();
 }