Ejemplo n.º 1
0
    public void SaveScene(string pathToFile)
    {
        //Load all StatsData objects from each GameObject in Inventory
        //Persist them via the FileData object
        FileData  fileData = new FileData();
        StatsData statsData;

        if (transform.childCount > 0)
        {
            foreach (Transform child in transform)
            {
                GameObject obj  = transform.gameObject;
                string     type = obj.GetType().Name;
                statsData = ((DataHolder)child.GetComponent <DataHolder> ()).StatsData;
                fileData.AddStatsData(statsData);
            }
        }
        Debug.Log("saving scene");

        FileStream fileStream = File.Open(pathToFile, FileMode.Create);

        try {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(fileStream, fileData);
        } catch (Exception e) {
            Debug.LogWarning("Save.SaveScene(): Failed to serialize object to a file " + filename + " (Reason: " + e.ToString() + ")");
        } finally {
            fileStream.Close();
        }
    }
    public void SaveScene(string pathToFile)
    {
        //Load all StatsData objects from each GameObject in Inventory
        //Persist them via the FileData object
        FileData fileData = new FileData ();
        StatsData statsData;
        if (transform.childCount > 0) {
            foreach (Transform child in transform) {
                GameObject obj = transform.gameObject;
                string type = obj.GetType ().Name;
                statsData = ((DataHolder)child.GetComponent<DataHolder> ()).StatsData;
                fileData.AddStatsData (statsData);
            }
        }
        Debug.Log ("saving scene");

        FileStream fileStream = File.Open (pathToFile, FileMode.Create);
        try {
            BinaryFormatter formatter = new BinaryFormatter ();
            formatter.Serialize (fileStream, fileData);
        } catch (Exception e) {
            Debug.LogWarning ("Save.SaveScene(): Failed to serialize object to a file " + filename + " (Reason: " + e.ToString () + ")");
        } finally {
            fileStream.Close ();
        }
    }