예제 #1
0
    public void CreatePool(int num)
    {
        // use one stack to reverse the order of accessing Button
        // because the priority in Canvas is from top(first access) to bottom(last success)
        // we should Reuse the button from bottom to top,
        // when button overlapped, player can click the button below(more close to the end line, create earlier, accessing order is first)
        btnPool = new Queue <GameObject>();
        Stack <GameObject> tmpBtnQueue = new Stack <GameObject>();

        for (int i = 0; i < num; ++i)
        {
            GameObject b = Instantiate(btn, note.transform) as GameObject;
            tmpBtnQueue.Push(b);
            //btnPool.Enqueue(b);
            ButtonData tmpBD = b.GetComponent <ButtonData>();
            tmpBD.SetScoreManager(scoreManager);
            tmpBD.SetPoolManager(this);
            tmpBD.SetSpeed(speed);
            b.SetActive(false);
        }
        for (int i = 0; i < num; ++i)
        {
            btnPool.Enqueue(tmpBtnQueue.Pop());
        }
        isCreate = true;
    }