예제 #1
0
    public void SaveToFile(string fileName)
    {
        if (fileName == "" || fileName == null)
        {
            Debug.Log("No file specified to save");
            return;
        }
        EasyFileSave saveFile = new EasyFileSave(fileName);

        Debug.Log("Filename:" + saveFile.GetFileName());
        try
        {
            object[] obj = Resources.FindObjectsOfTypeAll <SerializedObject>(); //this ensures disabled object are also considered
            //object[] obj = Resources.FindObjectsOfType(typeof (SerializedObject)); //this ignores disabled objects
            foreach (object o in obj)
            {
                SerializedObject g = (SerializedObject)o;
                if (g.UUID == "")
                {
                    continue;
                }

                saveFile.AddBinary(g.UUID, g.getSaveData());
                //Debug.Log(g.UUID + " is saved");
            }
            saveFile.Save();
            PlayerPrefs.SetString("LastCheckPoint", fileName);
            PlayerPrefs.Save();
            Debug.Log("saving done");
        } catch (Exception e) {
            Debug.Log("Exception while saving file:" + e);
        } finally {
            saveFile.Dispose();
        }
    }