static public int constructor(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); UnityEngine.UI.Extensions.SaveGame o; if (argc == 1) { o = new UnityEngine.UI.Extensions.SaveGame(); pushValue(l, o); return(1); } else if (argc == 3) { System.String a1; checkType(l, 2, out a1); System.Collections.Generic.List <UnityEngine.UI.Extensions.SceneObject> a2; checkType(l, 3, out a2); o = new UnityEngine.UI.Extensions.SaveGame(a1, a2); pushValue(l, o); return(1); } return(error(l, "New object failed.")); } catch (Exception e) { return(error(l, e)); } }
static public int get_sceneObjects(IntPtr l) { try { UnityEngine.UI.Extensions.SaveGame self = (UnityEngine.UI.Extensions.SaveGame)checkSelf(l); pushValue(l, self.sceneObjects); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_sceneObjects(IntPtr l) { try { UnityEngine.UI.Extensions.SaveGame self = (UnityEngine.UI.Extensions.SaveGame)checkSelf(l); System.Collections.Generic.List <UnityEngine.UI.Extensions.SceneObject> v; checkType(l, 2, out v); self.sceneObjects = v; return(0); } catch (Exception e) { return(error(l, e)); } }
static public int set_savegameName(IntPtr l) { try { UnityEngine.UI.Extensions.SaveGame self = (UnityEngine.UI.Extensions.SaveGame)checkSelf(l); System.String v; checkType(l, 2, out v); self.savegameName = v; return(0); } catch (Exception e) { return(error(l, e)); } }
public static void Save(SaveGame saveGame) { BinaryFormatter bf = new BinaryFormatter(); // 1. Construct a SurrogateSelector object SurrogateSelector ss = new SurrogateSelector(); // 2. Add the ISerializationSurrogates to our new SurrogateSelector AddSurrogates(ref ss); // 3. Have the formatter use our surrogate selector bf.SurrogateSelector = ss; //Application.persistentDataPath is a string, so if you wanted you can put that into debug.log if you want to know where save games are located //You can also use any path you like CheckPath(saveGamePath); FileStream file = File.Create(saveGamePath + saveGame.savegameName + ".sav"); //you can call it anything you want including the file extension bf.Serialize(file, saveGame); file.Close(); Debug.Log("Saved Game: " + saveGame.savegameName); }
//use this one for specifying a filename public void SaveGame(string saveGameName) { if (string.IsNullOrEmpty(saveGameName)) { Debug.Log("SaveGameName is null or empty!"); return; } SaveLoad.saveGamePath = savePath; //Create a new instance of SaveGame. This will hold all the data that should be saved in our scene. SaveGame newSaveGame = new SaveGame(); newSaveGame.savegameName = saveGameName; List<GameObject> goList = new List<GameObject>(); //Find all ObjectIdentifier components in the scene. //Since we can access the gameObject to which each one belongs with .gameObject, we thereby get all GameObject in the scene which should be saved! ObjectIdentifier[] objectsToSerialize = FindObjectsOfType(typeof(ObjectIdentifier)) as ObjectIdentifier[]; //Go through the "raw" collection of components foreach (ObjectIdentifier objectIdentifier in objectsToSerialize) { //if the gameObject shouldn't be saved, for whatever reason (maybe it's a temporary ParticleSystem that will be destroyed anyway), ignore it if (objectIdentifier.dontSave == true) { Debug.Log("GameObject " + objectIdentifier.gameObject.name + " is set to dontSave = true, continuing loop."); continue; } //First, we will set the ID of the GO if it doesn't already have one. if (string.IsNullOrEmpty(objectIdentifier.id) == true) { objectIdentifier.SetID(); } //store it in the goList temporarily, so we can first set it's ID (done above), //then go through the list and call all OnSerialize methods on it, //and finally go through the list again to pack the GO and add the packed data to the sceneObjects list of the new SaveGame. goList.Add(objectIdentifier.gameObject); } //This is a good time to call any functions on the GO that should be called before it gets serialized as part of a SaveGame. Example below. foreach (GameObject go in goList) { go.SendMessage("OnSerialize", SendMessageOptions.DontRequireReceiver); } foreach (GameObject go2 in goList) { //Convert the GameObject's data into a form that can be serialized (an instance of SceneObject), //and add it to the SaveGame instance's list of SceneObjects. newSaveGame.sceneObjects.Add(PackGameObject(go2)); } //Call the static method that serialized our game and writes the data to a file. SaveLoad.Save(newSaveGame); }