Exemplo n.º 1
0
        protected ComUIListElementScript CreateElement(int index, ref stRect rect)
        {
            ComUIListElementScript item = null;

            if (this.m_unUsedElementScripts.Count > 0)
            {
                item = this.m_unUsedElementScripts[0];
                this.m_unUsedElementScripts.RemoveAt(0);
            }
            else if (this.m_elementTemplate != null)
            {
                GameObject root = InstantiateElement(this.m_elementTemplate);
                root.transform.SetParent(this.m_content.transform);
                root.transform.localScale = Vector3.one;
                item = root.GetComponent <ComUIListElementScript>();
            }
            if (item != null)
            {
                if (onBindItem != null && item.gameObjectBindScript == null)
                {
                    item.gameObjectBindScript = onBindItem(item.gameObject);
                }

                item.Initialize();
                item.Enable(this, index, this.m_elementName, ref rect, this.IsSelectedIndex(index));
                this.m_elementScripts.Add(item);

                if (onItemVisiable != null)
                {
                    onItemVisiable(item);
                }
            }
            return(item);
        }
Exemplo n.º 2
0
        protected virtual void ProcessElements()
        {
            this.m_contentSize = Vector2.zero;
            Vector2 zero = Vector2.zero;

            if ((this.m_listType == enUIListType.Vertical) || (this.m_listType == enUIListType.VerticalGrid))
            {
                zero.y += this.m_elementLayoutOffset;
            }
            else
            {
                zero.x += this.m_elementLayoutOffset;
            }

            zero.x += this.m_elementPadding.x;
            zero.y -= this.m_elementPadding.y;

            for (int i = 0; i < this.m_elementAmount; i++)
            {
                stRect item = this.LayoutElement(i, ref this.m_contentSize, ref zero);
                if (this.m_useOptimized)
                {
                    if (i < this.m_elementsRect.Count)
                    {
                        this.m_elementsRect[i] = item;
                    }
                    else
                    {
                        this.m_elementsRect.Add(item);
                    }
                }
                if (!this.m_useOptimized || this.IsRectInScrollArea(ref item))
                {
                    this.CreateElement(i, ref item);
                }
            }

            if ((this.m_listType == enUIListType.Vertical) || (this.m_listType == enUIListType.VerticalGrid))
            {
                m_contentSize.y += this.m_elementPadding.y;
            }
            else
            {
                m_contentSize.x += this.m_elementPadding.x;
            }

            if (this.m_extraContent != null)
            {
                if (this.m_elementAmount > 0)
                {
                    this.ProcessExtraContent(ref this.m_contentSize, zero);
                }
                else
                {
                    this.m_extraContent.SetActive(false);
                    //this.m_extraContent.CustomActive(false);
                }
            }
            this.ResizeContent(ref this.m_contentSize, false);
        }
Exemplo n.º 3
0
        protected bool IsRectInScrollArea(ref stRect rect)
        {
            Vector2 zero = Vector2.zero;

            zero.x = this.m_contentRectTransform.anchoredPosition.x + rect.m_left;
            zero.y = this.m_contentRectTransform.anchoredPosition.y + rect.m_top;
            return((((zero.x + rect.m_width) >= 0f) && (zero.x <= this.m_scrollAreaSize.x)) && (((zero.y - rect.m_height) <= 0f) && (zero.y >= -this.m_scrollAreaSize.y)));
        }
Exemplo n.º 4
0
        public void SetRect(ref stRect rect)
        {
            this.m_rect = rect;
            RectTransform transform = base.gameObject.transform as RectTransform;

            transform.sizeDelta        = new Vector2((float)this.m_rect.m_width, (float)this.m_rect.m_height);
            transform.anchoredPosition = new Vector2((float)rect.m_left, (float)rect.m_top);
        }
Exemplo n.º 5
0
        public bool IsElementInScrollArea(int index)
        {
            if ((index < 0) || (index >= this.m_elementAmount))
            {
                return(false);
            }
            stRect rect = !this.m_useOptimized ? this.m_elementScripts[index].m_rect : this.m_elementsRect[index];

            return(this.IsRectInScrollArea(ref rect));
        }
Exemplo n.º 6
0
 public void EnsureElementVisable(int index)
 {
     if ((this.m_listType == enUIListType.Vertical) || (this.m_listType == enUIListType.VerticalGrid))
     {
         stRect rect = GetElementRect(index);
         //float value = rect.m_top / (contentSize.y - m_scrollAreaSize.y);
         //m_scrollBar.value = value;
         m_contentRectTransform.anchoredPosition = new Vector2(m_contentRectTransform.anchoredPosition.x, -rect.m_top);
     }
 }
