using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System .Serializable]
public class GameDate
{
public static bool IsAgainGame =false ;
private bool isFirstGame;
private bool isMusicOn;
private int[] bestScoreArr;
private int selectSkin;
private bool[] skinUnlocked;
private int diamondCount;
public void SetIsFirstGame(bool isFirstGame)
{
this.isFirstGame = isFirstGame;
}
public void SetMusicOn(bool isMusicOn)
{
this.isMusicOn = isMusicOn;
}
public void SetBestScoreArr(int[] bestScoreArr)
{
this.bestScoreArr = bestScoreArr;
}
public void SetSelectSkin(int selectSkin)
{
this.selectSkin = selectSkin;
}
public void SetSkinUnlocked(bool [] skinUnlocked)
{
this.skinUnlocked = skinUnlocked;
}
public void SetDiamondCount (int diamondCount)
{
this.diamondCount = diamondCount;
}
public bool GetIsFirstGame()
{
return isFirstGame;
}
public bool GetMusicOn()
{
return isMusicOn ;
}
public int [] GetBestScoreArr()
{
return bestScoreArr;
}
public int GetSelectSkin()
{
return selectSkin;
}
public bool [] GetUnlockedSkin()
{
return skinUnlocked;
}
public int GetDiamongCount()
{
return diamondCount;
}
}
/// <summary>
/// 储存数据
/// </summary>
private void Save()
{
try
{
BinaryFormatter bf = new BinaryFormatter();
using (FileStream fs = File.Create(Application.persistentDataPath + "/DameData.data"))
{
data.SetBestScoreArr(bestScoreArr);
data.SetDiamondCount(diamondCount);
data.SetIsFirstGame(isFirstGame);
data.SetMusicOn(isMusicOn);
data.SetSelectSkin(selectSkin);
data.SetSkinUnlocked(skinUnlocked);
bf.Serialize(fs, data);
}
}
catch (System.Exception e)
{
Debug.Log(e.Message);
}
}
/// <summary>
/// 读取数据
/// </summary>
private void Read()
{
try
{
BinaryFormatter bf = new BinaryFormatter();
using (FileStream fs = File .Open (Application.persistentDataPath + "/DameData.data",FileMode.Open ))
{
data = (GameDate )bf.Deserialize(fs);
}
}
catch (System.Exception e)
{
Debug.Log(e.Message);
}
}
//初始化
public void ResetData()
{
isFirstGame = false;
isMusicOn = true;
bestScoreArr = new int[3];
selectSkin = 0;
skinUnlocked = new bool[vars.skinSpriteList.Count];
skinUnlocked[0] = true;
diamondCount = 10;
data = new GameDate();//初始化时读取
Save();
}
}