void Awake() { if (!_instance) _instance = this; else Destroy(this.gameObject); // GetComponent<GameManager>().DeadCanvas = GameObject.Find("DeadUI").GetComponent<Canvas>(); DontDestroyOnLoad(this.gameObject); }
public void setNewPermanentData() { this.permanentData = new PermanentData(); this.permanentData.highscore = 0; this.permanentData.gold = 0; this.permanentData.knightBaseHealth = 11; this.permanentData.dwarfBaseHealth = 10; this.permanentData.wizardBaseHealth = 9; this.permanentData.rogueBaseHealth = 9; this.permanentData.rangerBaseHealth = 10; this.permanentData.knightStrength = 2; this.permanentData.dwarfStrength = 1; this.permanentData.wizardStrength = 2; this.permanentData.rogueStrength = 1; this.permanentData.rangerStrength = 1; this.dataController.savePermanentData(this.permanentData); }
public PermanentData loadPermanentData() { string filePath = Path.Combine(Application.persistentDataPath, DataController.permanentDataFileName); if (File.Exists(filePath)) { try { return(PermanentData.Deserialize(File.ReadAllBytes(filePath))); } catch (EndOfStreamException e) { // new version perhaps? Debug.Log(e); return(null); } } else { return(null); } }
void Start() { initDefaultValuesPreferences(); this.permanentData = this.dataController.loadPermanentData(); if (this.permanentData == null) { setNewPermanentData(); } this.restoredGameProgress = this.dataController.loadGameProgress(); if (this.restoredGameProgress != null) { continueAvailable = true; } this.gameProgress = new GameProgress(); this.gameProgress.level = 0; // start the music after the volume is set setSoundVolume(); SoundManager.instance.playMusic = true; }
public static PermanentData Deserialize(byte[] data) { PermanentData result = new PermanentData(); using (MemoryStream m = new MemoryStream(data)) { using (BinaryReader reader = new BinaryReader(m)) { result.highscore = reader.ReadInt32(); result.gold = reader.ReadInt32(); result.knightBaseHealth = reader.ReadInt32(); result.wizardBaseHealth = reader.ReadInt32(); result.rogueBaseHealth = reader.ReadInt32(); result.rangerBaseHealth = reader.ReadInt32(); result.dwarfBaseHealth = reader.ReadInt32(); result.knightStrength = reader.ReadInt32(); result.wizardStrength = reader.ReadInt32(); result.rogueStrength = reader.ReadInt32(); result.rangerStrength = reader.ReadInt32(); result.dwarfStrength = reader.ReadInt32(); } } return(result); }
public void savePermanentData(PermanentData pd) { File.WriteAllBytes(Path.Combine(Application.persistentDataPath, DataController.permanentDataFileName), pd.Serialize()); }
public static void Init(TextRenderer targetText) { CommentGuy.targetText = targetText; CommentGuy.schedule = new List<Comment>(); // Load permanent data, if existing if (permanentMind == null) { string mindPath = Path.Combine(Path.GetDirectoryName(DualityApp.UserDataPath), "mind.dat"); if (File.Exists(mindPath)) { try { using (FileStream stream = File.OpenRead(mindPath)) { using (Formatter formatter = Formatter.Create(stream)) { permanentMind = formatter.ReadObject() as PermanentData; } } } catch (Exception e) { Log.Game.WriteError("Error loading permanent data: {0}", Log.Exception(e)); } } } // Create new permanent data, if not if (permanentMind == null) permanentMind = new PermanentData(); if (temporaryMind == null) temporaryMind = new TemporaryData(); // Only do once what is behind this line. if (initialized) return; initialized = true; DualityApp.Terminating += (s, e) => Terminate(); temporaryMind.TimeSinceLastMet = DateTime.Now - permanentMind.TimeShutdown; }