Esempio n. 1
0
    /// <summary>
    /// Method gather data to structure and save it to file
    /// </summary>
    public void SaveTimers()
    {
        string     destination = Application.persistentDataPath + "/save.dat";
        FileStream file;

        if (File.Exists(destination))
        {
            File.Delete(destination);
        }
        BinaryFormatter bf = new BinaryFormatter();

        float[][] Timers    = new float[allJunctions.Count][];
        int[][]   eqCounter = new int[allJunctions.Count][];
        for (int i = 0; i < allJunctions.Count; i++)
        {
            Timers[i]    = allJunctions[i].timers;
            eqCounter[i] = new int[allJunctions[i].paths.Count];
            for (int j = 0; j < allJunctions[i].paths.Count; j++)
            {
                eqCounter[i][j] = allJunctions[i].paths[j].entireQueue;
            }
        }
        SavingStructure sav = new SavingStructure {
            Timers    = Timers,
            eqCounter = eqCounter
        };

        file = File.Create(destination);
        bf.Serialize(file, sav);
        file.Close();
        Debug.Log("File saved");
    }
Esempio n. 2
0
    /// <summary>
    /// Method load file and fill certain objects
    /// </summary>
    public void LoadTimers()
    {
        string     destination = Application.persistentDataPath + "/save.dat";
        FileStream file;

        if (File.Exists(destination))
        {
            file = File.OpenRead(destination);
        }
        else
        {
            Debug.Log("File not found");
            return;
        }
        BinaryFormatter bf  = new BinaryFormatter();
        SavingStructure sav = (SavingStructure)bf.Deserialize(file);

        float[][] Timers    = sav.Timers;
        int[][]   eqCounter = sav.eqCounter;

        if (allJunctions.Count != Timers.Length)
        {
            return;
        }
        for (int i = 0; i < allJunctions.Count; i++)
        {
            allJunctions[i].timers = Timers[i];
            if (allJunctions[i].paths.Count == eqCounter[i].Length)
            {
                for (int j = 0; j < allJunctions[i].paths.Count; j++)
                {
                    allJunctions[i].paths[j].entireQueue = eqCounter[i][j];
                }
            }
        }
        file.Close();
        Debug.Log("File loaded");
    }