Esempio n. 1
0
    void Fill()
    {
        //build the available supply
        List <Sushi> supply_list = new List <Sushi>();

        foreach (Sushi fish in inventory.Keys)
        {
            Debug.Log(fish.name + ": " + inventory[fish]);
            int how_many = Mathf.Min(fish.maxActive, inventory[fish]);
            for (int i = 0; i < how_many; i++)
            {
                supply_list.Add(fish);
            }
        }

        //subtract any that have already been placed
        foreach (Sushi fish in activeIngredients.Values)
        {
            if (fish != null)
            {
                supply_list.Remove(fish);
            }
        }

        //fill in randomly
        List <int> keys = new List <int>(activeIngredients.Keys);

        foreach (int key in keys)
        {
            //deactivate any that were selected
            metaNode.SpriteWithName("fill_" + key).gameObject.SetActive(false);

            if (activeIngredients[key] == null)
            {
                if (key == 5 && supply_list.IndexOf(rice) >= 0)
                {
                    int   which = supply_list.IndexOf(rice);
                    Sushi fish  = supply_list[which];
                    supply_list.RemoveAt(which);
                    activeIngredients[key] = fish;
                    metaNode.LabelWithName("label_" + key).text = fish.fish;
                    metaNode.Get <SuperTab>("tab_sushi_" + key).currentState = fish.name;
                }
                else if (supply_list.Count > 0)
                {
                    int   which = Random.Range(0, supply_list.Count);
                    Sushi fish  = supply_list[which];
                    supply_list.RemoveAt(which);
                    activeIngredients[key] = fish;
                    metaNode.LabelWithName("label_" + key).text = fish.fish;
                    metaNode.Get <SuperTab>("tab_sushi_" + key).currentState = fish.name;
                }
                else
                {
                    metaNode.LabelWithName("label_" + key).text = "EMPTY";
                    metaNode.Get <SuperTab>("tab_sushi_" + key).currentState = "none";
                }
            }
        }
    }