protected override void Interact() { Vector2 start = transform.position; Vector2 end = start + new Vector2(_animator.GetFloat("MoveX"), _animator.GetFloat("MoveY")); RaycastHit2D hit; CheckHit(start, end, out hit); if (hit.transform == null) { return; } if (hit.transform.tag == "SaveNPC") { MySaveData saveData = new MySaveData { Inventory = GetComponent <Inventory>().InventoryItems, DisplayName = MyPlayerManager.PlayerName, MaxHealth = MyPlayerManager.MaxHealth }; GetComponent <SaveMenu>().SaveGame(saveData, Application.persistentDataPath + "/save.sav"); } }
/// <summary> /// Restores deserialized state back to action. /// </summary> /// <param name="dataIn">Data packet with action state to load.</param> public override void RestoreSaveData(object dataIn) { MySaveData data = (MySaveData)dataIn; thingName = data.thingName; thingsRemaining = data.thingsRemaining; interval = data.interval; dropPercent = data.dropPercent; }
/// <summary> /// Gets save data for action serialization. /// </summary> /// <returns>Data packet with action state to save.</returns> public override object GetSaveData() { MySaveData data = new MySaveData(); data.thingName = thingName; data.thingsRemaining = thingsRemaining; data.interval = interval; data.dropPercent = dropPercent; return(data); }
/// <summary> /// Gets save data for action serialization. /// </summary> /// <returns>Data packet with action state to save.</returns> public override object GetSaveData() { var saveData = new MySaveData(); saveData.soundName = this.soundName; saveData.soundIndex = this.soundIndex; saveData.interval = this.interval; saveData.lastTimePlayed = this.lastTimePlayed; return(saveData); }
public override void LoadGame() { string path = Application.persistentDataPath + "/save.sav"; MySaveData save = gameObject.GetComponent <SaveLoad>().Load <MySaveData>(path); if (save != null) { GameManager.SaveLoaded = true; MyGameManager.Save = save; } base.LoadGame(); }
/// <summary> /// Restores deserialized state back to action. /// </summary> /// <param name="dataIn">Data packet with action state to load.</param> public override void RestoreSaveData(object dataIn) { if (dataIn == null) { return; } MySaveData saveData = (MySaveData)dataIn; this.soundName = saveData.soundName; this.soundIndex = saveData.soundIndex; this.interval = saveData.interval; this.lastTimePlayed = saveData.lastTimePlayed; }
public static void ReadGameDataBinary() { string filepath = Application.persistentDataPath + "/savedata.sav"; if (!File.Exists(filepath)) { return; } BinaryFormatter bf = new BinaryFormatter(); FileStream stream = File.Open(filepath, FileMode.Open); MyData = bf.Deserialize(stream) as MySaveData; stream.Close(); GetData(); }
public static void Load(MySaveData saveData) { InitPlayer(saveData.DisplayName, saveData.MaxHealth); Inventory = saveData.Inventory; Initialized = true; }