示例#1
0
        public static void SaveGame(int slot)
        {
            if (GameManager.isInMainMenuScene)
            {
                Debug.LogWarning("Cant save in main menu scene");
                return;
            }
            Debug.Log("Saving game to slot: " + slot);

            Debug.Log("On Save Game Event");
            // let everyone know we're saving
            if (onSaveGame != null)
            {
                onSaveGame(SceneLoading.currentLoadedScenes);
            }


            Debug.Log("Saving Info To File");
            // keep track of the scene we were in when saving
            // save the description info
            IOTools.SaveToFile(new SaveStateInfo(SceneLoading.playerScene), GetGameStatePath(slot, infoExtension));

            Debug.Log("Saving Game State To File");
            // save the actual game state
            IOTools.SaveToFile(gameSaveState.state, GetGameStatePath(slot, saveExtension));
        }
示例#2
0
 public static SaveStateInfo GetSaveDescription(int slot)
 {
     if (!SaveExists(slot))
     {
         return(null);
     }
     return((SaveStateInfo)IOTools.LoadFromFile(GetGameStatePath(slot, infoExtension)));
 }
示例#3
0
        static void RefreshLocations(Scene scene, string path)
        {
            string sceneName = scene.name;

            List <LocationTemplate> templates = GetAllLocationTemplates(scene);

            if (templates.Count == 0)
            {
                return;
            }

            Debug.Log("Refreshing Locations List for scene " + sceneName);

            List <LocationDefenition> allLocations = new List <LocationDefenition>();

            AddNonAreaLocations(templates, sceneName, allLocations);
            AddAreaLocations(templates, sceneName, allLocations);

            if (allLocations.Count == 0)
            {
                return;
            }

            Dictionary <string, LocationDefenition> locationDict = new Dictionary <string, LocationDefenition>();

            for (int i = 0; i < allLocations.Count; i++)
            {
                locationDict.Add(allLocations[i].name, allLocations[i]);
            }

            string directory = Locations.GetLocationsObjectDirectory();

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            string filePath = Locations.GetLocationsObjectPath();
            Dictionary <string, Dictionary <string, LocationDefenition> > existing;

            if (File.Exists(filePath))
            {
                Debug.Log("Updating Locations File: " + filePath);
                existing            = (Dictionary <string, Dictionary <string, LocationDefenition> >)IOTools.LoadFromFile(filePath);
                existing[sceneName] = locationDict;
            }
            else
            {
                Debug.Log("Creating Locations File: " + filePath);
                existing = new Dictionary <string, Dictionary <string, LocationDefenition> > ()
                {
                    { sceneName, locationDict }
                };
            }
            IOTools.SaveToFile(existing, filePath);
        }
示例#4
0
        // call when we're done editng any settings, or when we're quittin ghte application
        public static void SaveSettingsOptions()
        {
            // let everyone know we're saving settings
            if (onSettingsSave != null)
            {
                onSettingsSave();
            }

            IOTools.SaveToFile(settingsSaveState.state, settingsSavePath);
        }
示例#5
0
        // call when starting up game
        static void LoadSettingsOptions()
        {
            string savePath = settingsSavePath;

            if (!File.Exists(savePath))
            {
                return;
            }
            settingsSaveState.SetState((Dictionary <string, object>)IOTools.LoadFromFile(savePath));
            if (onSettingsLoaded != null)
            {
                onSettingsLoaded();
            }
        }
示例#6
0
        static void _LoadGame(int slot)
        {
            string savePath = GetGameStatePath(slot, saveExtension);

            if (!File.Exists(savePath))
            {
                Debug.LogError("No Save File Found For Slot " + slot);
                return;
            }

            Debug.Log("Loading game slot " + slot);

            isLoadingSave = true;

            // try and load teh scene from the save state:

            // load the actual save state (if the scene starts loading)
            Action <LoadSceneMode> onSceneStartLoad = (m) => {
                Debug.Log("Loading State From File");
                gameSaveState.SetState((Dictionary <string, object>)IOTools.LoadFromFile(savePath));

                Debug.Log("On Load Game Event");
                if (onGameLoaded != null)
                {
                    onGameLoaded();
                }
            };

            // when the scene is done loading, set 'isLoadingSave' to false
            Action <string, LoadSceneMode> onSceneLoaded = (s, m) => isLoadingSave = false;

            Debug.Log("Getting Save Descriptor");
            SaveStateInfo descriptor = GetSaveDescription(slot);

            Debug.Log("Loading Saved Scene: " + descriptor.sceneName);
            // if theres a problem and this returns false, set 'isLoadingSave' to false
            if (!SceneLoading.LoadSceneAsync(descriptor.sceneName, onSceneStartLoad, onSceneLoaded, LoadSceneMode.Single, false))
            {
                isLoadingSave = false;
            }
        }
示例#7
0
        public static Dictionary <string, Dictionary <string, LocationDefenition> > LoadAllLocations()
        {
            string path = GetLocationsObjectPath();

            if (File.Exists(path))
            {
                return((Dictionary <string, Dictionary <string, LocationDefenition> >)IOTools.LoadFromFile(path));
            }
            return(null);
        }