Example #1
0
    void InitializePositionVars()
    {
        /* The the reference of canvas plane */
        _parentCanvas = GetComponentInParent <Canvas>();

        /* Get the max position of canvas plane in the canvas space.
         * Assume that the origin of the canvas space is at the center of canvas plane. */
        RectTransform rectTransform = _parentCanvas.GetComponent <RectTransform>();

        canvasMaxPos_L = new Vector2(rectTransform.rect.width / 2, rectTransform.rect.height / 2);

        listBoxes = new List <ListBox>();
        for (int i = 0; i < listBank.GetListLength(); i++)
        {
            GameObject listBox = Instantiate(box, box.transform.position, Quaternion.identity, parent);
            listBoxes.Add(listBox.GetComponent <ListBox>());
            //listBoxes =  new ListBox[]{listBox.GetComponent<ListBox>()};
        }

        unitPos_L       = canvasMaxPos_L / boxGapFactor;
        lowerBoundPos_L = unitPos_L * (-1 * listBoxes.Count / 2 - 1);
        upperBoundPos_L = unitPos_L * (listBoxes.Count / 2 + 1);

        // If there are even number of ListBoxes, narrow the boundary for 1 unitPos.
        if ((listBoxes.Count & 0x1) == 0)
        {
            lowerBoundPos_L += unitPos_L / 2;
            upperBoundPos_L -= unitPos_L / 2;
        }
    }
Example #2
0
    /* Initialize the content of ListBox.
     */
    void InitialContent()
    {
        // Get the content ID of the centered box
        _contentID = _positionCtrl.centeredContentID;

        // Adjust the contentID accroding to its initial order.
        _contentID += listBoxID - _positionCtrl.listBoxes.Length / 2;

        // In the linear mode, disable the box if needed
        if (_positionCtrl.listType == ListPositionCtrl.ListType.Linear)
        {
            // Disable the boxes at the upper half of the list
            // which will hold the item at the tail of the contents.
            if (_contentID < 0)
            {
                _positionCtrl.numOfUpperDisabledBoxes += 1;
                gameObject.SetActive(false);
            }
            // Disable the box at the lower half of the list
            // which will hold the repeated item.
            else if (_contentID >= _listBank.GetListLength())
            {
                _positionCtrl.numOfLowerDisabledBoxes += 1;
                gameObject.SetActive(false);
            }
        }

        // Round the content id
        while (_contentID < 0)
        {
            _contentID += _listBank.GetListLength();
        }
        _contentID = _contentID % _listBank.GetListLength();

        UpdateDisplayContent();
    }