Esempio n. 1
0
    public void UpdatePosition()
    {
        if (list == null)
        {
            return;
        }

        List <UIMenuListItem> childItems = list.GetChildItems(parent);

        int count = childItems.Count;

        for (int i = 0; i < childItems.Count; i++)
        {
            if (childItems[i] != null)
            {
                GameObject obj = childItems[i].gameObject;
                obj.transform.localPosition       = new Vector3(0f, -i * list.ItemSize.y, 0f);
                childItems[i].Box_Collider.center = new Vector3(list.ItemSize.x / 2 - 29, 0, 0);
                childItems[i].Box_Collider.size   = new Vector3(list.ItemSize.x, list.ItemSize.y, -2);
                obj.SetActive(true);
            }
        }

        //int bgScale_x = Convert.ToInt32( list.Margin.x + list.ItemSize.x + list.Margin.z);
        int bgScale_x = Convert.ToInt32(list.ItemSize.x);
        int bgScale_y = Convert.ToInt32(list.Margin.y + list.ItemSize.y * count + list.Margin.w);

        spBg.transform.localScale = new Vector3(bgScale_x, bgScale_y, 1);

        int content_x = Convert.ToInt32(list.Margin.x);
        int content_y = Convert.ToInt32(-list.Margin.y + (list.ItemSize.y * count) / 2);

        content.transform.localPosition = new Vector3(content_x - 4, content_y, 0);

        // update panel position
        if (parent != null)
        {
            Vector3 parentPos = parent.gameObject.transform.localPosition;
            parentPos += parent.gameObject.transform.parent.localPosition;
            parentPos += parent.gameObject.transform.parent.parent.localPosition;

            int panel_x = Convert.ToInt32(parentPos.x + list.PanelMargin.x);
            int panel_y = Convert.ToInt32(parentPos.y + list.PanelMargin.y);
            this.gameObject.transform.localPosition = new Vector3(panel_x - 5, panel_y, 0);

            spBg.pivot          = UIWidget.Pivot.Left;
            mBoxCollider.center = new Vector3(0.5f, 0f, 0);
        }
        else
        {
            spBg.pivot          = UIWidget.Pivot.Bottom;
            mBoxCollider.center = new Vector3(0f, 0.5f, 0);
        }
    }