private void updateDisplay() { string s = ""; // Text for no Containers if (containersToInspect.Count == 0) { s = "I want " + order.name + "."; } // Text for too many Containers else if (containersToInspect.Count > 1) { s = "One at a time, please."; } // Text for Container analysis else { // Find best match Container c = containersToInspect[0]; Liquid bestMatch = Manager.BestMatch(c.volume.liquid); float score = Manager.Compare(c.volume.liquid, order); // Good job if (bestMatch == order) { s = string.Format( "Thanks for the {0}!\nQuality: {1:0.}%\nQuantity: {2:0.}%", order.name, score * 100, c.volume.fullness * 100 ); } // Bad job else { s = string.Format( "I wanted {0}, not {1}!\nError: {2:0.}%\nQuantity: {3:0.}%", order.name, bestMatch.name, (1 - score) * 100, c.volume.fullness * 100 ); } } // Set text s += "\nPatience: " + (int)((patience / maxPatience) * 100) + "%"; text.text = s; }
public void addLiquid(Liquid l, float amount) { // Update volume and fullness volume = Mathf.Max(Mathf.Min(volume + amount, maxVolume), 0); fullness = volume / maxVolume; // Mix liquids if (l != null) { liquid = Mixture.Mix(liquid.ToMixture(), volume, l.ToMixture(), amount); } // Update mesh and color updateVolumeMesh(); GetComponent <MeshRenderer>().material.color = liquid.color; }
// Return which mixture most resembles a liquid public static Liquid BestMatch(Liquid a) { // Combine Mixtures and Bases into one list List <Liquid> candidates = new List <Liquid>(); candidates.AddRange(Mixtures.ToArray()); candidates.AddRange(Bases.ToArray()); // Select which liquid is the closest match Liquid bestMatch = null; float bestScore = 0; foreach (Liquid o in candidates) { float score = Compare(a.ToMixture(), o.ToMixture()); if (score > bestScore) { bestMatch = o; bestScore = score; } } // Friendly debug message /* * Debug.Log(string.Format( * "{0:0.}%\t'{1}' best match is '{2}'\n", * bestScore * 100, * a.name, * bestMatch ? bestMatch.name : "null" * )); * Debug.Log("\n\n"); */ // Return the best match return(bestMatch); }