예제 #1
0
        public override Mixture ToMixture()
        {
            Mixture mixture = CreateInstance <Mixture>();

            mixture.components.Add(this, 1);
            mixture.name = name;
            return(mixture);
        }
예제 #2
0
        private void Awake()
        {
            // Set up mesh for this object
            gameObject.AddComponent <MeshFilter>();
            gameObject.AddComponent <MeshRenderer>().material = material;
            gameObject.AddComponent <MeshCollider>().convex   = true;
            GetComponent <MeshCollider>().isTrigger           = true;

            // Set initial volume according to fullnesss
            liquid = Mixture.DefaultMixture();
            volume = maxVolume * fullness;
            updateVolumeMesh();
        }
예제 #3
0
        public static Mixture Mix(Mixture a, float amountA, Mixture b, float amountB)
        {
            // Get total amount between a and b
            float totalAmount = amountA + amountB;
            float totalPartsA = 0, totalPartsB = 0;

            foreach (float o in a.components.Values)
            {
                totalPartsA += o;
            }
            foreach (float o in b.components.Values)
            {
                totalPartsB += o;
            }

            // Get all bases
            Base[] bases = (
                from x in a.components.Keys.Union(b.components.Keys)
                select x
                ).Distinct().ToArray();

            // Mix
            Mixture mixture = CreateInstance <Mixture>();

            mixture.name = "custom";
            string debugMessage = "Mixing:";

            foreach (Base o in bases)
            {
                float percentOfA    = a.components.ContainsKey(o) ? a.components[o] / totalPartsA : 0;
                float percentOfB    = b.components.ContainsKey(o) ? b.components[o] / totalPartsB : 0;
                float absoluteA     = percentOfA * amountA;
                float absoluteB     = percentOfB * amountB;
                float absoluteTotal = (absoluteA + absoluteB) / totalAmount;
                mixture.components.Add(o, absoluteTotal);

                // Friendly debug message
                debugMessage += string.Format(
                    "\n{0}: {1:0.0}%",
                    o.name,
                    absoluteTotal * 100
                    );
            }
            //Debug.Log(debugMessage);

            // Update color
            mixture.updateColor();

            // Return the new mixture
            return(mixture);
        }
예제 #4
0
        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;
        }
예제 #5
0
        private IEnumerator changeOrder()
        {
            // Set order to a random mixture
            order = Manager.Mixtures[Random.Range(0, Manager.Mixtures.Count)];

            // Check repeatedly until impatient
            patience += maxPatience;
            while (patience > 0)
            {
                updateDisplay();
                yield return(new WaitForSeconds(refreshInterval));

                patience -= refreshInterval;
            }

            // Change the order
            StartCoroutine(changeOrder());
        }
예제 #6
0
        // Return a float representing how similar two liquids are
        public static float Compare(Mixture a, Mixture b)
        {
            // Get all bases

            Base[] bases = (
                from x in a.components.Keys.Union(b.components.Keys)
                select x
                ).Distinct().ToArray();

            // Get total parts in a and b
            float totalPartsA = 0, totalPartsB = 0;

            foreach (float o in a.components.Values)
            {
                totalPartsA += o;
            }
            foreach (float o in b.components.Values)
            {
                totalPartsB += o;
            }

            // Calculate score

            /*
             * string debugString = "";
             */
            float score = 1;

            foreach (Base o in bases)
            {
                float percentOfA = a.components.ContainsKey(o) ? a.components[o] / totalPartsA : 0;
                float percentOfB = b.components.ContainsKey(o) ? b.components[o] / totalPartsB : 0;
                score -= Mathf.Abs(percentOfA - percentOfB) / 2;

                /*
                 * debugString += string.Format(
                 *      "\n{0}: {1:0.}% - {2:0.}% ---> -{3:0.}",
                 *      o.name,
                 *      percentOfA * 100,
                 *      percentOfB * 100,
                 *      Mathf.Abs(percentOfA - percentOfB) / 2
                 * );
                 */
            }

            // Friendly debug message

            /*
             * if(score > -100.0f) {
             *      Debug.Log(string.Format(
             *              "{0:0.}%\t'{1}' compared to '{2}'\n{3}\n\n\n\n\n\n",
             *              score * 100,
             *              a.name,
             *              b.name,
             *              debugString
             *      ));
             * }
             */

            // Return score
            return(score);
        }