92 lines
2.0 KiB
C#
92 lines
2.0 KiB
C#
using UnityEngine;
|
|||
|
|
using System.Collections;
|
||
|
|
using System.Xml;
|
||
|
|
using System.Xml.Serialization;
|
||
|
|
using System.IO;
|
||
|
|
using System.Text;
|
||
|
|
|
||
|
|
|
||
|
|
public class GameManager : MonoBehaviour {
|
||
|
|
|
||
|
|
private const string saveFileName = "save.xml";
|
||
|
|
private MenuManager menuManager;
|
||
|
|
private int chemistryUsers = 0;
|
||
|
|
|
||
|
|
public class GameState{
|
||
|
|
public int gameFinishCount;
|
||
|
|
public int currentLevel;
|
||
|
|
public float Volume;
|
||
|
|
}
|
||
|
|
|
||
|
|
private GameState state = new GameState();
|
||
|
|
public GameState State{
|
||
|
|
get{return state; }
|
||
|
|
}
|
||
|
|
|
||
|
|
string GetSaveFilePath(){
|
||
|
|
return Application.persistentDataPath + "/" + saveFileName;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Use this for initialization
|
||
|
|
void Start () {
|
||
|
|
var src = gameObject.AddComponent<AudioSource> ();
|
||
|
|
src.volume = 1.0f;
|
||
|
|
menuManager = GameObject.FindObjectOfType<MenuManager> ();
|
||
|
|
LoadState ();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ActivateChemistry(){
|
||
|
|
chemistryUsers++;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void DeactivateChemistry(){
|
||
|
|
chemistryUsers--;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update is called once per frame
|
||
|
|
void Update () {
|
||
|
|
//Debug.Log (Time.timeScale);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NewGame(){
|
||
|
|
menuManager.ActivateMenu ("");
|
||
|
|
Application.LoadLevel ("Level0");
|
||
|
|
}
|
||
|
|
|
||
|
|
public void MainMenu(){
|
||
|
|
SaveState ();
|
||
|
|
menuManager.ActivateMenu ("");
|
||
|
|
Application.LoadLevel("StartScene");
|
||
|
|
}
|
||
|
|
|
||
|
|
public void SaveState(){
|
||
|
|
Debug.Log ("Saving game state!");
|
||
|
|
XmlSerializer serializer = new XmlSerializer (typeof(GameState));
|
||
|
|
FileStream fs = new FileStream (GetSaveFilePath(), FileMode.Create);
|
||
|
|
TextWriter writer = new StreamWriter(fs, new UTF8Encoding());
|
||
|
|
serializer.Serialize(writer, state);
|
||
|
|
writer.Close();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void LoadState(){
|
||
|
|
Debug.Log ("Loading game state!");
|
||
|
|
if (File.Exists (GetSaveFilePath ())) {
|
||
|
|
XmlSerializer serializer = new XmlSerializer (typeof(GameState));
|
||
|
|
FileStream fs = new FileStream (GetSaveFilePath(), FileMode.Open);
|
||
|
|
TextReader reader = new StreamReader(fs, new UTF8Encoding());
|
||
|
|
state = (GameState)serializer.Deserialize(reader);
|
||
|
|
reader.Close();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
public void LoadLevel(int id){
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/*void OnGUI(){
|
||
|
|
if (chemistryUsers > 0) {
|
||
|
|
GUI.Button(new Rect(200,200,100,100), "Chemistry activated");
|
||
|
|
}
|
||
|
|
}*/
|
||
|
|
}
|