void LoadDataPlayerPriority_Level(GameObject player) { Component[] components = player.GetComponents <UpgradableComponent>(); foreach (TablePlayerLevel row in Query <TablePlayerLevel>("SELECT * FROM " + nameof(TablePlayerLevel) + " WHERE owner=?", player.name)) { foreach (Component component in components) { if (component is UpgradableComponent) { UpgradableComponent manager = (UpgradableComponent)component; if (manager.GetType().ToString() == row.name) { manager.level = row.level; } } } } }
void SaveDataPlayer_Level(GameObject player, bool isOnline) { // you should delete all data of this player first, to prevent duplicates DeleteDataPlayer_Level(player.name); Component[] components = player.GetComponents <UpgradableComponent>(); foreach (Component component in components) { if (component is UpgradableComponent) { UpgradableComponent manager = (UpgradableComponent)component; InsertOrReplace(new TablePlayerLevel { owner = player.name, name = manager.GetType().ToString(), level = manager.level }); } } }