Exemplo n.º 7
0
        protected stRect LayoutElement(int index, ref Vector2 contentSize, ref Vector2 offset)
        {
            stRect rect;

            rect = new stRect();

            rect.m_width  = (((this.m_elementsSize != null) && (this.m_listType != enUIListType.Vertical)) && ((this.m_listType != enUIListType.VerticalGrid) && (this.m_listType != enUIListType.HorizontalGrid))) ? ((int)this.m_elementsSize[index].x) : ((int)this.m_elementDefaultSize.x);
            rect.m_height = (((this.m_elementsSize != null) && (this.m_listType != enUIListType.Horizontal)) && ((this.m_listType != enUIListType.VerticalGrid) && (this.m_listType != enUIListType.HorizontalGrid))) ? ((int)this.m_elementsSize[index].y) : ((int)this.m_elementDefaultSize.y);
            rect.m_left   = (int)offset.x;
            rect.m_top    = (int)offset.y;
            rect.m_right  = rect.m_left + rect.m_width;
            rect.m_bottom = rect.m_top - rect.m_height;
            rect.m_center = new Vector2(rect.m_left + (rect.m_width * 0.5f), rect.m_top - (rect.m_height * 0.5f));

            if (rect.m_right > contentSize.x)
            {
                contentSize.x = rect.m_right;
            }
            if (-rect.m_bottom > contentSize.y)
            {
                contentSize.y = -rect.m_bottom;
            }
            switch (this.m_listType)
            {
            case enUIListType.Vertical:
                offset.y -= rect.m_height + this.m_elementSpacing.y;
                return(rect);

            case enUIListType.Horizontal:
                offset.x += rect.m_width + this.m_elementSpacing.x;
                return(rect);

            case enUIListType.VerticalGrid:
                offset.x += rect.m_width + this.m_elementSpacing.x;
                if ((offset.x + rect.m_width) > this.m_scrollAreaSize.x)
                {
                    offset.x  = 0f;
                    offset.y -= rect.m_height + this.m_elementSpacing.y;
                }
                return(rect);

            case enUIListType.HorizontalGrid:
                offset.y -= rect.m_height + this.m_elementSpacing.y;
                if ((-offset.y + rect.m_height) > this.m_scrollAreaSize.y)
                {
                    offset.y  = 0f;
                    offset.x += rect.m_width + this.m_elementSpacing.x;
                }
                return(rect);
            }
            return(rect);
        }
Exemplo n.º 8
0
 public void Enable(ComUIListScript belongedList, int index, string name, ref stRect rect, bool selected)
 {
     m_belongedListScript = belongedList;
     this.m_index         = index;
     base.gameObject.name = name + "_" + index.ToString();
     if (this.m_useSetActiveForDisplay)
     {
         gameObject.CustomActive(true);
     }
     else
     {
         this.m_canvasGroup.alpha          = 1f;
         this.m_canvasGroup.blocksRaycasts = true;
     }
     this.SetComponentBelongedList(base.gameObject);
     this.SetRect(ref rect);
     this.ChangeDisplay(selected);
 }
Exemplo n.º 9
0
        protected void UpdateElementsScroll()
        {
            int num = 0;

            while (num < this.m_elementScripts.Count)
            {
                if (!this.IsRectInScrollArea(ref this.m_elementScripts[num].m_rect))
                {
                    this.RecycleElement(this.m_elementScripts[num], true);
                }
                else
                {
                    num++;
                }
            }
            for (int i = 0; i < this.m_elementAmount; i++)
            {
                stRect rect = this.m_elementsRect[i];
                if (this.IsRectInScrollArea(ref rect))
                {
                    bool flag = false;
                    for (int j = 0; j < this.m_elementScripts.Count; j++)
                    {
                        if (this.m_elementScripts[j].m_index == i)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        this.CreateElement(i, ref rect);
                    }
                }
            }
        }
Exemplo n.º 10
0
 public void MoveElementInScrollArea(int index, bool moveImmediately)
 {
     if ((index >= 0) && (index < this.m_elementAmount))
     {
         Vector2 zero    = Vector2.zero;
         Vector2 vector2 = Vector2.zero;
         stRect  rect    = !this.m_useOptimized ? this.m_elementScripts[index].m_rect : this.m_elementsRect[index];
         vector2.x = this.m_contentRectTransform.anchoredPosition.x + rect.m_left;
         vector2.y = this.m_contentRectTransform.anchoredPosition.y + rect.m_top;
         if (vector2.x < 0f)
         {
             zero.x = -vector2.x;
         }
         else if ((vector2.x + rect.m_width) > this.m_scrollAreaSize.x)
         {
             zero.x = this.m_scrollAreaSize.x - (vector2.x + rect.m_width);
         }
         if (vector2.y > 0f)
         {
             zero.y = -vector2.y;
         }
         else if ((vector2.y - rect.m_height) < -this.m_scrollAreaSize.y)
         {
             zero.y = -this.m_scrollAreaSize.y - (vector2.y - rect.m_height);
         }
         if (moveImmediately)
         {
             this.m_contentRectTransform.anchoredPosition += zero;
         }
         else
         {
             Vector2 to = this.m_contentRectTransform.anchoredPosition + zero;
             //LeanTween.value(base.gameObject, pos => this.m_contentRectTransform.anchoredPosition = pos, this.m_contentRectTransform.anchoredPosition, to, this.m_fSpeed);
         }
     }
 }