public GameElementData GetProgress(System.Enum key) { int index = Player.progress.FirstIndex(p => p.key == key.ToString()); if (index == -1) { return(GameElementData.CreateState(key.ToString(), 0)); } return(Player.progress[index].Clone() as GameElementData); }
public bool ResetProgress(string key, int value = 0) { int index = _data.progress.GetIndex(key); if (index == -1) { return(false); } _data.progress[index] = GameElementData.CreateState(key, value); return(Save()); }
public GameElementData GetLevelProgress(string levelConfigId, System.Enum key) { LevelStateData data = _sharedStateItems.FirstOrDefault(l => l.id == levelConfigId); if (data != null) { int index = data.progress.FirstIndex(p => p.key == key.ToString()); if (index != -1) { return(data.progress[index].Clone() as GameElementData); } } return(GameElementData.CreateState(key.ToString(), 0)); }
/// <summary> /// Sets the progress. /// </summary> /// <param name="setOnlyIfHigher">If set to <c>true</c> will assign only if the value is higher.</param> public bool SetProgress(System.Enum key, int value, bool setOnlyIfHigher = false) { int index = Player.progress.FirstIndex(p => p.key == key.ToString()); if (index == -1) { Player.progress.Add(GameElementData.CreateState(key.ToString(), value)); return(true); } else { if (value >= Player.progress[index].value || !setOnlyIfHigher) { Player.progress[index] = GameElementData.CreateState(key.ToString(), value); return(true); } } return(false); }
public bool IncreaseProgress(string key, int value) { return(IncreaseProgress(GameElementData.CreateState(key, value))); }