Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- public class DataManager : MonoBehaviour
- {
- public static DataManager Instance;
- public string testID = "0";
- string filename;
- int keyboardCount = 0;
- int guitarCount = 0;
- int controllerCount = 0;
- public bool playedKeyboard = false;
- public bool playedController = false;
- public bool playedGuitar = false;
- [HideInInspector] public string keyTime1 , keyTime2, conTime1, conTime2, ghTime1, ghTime2;
- [HideInInspector] public int keyCrash1, keyCrash2, conCrash1, conCrash2, ghCrash1, ghCrash2;
- [HideInInspector] public int keyOrb1, keyOrb2, conOrb1, conOrb2, ghOrb1, ghOrb2;
- [HideInInspector] public int totalOrbs;
- [HideInInspector] public int keyOrbAc1, keyOrbAc2, conOrbAc1, conOrbAc2, ghOrbAc1, ghOrbAc2;
- [HideInInspector] public int keyTotAc1, keyTotAc2, conTotAc1, conTotAc2, ghTotAc1, ghTotAc2;
- [HideInInspector] public int keyScore1, keyScore2, conScore1, conScore2, ghScore1, ghScore2;
- void Awake()
- {
- //singelton
- if (Instance == null)
- {
- Instance = this as DataManager;
- DontDestroyOnLoad(gameObject);
- }
- else
- Destroy(gameObject);
- }
- public bool PlayKeyboard()
- {
- if (keyboardCount < 2)
- {
- keyboardCount++;
- playedKeyboard = true;
- return true;
- }
- else
- return false;
- }
- public bool PlayController()
- {
- if (controllerCount < 2)
- {
- controllerCount++;
- playedController = true;
- return true;
- }
- else
- return false;
- }
- public bool PlayGuitar()
- {
- if (guitarCount < 2)
- {
- guitarCount++;
- playedGuitar = true;
- return true;
- }
- else
- return false;
- }
- public void SaveData(string endTime, int crashes, int orbsTaken, int totalOrbs, int orbAccuracy, int totalAccuracy, int score)
- {
- if (playedKeyboard)
- {
- if (keyboardCount == 1)
- {
- keyTime1 = endTime;
- keyCrash1 = crashes;
- keyOrb1 = orbsTaken;
- this.totalOrbs = totalOrbs;
- keyOrbAc1 = orbAccuracy;
- keyTotAc1 = totalAccuracy;
- keyScore1 = score;
- }
- if (keyboardCount == 2)
- {
- keyTime2 = endTime;
- keyCrash2 = crashes;
- keyOrb2 = orbsTaken;
- this.totalOrbs = totalOrbs;
- keyOrbAc2 = orbAccuracy;
- keyTotAc2 = totalAccuracy;
- keyScore2 = score;
- }
- playedKeyboard = false;
- }
- else if (playedController)
- {
- if (controllerCount == 1)
- {
- conTime1 = endTime;
- conCrash1 = crashes;
- conOrb1 = orbsTaken;
- this.totalOrbs = totalOrbs;
- conOrbAc1 = orbAccuracy;
- conTotAc1 = totalAccuracy;
- conScore1 = score;
- }
- if (controllerCount == 2)
- {
- conTime2 = endTime;
- conCrash2 = crashes;
- conOrb2 = orbsTaken;
- this.totalOrbs = totalOrbs;
- conOrbAc2 = orbAccuracy;
- conTotAc2 = totalAccuracy;
- conScore2 = score;
- }
- playedController = false;
- }
- else if (playedGuitar)
- {
- if (guitarCount == 1)
- {
- ghTime1 = endTime;
- ghCrash1 = crashes;
- ghOrb1 = orbsTaken;
- this.totalOrbs = totalOrbs;
- ghOrbAc1 = orbAccuracy;
- ghTotAc1 = totalAccuracy;
- ghScore1 = score;
- }
- if (guitarCount == 2)
- {
- ghTime2 = endTime;
- ghCrash2 = crashes;
- ghOrb2 = orbsTaken;
- this.totalOrbs = totalOrbs;
- ghOrbAc2 = orbAccuracy;
- ghTotAc2 = totalAccuracy;
- ghScore2 = score;
- }
- playedGuitar = false;
- }
- }
- public void SaveToTxt()
- {
- filename = "Data " + testID + ".txt";
- using (StreamWriter sw = new StreamWriter(filename))
- {
- sw.WriteLine("-------------------");
- sw.WriteLine("");
- sw.WriteLine("KEYBOARD - PLAYTHROUGH 1");
- sw.WriteLine("");
- sw.WriteLine("TIME: " + keyTime1);
- sw.WriteLine("CRASHES: " + keyCrash1);
- sw.WriteLine("ORBS: " + keyOrb1 + " / " + totalOrbs + " (" + keyOrbAc1 + "%)");
- sw.WriteLine("ACCURACY: " + keyTotAc1 + "%");
- sw.WriteLine("SCORE: " + keyScore1);
- sw.WriteLine("");
- sw.WriteLine("-------------------");
- sw.WriteLine("");
- sw.WriteLine("KEYBOARD - PLAYTHROUGH 2");
- sw.WriteLine("");
- sw.WriteLine("TIME: " + keyTime2);
- sw.WriteLine("CRASHES: " + keyCrash2);
- sw.WriteLine("ORBS: " + keyOrb2 + " / " + totalOrbs + " (" + keyOrbAc2 + "%)");
- sw.WriteLine("ACCURACY: " + keyTotAc2 + "%");
- sw.WriteLine("SCORE: " + keyScore2);
- sw.WriteLine("");
- sw.WriteLine("-------------------");
- sw.WriteLine("");
- sw.WriteLine("CONTROLLER - PLAYTHROUGH 1");
- sw.WriteLine("");
- sw.WriteLine("TIME: " + conTime1);
- sw.WriteLine("CRASHES: " + conCrash1);
- sw.WriteLine("ORBS: " + conOrb1 + " / " + totalOrbs + " (" + conOrbAc1 + "%)");
- sw.WriteLine("ACCURACY: " + conTotAc1 + "%");
- sw.WriteLine("SCORE: " + conScore1);
- sw.WriteLine("");
- sw.WriteLine("-------------------");
- sw.WriteLine("");
- sw.WriteLine("CONTROLLER - PLAYTHROUGH 2");
- sw.WriteLine("");
- sw.WriteLine("TIME: " + conTime2);
- sw.WriteLine("CRASHES: " + conCrash2);
- sw.WriteLine("ORBS: " + conOrb2 + " / " + totalOrbs + " (" + conOrbAc2 + "%)");
- sw.WriteLine("ACCURACY: " + conTotAc2 + "%");
- sw.WriteLine("SCORE: " + conScore2);
- sw.WriteLine("");
- sw.WriteLine("-------------------");
- sw.WriteLine("");
- sw.WriteLine("GUITAR - PLAYTHROUGH 1");
- sw.WriteLine("");
- sw.WriteLine("TIME: " + ghTime1);
- sw.WriteLine("CRASHES: " + ghCrash1);
- sw.WriteLine("ORBS: " + ghOrb1 + " / " + totalOrbs + " (" + ghOrbAc1 + "%)");
- sw.WriteLine("ACCURACY: " + ghTotAc1 + "%");
- sw.WriteLine("SCORE: " + ghScore1);
- sw.WriteLine("");
- sw.WriteLine("-------------------");
- sw.WriteLine("");
- sw.WriteLine("GUITAR - PLAYTHROUGH 2");
- sw.WriteLine("");
- sw.WriteLine("TIME: " + ghTime2);
- sw.WriteLine("CRASHES: " + ghCrash2);
- sw.WriteLine("ORBS: " + ghOrb2 + " / " + totalOrbs + " (" + ghOrbAc2 + "%)");
- sw.WriteLine("ACCURACY: " + ghTotAc2 + "%");
- sw.WriteLine("SCORE: " + ghScore2);
- sw.WriteLine("");
- sw.WriteLine("-------------------");
- }
- }
- public void Save()
- {
- BinaryFormatter bf = new BinaryFormatter();
- FileStream file = File.Create("ZombieCrash_Data/TestData.dat");
- TestData data = new TestData();
- data.testID = testID;
- data.keyboardCount = keyboardCount;
- data.controllerCount = controllerCount;
- data.guitarCount = guitarCount;
- data.keyTime1 = keyTime1;
- data.keyTime2 = keyTime2;
- data.conTime1 = conTime1;
- data.conTime2 = conTime2;
- data.ghTime1 = ghTime1;
- data.ghTime2 = ghTime2;
- data.keyCrash1 = keyCrash1;
- data.keyCrash2 = keyCrash2;
- data.conCrash1 = conCrash1;
- data.conCrash2 = conCrash2;
- data.ghCrash1 = ghCrash1;
- data.ghCrash2 = ghCrash2;
- data.keyOrb1 = keyOrb1;
- data.keyOrb2 = keyOrb2;
- data.conOrb1 = conOrb1;
- data.conOrb2 = conOrb2;
- data.ghOrb1 = ghOrb1;
- data.ghOrb2 = ghOrb2;
- data.totalOrbs = totalOrbs;
- data.keyOrbAc1 = keyOrbAc1;
- data.keyOrbAc2 = keyOrbAc2;
- data.conOrbAc1 = conOrbAc1;
- data.conOrbAc2 = conOrbAc2;
- data.ghOrbAc1 = ghOrbAc1;
- data.ghOrbAc2 = ghOrbAc2;
- data.keyTotAc1 = keyTotAc1;
- data.keyTotAc2 = keyTotAc2;
- data.conTotAc1 = conTotAc1;
- data.conTotAc2 = conTotAc2;
- data.ghTotAc1 = ghTotAc1;
- data.ghTotAc2 = ghTotAc2;
- data.keyScore1 = keyScore1;
- data.keyScore2 = keyScore2;
- data.conScore1 = conScore1;
- data.conScore2 = conScore2;
- data.ghScore1 = ghScore1;
- data.ghScore2 = ghScore2;
- bf.Serialize(file, data);
- file.Close();
- }
- public void Load()
- {
- if (File.Exists("ZombieCrash_Data/TestData.dat"))
- {
- BinaryFormatter bf = new BinaryFormatter();
- FileStream file = File.Open("ZombieCrash_Data/TestData.dat", FileMode.Open);
- TestData data = (TestData)bf.Deserialize(file);
- file.Close();
- testID = data.testID;
- keyboardCount = data.keyboardCount;
- controllerCount = data.controllerCount;
- guitarCount = data.guitarCount;
- keyTime1 = data.keyTime1;
- keyTime2 = data.keyTime2;
- conTime1 = data.conTime1;
- conTime2 = data.conTime2;
- ghTime1 = data.ghTime1;
- ghTime2 = data.ghTime2;
- keyCrash1 = data.keyCrash1;
- keyCrash2 = data.keyCrash2;
- conCrash1 = data.conCrash1;
- conCrash2 = data.conCrash2;
- ghCrash1 = data.ghCrash1;
- ghCrash2 = data.ghCrash2;
- keyOrb1 = data.keyOrb1;
- keyOrb2 = data.keyOrb2;
- conOrb1 = data.conOrb1;
- conOrb2 = data.conOrb2;
- ghOrb1 = data.ghOrb1;
- ghOrb2 = data.ghOrb2;
- totalOrbs = data.totalOrbs;
- keyOrbAc1 = data.keyOrbAc1;
- keyOrbAc2 = data.keyOrbAc2;
- conOrbAc1 = data.keyOrbAc1;
- conOrbAc2 = data.keyOrbAc2;
- ghOrbAc1 = data.ghOrbAc1;
- ghOrbAc2 = data.ghOrbAc2;
- keyTotAc1 = data.keyTotAc1;
- keyTotAc2 = data.keyTotAc2;
- conTotAc1 = data.conTotAc1;
- conTotAc2 = data.conTotAc2;
- ghTotAc1 = data.ghTotAc1;
- ghTotAc2 = data.ghTotAc2;
- keyScore1 = data.keyScore1;
- keyScore2 = data.keyScore2;
- conScore1 = data.conScore1;
- conScore2 = data.conScore2;
- ghScore1 = data.ghScore1;
- ghScore2 = data.ghScore2;
- }
- }
- }
- [Serializable]
- class TestData
- {
- public string testID;
- public int keyboardCount, guitarCount, controllerCount;
- public string keyTime1 , keyTime2, conTime1, conTime2, ghTime1, ghTime2;
- public int keyCrash1, keyCrash2, conCrash1, conCrash2, ghCrash1, ghCrash2;
- public int keyOrb1, keyOrb2, conOrb1, conOrb2, ghOrb1, ghOrb2;
- public int totalOrbs;
- public int keyOrbAc1, keyOrbAc2, conOrbAc1, conOrbAc2, ghOrbAc1, ghOrbAc2;
- public int keyTotAc1, keyTotAc2, conTotAc1, conTotAc2, ghTotAc1, ghTotAc2;
- public int keyScore1, keyScore2, conScore1, conScore2, ghScore1, ghScore2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement