Esempio n. 1
0
    void M8.IModalPush.Push(M8.GenericParams parms)
    {
        //grab data
        int datIndex = 0;

        if (parms != null)
        {
            int minInd = 0, maxInd = 0;

            if (parms.ContainsKey(parmDataIndexMin))
            {
                minInd = parms.GetValue <int>(parmDataIndexMin);
            }
            if (parms.ContainsKey(parmDataIndexMax))
            {
                maxInd = parms.GetValue <int>(parmDataIndexMax);
            }

            if (minInd == maxInd)
            {
                datIndex = minInd;
            }
            else
            {
                datIndex = Random.Range(minInd, maxInd + 1);
            }
        }

        datIndex = Mathf.Clamp(datIndex, 0, data.Length - 1);

        var dat = data[datIndex];

        ClearSlots();

        //fill up itemSlots based on the amount to fill
        for (int i = 0; i < fillSlots.Length; i++)
        {
            SlotWidget slot;
            if (mItemSlotCache.Count > 0)
            {
                slot = mItemSlotCache.RemoveLast();
                slot.transform.SetParent(itemSlotRoot);
            }
            else
            {
                slot = Instantiate(templateItemSlot, itemSlotRoot);
            }

            mItemSlotActives.Add(slot);
        }

        mItemSlotActives.Shuffle();

        //fill slot items
        for (int i = 0; i < fillSlots.Length; i++)
        {
            var slot     = mItemSlotActives[i];
            var fillSlot = fillSlots[i];
            var number   = dat.slotNumbers[i];

            SlotItemWidget item;
            if (mItemCache.Count > 0)
            {
                item = mItemCache.RemoveLast();
            }
            else
            {
                item = Instantiate(templateItem);
            }

            item.Init(number, slot, fillSlot, dragAreaRoot);

            mItemActives.Add(item);
        }

        //setup fixed numbers
        for (int i = 0; i < numberTexts.Length; i++)
        {
            var number = dat.numbers[i];
            numberTexts[i].text = number.ToString();
        }

        //setup bonus score display
        var textFormat = M8.Localize.Get(bonusScoreTextFormatRef);

        bonusScoreText.text = string.Format(textFormat, GameData.instance.bonusRoundScore);

        //init bottom display
        incorrectGO.SetActive(false);
        timeExpireGO.SetActive(false);
        bonusScoreGO.SetActive(false);
        finishGO.SetActive(false);
    }