public SaveablePlayerData GetSavePlayerData() { var saveablePlayerData = new SaveablePlayerData(); saveablePlayerData.PositionX = Player.transform.position.x; saveablePlayerData.PositionY = Player.transform.position.y; PlayerPosition = Player.transform.position; foreach (var spell in SpellBar.Spells) { if (spell != null) { saveablePlayerData.BoundSpellIds.Add(spell.Id); } else { saveablePlayerData.BoundSpellIds.Add(""); } } foreach (var spellCategory in SpellBook.SpellCategories) { foreach (var spell in spellCategory.Spells) { if (spell.IsUnlocked) { saveablePlayerData.UnlockedSpellIds.Add(spell.Id); } } } return(saveablePlayerData); }
public void LoadPlayerData(SaveablePlayerData data) { PlayerPosition = new Vector2(data.PositionX, data.PositionY); foreach (var spellCategory in SpellBook.SpellCategories) { foreach (var spell in spellCategory.Spells) { spell.IsUnlocked = data.UnlockedSpellIds.Contains(spell.Id); } } var spells = new List <SpellConfig>(); foreach (var boundSpell in data.BoundSpellIds) { spells.Add(SpellBook.GetSpellById(boundSpell)); } SpellBar.Initialize(spells); }