Example #1
0
    protected bool IsRectInScrollArea(ref stRect rect)
    {
        Vector2 zero = Vector2.zero;

        zero.x = m_contentRectTransform.anchoredPosition.x + (float)rect.m_left;
        zero.y = m_contentRectTransform.anchoredPosition.y + (float)rect.m_top;
        return(zero.x + (float)rect.m_width >= 0f && zero.x <= scrollAreaSize.x && zero.y - (float)rect.m_height <= 0f && zero.y >= -scrollAreaSize.y);
    }
Example #2
0
    public bool IsElementInScrollArea(int index)
    {
        if (index < 0 || index >= elementAmount)
        {
            return(false);
        }
        stRect stRect = (!useOptimized) ? m_elementScripts[index].m_rect : m_elementsRect[index];

        return(IsRectInScrollArea(ref stRect));
    }
Example #3
0
    protected stRect LayoutElement(int index, ref Vector2 contentSize, ref Vector2 offset)
    {
        stRect result = default(stRect);

        result.m_width  = (int)((m_elementsSize != null && listType != enUIListType.Vertical && listType != enUIListType.VerticalGrid && listType != enUIListType.HorizontalGrid) ? m_elementsSize[index].x : m_elementDefaultSize.x);
        result.m_height = (int)((m_elementsSize != null && listType != enUIListType.Horizontal && listType != enUIListType.VerticalGrid && listType != enUIListType.HorizontalGrid) ? m_elementsSize[index].y : m_elementDefaultSize.y);
        result.m_left   = (int)offset.x;
        result.m_top    = (int)offset.y;
        result.m_right  = result.m_left + result.m_width;
        result.m_bottom = result.m_top - result.m_height;
        result.m_center = new Vector2((float)result.m_left + (float)result.m_width * 0.5f, (float)result.m_top - (float)result.m_height * 0.5f);
        if ((float)result.m_right > contentSize.x)
        {
            contentSize.x = (float)result.m_right;
        }
        if ((float)(-(float)result.m_bottom) > contentSize.y)
        {
            contentSize.y = (float)(-(float)result.m_bottom);
        }
        switch (listType)
        {
        case enUIListType.Vertical:
            offset.y -= (float)result.m_height + elementSpacing.y;
            break;

        case enUIListType.Horizontal:
            offset.x += (float)result.m_width + elementSpacing.x;
            break;

        case enUIListType.VerticalGrid:
            offset.x += (float)result.m_width + elementSpacing.x;
            if (offset.x + (float)result.m_width > scrollAreaSize.x)
            {
                offset.x  = 0f;
                offset.y -= (float)result.m_height + elementSpacing.y;
            }
            break;

        case enUIListType.HorizontalGrid:
            offset.y -= (float)result.m_height + elementSpacing.y;
            if (-offset.y + (float)result.m_height > scrollAreaSize.y)
            {
                offset.y  = 0f;
                offset.x += (float)result.m_width + elementSpacing.x;
            }
            break;
        }
        return(result);
    }
Example #4
0
    public void SetRect(ref stRect rect)
    {
        m_rect = rect;
        RectTransform rectTransform = gameObject.transform as RectTransform;

        rectTransform.sizeDelta = new Vector2((float)m_rect.m_width, (float)m_rect.m_height);
        if (m_pivotType == enPivotType.Centre)
        {
            rectTransform.anchoredPosition = rect.m_center;
        }
        else
        {
            rectTransform.anchoredPosition = new Vector2((float)rect.m_left, (float)rect.m_top);
        }
    }
Example #5
0
    protected virtual void ProcessElements()
    {
        m_contentSize = Vector2.zero;
        Vector2 zero = Vector2.zero;

        if (listType == enUIListType.Vertical || listType == enUIListType.VerticalGrid)
        {
            zero.y += elementLayoutOffset;
        }
        else
        {
            zero.x += elementLayoutOffset;
        }
        for (int i = 0; i < elementAmount; i++)
        {
            stRect stRect = LayoutElement(i, ref m_contentSize, ref zero);
            if (useOptimized)
            {
                if (i < m_elementsRect.Count)
                {
                    m_elementsRect[i] = stRect;
                }
                else
                {
                    m_elementsRect.Add(stRect);
                }
            }
            if (!useOptimized || IsRectInScrollArea(ref stRect))
            {
                CreateElement(i, ref stRect);
            }
        }
        if (extraContent != null)
        {
            if (elementAmount > 0 && m_isExtraContentEnabled)
            {
                ProcessExtraContent(ref m_contentSize, zero);
            }
            else
            {
                extraContent.SetActive(false);
            }
        }
        ResizeContent(ref m_contentSize, false);
    }
Example #6
0
 public void Enable(UIListScript belongedList, int index, string name, ref stRect rect, bool selected)
 {
     belongedListScript = belongedList;
     m_index            = index;
     gameObject.name    = name + "_" + index.ToString();
     if (m_useSetActiveForDisplay)
     {
         base.gameObject.SetActive(true);
     }
     else
     {
         m_canvasGroup.alpha          = 1f;
         m_canvasGroup.blocksRaycasts = true;
     }
     SetComponentBelongedList(gameObject);
     SetRect(ref rect);
     ChangeDisplay(selected);
     DispatchOnEnableEvent();
 }
Example #7
0
    public void MoveElementInScrollArea(int index, bool moveImmediately)
    {
        if (index < 0 || index >= elementAmount)
        {
            return;
        }
        Vector2 zero   = Vector2.zero;
        Vector2 zero2  = Vector2.zero;
        stRect  stRect = (!useOptimized) ? m_elementScripts[index].m_rect : m_elementsRect[index];

        zero2.x = m_contentRectTransform.anchoredPosition.x + (float)stRect.m_left;
        zero2.y = m_contentRectTransform.anchoredPosition.y + (float)stRect.m_top;
        if (zero2.x < 0f)
        {
            zero.x = -zero2.x;
        }
        else if (zero2.x + (float)stRect.m_width > scrollAreaSize.x)
        {
            zero.x = scrollAreaSize.x - (zero2.x + (float)stRect.m_width);
        }
        if (zero2.y > 0f)
        {
            zero.y = -zero2.y;
        }
        else if (zero2.y - (float)stRect.m_height < -scrollAreaSize.y)
        {
            zero.y = -scrollAreaSize.y - (zero2.y - (float)stRect.m_height);
        }
        if (moveImmediately)
        {
            m_contentRectTransform.anchoredPosition += zero;
        }
        else
        {
            //Vector2 to = m_contentRectTransform.anchoredPosition + zero;
            //LeanTween.value(base.gameObject, delegate(Vector2 pos)
            //{
            //    m_contentRectTransform.anchoredPosition = pos;
            //}, m_contentRectTransform.anchoredPosition, to, fSpeed);
        }
    }
Example #8
0
    protected UIListElementScript CreateElement(int index, ref stRect rect)
    {
        UIListElementScript uiListElementScript = null;

        if (m_unUsedElementScripts.Count > 0)
        {
            uiListElementScript = m_unUsedElementScripts[0];
            m_unUsedElementScripts.RemoveAt(0);
        }
        else if (m_elementTemplate != null)
        {
            GameObject gameObject1 = GameObject.Instantiate(m_elementTemplate);
            gameObject1.transform.SetParent(m_content.transform);
            gameObject1.transform.localScale = Vector3.one;
            base.InitializeComponent(gameObject1);
            uiListElementScript = gameObject1.GetComponent <UIListElementScript>();
        }
        if (uiListElementScript != null)
        {
            uiListElementScript.Enable(this, index, m_elementName, ref rect, IsSelectedIndex(index));
            m_elementScripts.Add(uiListElementScript);
        }
        return(uiListElementScript);
    }
Example #9
0
    protected void UpdateElementsScroll()
    {
        int i = 0;

        while (i < m_elementScripts.Count)
        {
            if (!IsRectInScrollArea(ref m_elementScripts[i].m_rect))
            {
                RecycleElement(m_elementScripts[i], true);
            }
            else
            {
                i++;
            }
        }
        for (int j = 0; j < elementAmount; j++)
        {
            stRect stRect = m_elementsRect[j];
            if (IsRectInScrollArea(ref stRect))
            {
                bool flag = false;
                for (int k = 0; k < m_elementScripts.Count; k++)
                {
                    if (m_elementScripts[k].m_index == j)
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    CreateElement(j, ref stRect);
                }
            }
        }
    }