Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        ChunkList         = new Dictionary <string, GameObject>();
        ModifiedChunkList = new Dictionary <string, Chunk_Data>();
        unusedChunks      = new List <GameObject>();

        player      = GameManager.Instance.Player;
        chunkHolder = GameObject.Find("ChunkHolder");
        if (!SaveManager.SaveExist())
        {
            GeneratePlayerStart();
            GenerateObjectif();
            GenerateSnake();
        }
        else
        {
            Chunk_Data data  = SaveManager.LoadObjectifChunk();
            Vector3Int coord = new Vector3Int();
            coord.x = data.Coordonates[0];
            coord.y = data.Coordonates[1];
            coord.z = data.Coordonates[2];

            objectifChunk = LoadChunk(coord);
            objectifChunk.GetComponent <Chunk>().Unused = false;
        }
    }
Ejemplo n.º 2
0
    public static void SaveObjectifChunk(GameObject gameObject)
    {
        string          fileName = "/ObjectiveChunk.dat";
        string          path     = chunkDirectory + fileName;
        BinaryFormatter bf       = new BinaryFormatter();
        FileStream      file     = new FileStream(path, FileMode.Create);

        Chunk_Data data = new Chunk_Data(gameObject);

        bf.Serialize(file, data);
        file.Close();
    }
Ejemplo n.º 3
0
    public void LoadChunk(Vector3Int coordonate)
    {
        string     Chunkname = "Chunk" + coordonate;
        Chunk_Data data      = SaveManager.LoadChunk(Chunkname);

        if (data != null)
        {
            LoadChunk(data);
        }
        else
        {
            Init(coordonate);
        }
    }
Ejemplo n.º 4
0
    public void LoadChunk(Chunk_Data data)
    {
        Vector3Int coord = new Vector3Int();

        coord.x = data.Coordonates[0];
        coord.y = data.Coordonates[1];
        coord.z = data.Coordonates[2];

        Init(coord, data.gridValues);
        objectives.Clear();
        foreach (Objective_Data item in data.objectives)
        {
            GameObject objectif = Instantiate(GameManager.Instance.ChunkManager.Objectif);
            objectif.GetComponent <Objective>().LoadObjective(item);
            objectives.Add(objectif);
        }
    }
Ejemplo n.º 5
0
    public static Chunk_Data LoadObjectifChunk()
    {
        string fileName = "/ObjectiveChunk.dat";
        string path     = chunkDirectory + fileName;

        if (File.Exists(path))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(path, FileMode.Open);

            Chunk_Data data = (Chunk_Data)bf.Deserialize(stream);

            stream.Close();

            return(data);
        }
        else
        {
            return(null);
        }
    }
Ejemplo n.º 6
0
    public static void SaveChunk(Chunk_Data data)
    {
        if (!Directory.Exists(chunkDirectory))
        {
            Directory.CreateDirectory(chunkDirectory);
        }

        Vector3Int coord = new Vector3Int();

        coord.x = data.Coordonates[0];
        coord.y = data.Coordonates[1];
        coord.z = data.Coordonates[2];


        string fileName = "/Chunk" + coord + ".dat";
        string path     = chunkDirectory + fileName;
        // Create the Binary Formatter.
        BinaryFormatter bf = new BinaryFormatter();
        // Stream the file with a File Stream. (Note that File.Create() 'Creates' or 'Overwrites' a file.)
        FileStream file = new FileStream(path, FileMode.Create);

        bf.Serialize(file, data);
        file.Close();
    }