Beispiel #1
0
 public static SaveStateInfo GetSaveDescription(int slot)
 {
     if (!SaveExists(slot))
     {
         return(null);
     }
     return((SaveStateInfo)IOTools.LoadFromFile(GetGameStatePath(slot, infoExtension)));
 }
Beispiel #2
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();
            }
        }
Beispiel #3
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;
            }
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }