Exemple #1
0
    protected void LayoutContentItemsVertical()
    {
        // Vertical ScrollviewContentItems should be anchored to their top.
        float currentY = 0;
        float currentX = 0;

        for (int i = 0; i < m_Items.Count; i++)
        {
            ScrollviewContentItem <T> item = m_Items[i];
            item.RectTransform.anchoredPosition = new Vector2(currentX, currentY);
            // Explicitly update position for revealer as well.
            if (item.canvasGroupRevealer != null)
            {
                item.canvasGroupRevealer.UpdateOriginalPosition();
            }

            if (item.gameObject.activeSelf == false)
            {
                item.gameObject.SetActive(true);
            }

            currentX += item.ContentItemSize.x;

            if ((i % m_ItemsPerLine) == (m_ItemsPerLine - 1))
            {
                currentX  = 0;
                currentY -= CalcRowHeightAtIndex(i);
            }
        }
    }
    protected void CreateEnoughItems(int targetCount)
    {
        while (m_ItemPrefabInstances.Count < targetCount)
        {
            GameObject neoObj = GameObject.Instantiate(m_ItemPrefab as UnityEngine.GameObject);
            ScrollviewContentItem <T> neoItem = neoObj.GetComponent <ScrollviewContentItem <T> >();

            neoItem.Init();
            neoItem.OnItemClicked += ItemClicked;

            if (neoItem is DraggableScrollviewContentItem <T> )
            {
                DraggableScrollviewContentItem <T> draggableItem = neoItem as DraggableScrollviewContentItem <T>;
                if (draggableItem != null)
                {
                    draggableItem.OnDragBegin += ItemDragBegin;
                    draggableItem.OnDragEnd   += ItemDragEnd;
                    draggableItem.OnDragging  += ItemDragging;
                }
            }

            neoItem.gameObject.SetActive(false);
            base.AddContentItem(neoItem);
            m_ItemPrefabInstances.Add(neoItem);
        }
    }
 protected void ItemClicked(string eventStr, ScrollviewContentItem <T> item)
 {
     if (OnItemClicked != null)
     {
         OnItemClicked(eventStr, item);
     }
 }
Exemple #4
0
    public void AddContentItem(ScrollviewContentItem <T> contentItem)
    {
        // if (m_Spinner && m_Spinner.enabled){
        //  m_Spinner.enabled = false;
        //  m_Spinner.Hide();
        // }

        contentItem.SetScrollviewContent(this);
        contentItem.RectTransform.SetParent(m_RectTransform, false);
        contentItem.RectTransform.anchoredPosition = new Vector3(0, 0, 0);
        contentItem.RectTransform.localScale       = new Vector3(1, 1, 1);

        m_Items.Add(contentItem);
        RepositionContentItems();
    }
Exemple #5
0
 public void RemoveContentItem(ScrollviewContentItem <T> contentItem)
 {
     m_Items.Remove(contentItem);
     RepositionContentItems();
 }