public MatterChange AddAmount(float addAmount) { MatterChange change = new MatterChange(type, Mathf.Clamp(amount + addAmount, 0, capacity) - amount); amount += change.amount; percent = amount / Tile.capacity; return(change); }
public void AddMatter(MatterChange newMatter) { MatterChange clamped = new MatterChange(newMatter.type, Mathf.Clamp(filled + newMatter.amount, 0, capacity) - filled); int found = content.FindIndex(m => m.type == clamped.type); MatterChange change; if (found >= 0) { change = content[found].AddAmount(clamped.amount); } else { content.Add(new Matter(clamped.type, clamped.amount)); change = clamped; } filled += change.amount; filledPercent = (float)filled / (float)capacity; }