コード例 #1
0
ファイル: SaveSystem.cs プロジェクト: Chaos-And-Art/2048-Game
    public static void SaveGame2(GameManager4x4 gameManager4x4)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/Game2.data";
        FileStream      stream    = new FileStream(path, FileMode.Create);

        SavedData2 data = new SavedData2(gameManager4x4);

        formatter.Serialize(stream, data);
        stream.Close();
    }
コード例 #2
0
ファイル: SaveSystem.cs プロジェクト: Chaos-And-Art/2048-Game
    public static SavedData2 LoadGame2()
    {
        string path = Application.persistentDataPath + "/Game2.data";

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

            SavedData2 data = formatter.Deserialize(stream) as SavedData2;
            stream.Close();
            return(data);
        }
        else
        {
            Debug.Log("Save File Cannot be found in " + path);
            return(null);
        }
    }
コード例 #3
0
    public void LoadGame2(int index)
    {
        SavedData2 data = SavingSystem.LoadGame2();
        string     Tile = "Tiles";

        if (PlayerPrefs.GetInt("Theme") == 0 || PlayerPrefs.GetInt("FirstTime") == 1)
        {
            foreach (Transform tile in PlayGrid)
            {
                Destroy(tile.gameObject);
            }
        }
        else if (PlayerPrefs.GetInt("Theme") == 1)
        {
            foreach (Transform tile in PlayGrid)
            {
                Destroy(tile.gameObject);
            }
        }
        for (i = 0; i < data.posX2.Count; i++)
        {
            x = data.posX2[index];
            y = data.posY2[index];

            Grid[x, y] = (GameObject)Instantiate(Resources.Load(Tile), new Vector2(data.posX2[index] * 1.1f, data.posY2[index] * 1.1f), Quaternion.identity);
            if (PlayerPrefs.GetInt("Theme") == 0 || PlayerPrefs.GetInt("FirstTime") == 1)
            {
                Grid[x, y].transform.SetParent(PlayGrid);
            }
            else if (PlayerPrefs.GetInt("Theme") == 1)
            {
                Grid[x, y].transform.SetParent(PlayGrid);
            }
            Grid[x, y].GetComponent <Tiles>().Number = data.tileNumber2[index];
            index++;
        }
        theScore = data.score2;
    }