コード例 #1
0
    // Use this for initialization
    void Start()
    {
        currentPosition = originalPosition;

        //we fill the list with empty stackpieces with default information.
        pool = new LinkedList <StackPiece>();
        for (int i = 0; i < poolSize; i++)
        {
            int        rNum  = Random.Range(0, QueueCars.Length);
            StackPiece clone = Instantiate <StackPiece>(QueueCars[rNum]);
            clone.gameObject.SetActive(false);
            clone.transform.SetParent(this.transform);
            clone.transform.position = currentPosition;
            pool.AddLast(clone);
        }
        for (int i = 1; i < 5; i++)
        {
            stackinground [i].gameObject.SetActive(false);
        }
    }
コード例 #2
0
    // activates a stack piece and changes its name this also chaning the value that it displays
    void Spawn()
    {
        //if the list is empty (we reached the limit of the stack) we will display this debug message
        if (pool.Count == 0)
        {
            Debug.Log("Nothing left to spawn ...");
            return;
        }
        // this line obtains the value that the newest element in the stack has
        string newtext = QueueManager.getQueueManager().queueList.last();
        // this gets the first stackpiece object that is store in the list
        StackPiece next = pool.First.Value;

        // the following two lines active the piece and changes its name to
        // the text of the last piece inserted into the stack respectively
        next.transform.position = currentPosition;
        next.gameObject.SetActive(true);
        next.name = newtext;
        // We assign to the piece the same index number it would have in the stack so we can find it later
        next.setIndex(StackManager.getCurrentStackManager().numberOfElements() - 1);
        // the stackpiece is removed from the stack list pool
        pool.RemoveFirst();
    }