Exemplo n.º 1
0
    void UpdatePour()
    {
        Glass.Sum = 0.0f;

        bool reorderIngredients = false;

        // UI
        for (int liquidIi = 0; liquidIi < Glass.liquids.Count; liquidIi++)
        {
            var liquid = Glass.liquids[liquidIi];
            Glass.Sum += liquid.amount;

            if (liquid.ingredient == null && liquid.type != LiquidType.BeerHead)
            {
                liquid.ingredient = FindIngredientUi(liquid.type);

                if (liquid.ingredient == null)
                {
                    liquid.ingredient = MakeIngredientUi(liquid.type);
                    if (liquid.ingredient)
                    {
                        liquid.ingredient.Liquid = liquid;
                        liquid.ingredient.Glass  = Glass;
                        liquid.ingredient.Enable();
                        liquid.ingredient.DoUpdate();
                        liquid.ingredient.Update();
                    }
                }
                else
                {
                    liquid.ingredient.Liquid = liquid;
                    liquid.ingredient.Glass  = Glass;
                }
            }
        }

        Glass.BeerHeadTimer += Time.deltaTime;

        // Beer Head
        if (Glass.BeerHead != null && Glass.BeerHead.type == LiquidType.BeerHead && Glass.BeerHeadTimer >= 0.1f)
        {
            GlassLiquid beer = Glass.FindLiquid(LiquidType.Beer);
            if (beer != null && beer.amount < 0.95f)
            {
                const float flowRate = 0.05f;

                float headAmount = Glass.BeerHead.amount;
                float headFlow   = flowRate * Time.deltaTime;

                bool doDeleteHead = false;

                float newHeadAmount = headAmount - headFlow;

                if (newHeadAmount <= 0.0f)
                {
                    doDeleteHead = true;
                    headFlow     = headAmount;
                }

                beer.amount           += headFlow;
                Glass.BeerHead.amount -= headFlow;

                if (doDeleteHead)
                {
                    Glass.DeleteLiquid(Glass.BeerHead);
                    Glass.BeerHead = null;
                }

                Glass.updateNeeded = true;
            }
        }

        // Spilling
        if (Glass.Sum > 1.0f)
        {
            float       upSum     = 0.0f;
            GlassLiquid topLiquid = null;

            for (int liquidIi = 0; liquidIi < Glass.liquids.Count; liquidIi++)
            {
                GlassLiquid gl = Glass.liquids[liquidIi];

                if (liquidIi == Glass.liquids.Count - 1)
                {
                    topLiquid = gl;
                }
                else
                {
                    upSum += gl.amount;
                }
            }

            if (topLiquid != null)
            {
                topLiquid.amount = 1.0f - upSum;

                if (topLiquid.amount <= 0.0f)
                {
                    if (topLiquid.ingredient != null)
                    {
                        if (topLiquid.ingredient.HasMeasure() == false)
                        {
                            topLiquid.ingredient.LiquidType = LiquidType.None;
                            topLiquid.ingredient.Disable();
                        }

                        topLiquid.ingredient.Liquid        = null;
                        topLiquid.ingredient.RefreshNeeded = true;
                    }

                    Glass.DeleteLiquid(topLiquid);
                    reorderIngredients = true;
                }
                else
                {
                    topLiquid.animate = true;
                }

                Glass.updateNeeded = true;
            }
        }

        if (reorderIngredients)
        {
            OrderMeasures();
        }

//    if (reorderIngredients || Mathf.Approximately(lastSum, Glass.Sum) == false)
//    {
//     // Debug.Log(GetWin());
//    }

        lastSum = Glass.Sum;

        // A - Add Drink
        if (Controls.Action1)
        {
            SubmitDrink();
        }
    }