private const string SCOREKEY = "Score";
private const string LEVELKEY = "Level";
private const string POINTKEY = "Point";
private const string SAVEDFIRSTRUNKEY = "savedFirstRun";
private int checkFirstRun;
public static int Score{private set; get;}
private static int _point = 2000;
public static int Point{
get{ return _point;}
private set{ _point = value;}
}
private static int _level = 1;
public static int Level{
get{ return _level;}
private set{ _level = value;}
}
private bool isLoadedGame = false;
void Awake()
{
LoadElapseData();
if(checkFirstRun == 0)
{
Point = 2000;
Debug.Log("FirstLaunch: Point: " + Point);
checkFirstRun = 1;
}
else{ }
}
void OnApplicationPause(bool pauseStatus)
{
//離れる時
if(pauseStatus) SaveToDisc();
//戻る時
else{
#if UNITY_EDITOR
//ゲームシーンから再生時OnApplicationPauseが呼ばれてしまうのでLoadElapseData();を呼ばない
Debug.Log("OnApplicationPause in UnityEditor");
#else
Debug.Log("OnApplicationPause in except UnityEditor");
LoadElapseData();
#endif
}
}
void OnApplicationQuit()
{
//gamesceneで止めるとなぜかtitleで読み込まれていることになる為、boolを作る
if(isLoadedGame) SaveToDisc();
}
void SaveToDisc()
{
Debug.Log("SaveToDisc");
createCharManager.SaveCharDataToDisc();
PlayerPrefs.SetInt( SCOREKEY, Score);
PlayerPrefs.SetInt( LEVELKEY,Level);
PlayerPrefs.SetInt( POINTKEY, Point);
Debug.Log("Point: " + Point + " SaveToDisc");
PlayerPrefs.SetInt( SAVEDFIRSTRUNKEY, checkFirstRun);
PlayerPrefs.Save();
}
void LoadElapseData()
{
Debug.Log("LoadElapseData");
Score = PlayerPrefs.GetInt(SCOREKEY);
Level = PlayerPrefs.GetInt(LEVELKEY);
Point = PlayerPrefs.GetInt(POINTKEY);
Debug.Log("Point: " + Point);
checkFirstRun = PlayerPrefs.GetInt(SAVEDFIRSTRUNKEY);
}