Пример #1
0
        public override void Initialize(CUIFormScript formScript)
        {
            if (this.m_isInitialized)
            {
                return;
            }
            base.Initialize(formScript);
            this.m_selectedElementIndex     = -1;
            this.m_lastSelectedElementIndex = -1;
            this.m_scrollRect = base.GetComponentInChildren <ScrollRect>(base.gameObject);
            if (this.m_scrollRect != null)
            {
                this.m_scrollRect.enabled = false;
                RectTransform rectTransform = this.m_scrollRect.transform as RectTransform;
                this.m_scrollAreaSize = new Vector2(rectTransform.rect.width, rectTransform.rect.height);
                this.m_content        = this.m_scrollRect.content.gameObject;
            }
            this.m_scrollBar = base.GetComponentInChildren <Scrollbar>(base.gameObject);
            if (this.m_listType == enUIListType.Vertical || this.m_listType == enUIListType.VerticalGrid)
            {
                if (this.m_scrollBar != null)
                {
                    this.m_scrollBar.direction = Scrollbar.Direction.BottomToTop;
                }
                DebugHelper.Assert(this.m_scrollRect != null);
                if (this.m_scrollRect != null)
                {
                    this.m_scrollRect.horizontal          = false;
                    this.m_scrollRect.vertical            = true;
                    this.m_scrollRect.horizontalScrollbar = null;
                    this.m_scrollRect.verticalScrollbar   = this.m_scrollBar;
                }
            }
            else if (this.m_listType == enUIListType.Horizontal || this.m_listType == enUIListType.HorizontalGrid)
            {
                if (this.m_scrollBar != null)
                {
                    this.m_scrollBar.direction = Scrollbar.Direction.LeftToRight;
                }
                DebugHelper.Assert(this.m_scrollRect != null);
                if (this.m_scrollRect != null)
                {
                    this.m_scrollRect.horizontal          = true;
                    this.m_scrollRect.vertical            = false;
                    this.m_scrollRect.horizontalScrollbar = this.m_scrollBar;
                    this.m_scrollRect.verticalScrollbar   = null;
                }
            }
            this.m_elementScripts       = new ListView <CUIListElementScript>();
            this.m_unUsedElementScripts = new ListView <CUIListElementScript>();
            if (this.m_useOptimized && this.m_elementsRect == null)
            {
                this.m_elementsRect = new List <stRect>();
            }
            CUIListElementScript cUIListElementScript = null;

            if (this.m_useExternalElement)
            {
                GameObject gameObject = null;
                if (this.m_externalElementPrefabPath != null)
                {
                    gameObject = (GameObject)Singleton <CResourceManager> .GetInstance().GetResource(this.m_externalElementPrefabPath, typeof(GameObject), 4, false, false).m_content;

                    if (gameObject != null)
                    {
                        cUIListElementScript = gameObject.GetComponent <CUIListElementScript>();
                    }
                }
                if (cUIListElementScript != null && gameObject != null)
                {
                    cUIListElementScript.Initialize(formScript);
                    this.m_elementTemplate    = gameObject;
                    this.m_elementName        = gameObject.name;
                    this.m_elementDefaultSize = cUIListElementScript.m_defaultSize;
                }
            }
            else
            {
                cUIListElementScript = base.GetComponentInChildren <CUIListElementScript>(base.gameObject);
                if (cUIListElementScript != null)
                {
                    cUIListElementScript.Initialize(formScript);
                    this.m_elementTemplate    = cUIListElementScript.gameObject;
                    this.m_elementName        = cUIListElementScript.gameObject.name;
                    this.m_elementDefaultSize = cUIListElementScript.m_defaultSize;
                    if (this.m_elementTemplate != null)
                    {
                        this.m_elementTemplate.name = this.m_elementName + "_Template";
                    }
                }
            }
            if (this.m_elementTemplate != null)
            {
                CUIListElementScript component = this.m_elementTemplate.GetComponent <CUIListElementScript>();
                if (component != null && component.m_useSetActiveForDisplay)
                {
                    this.m_elementTemplate.CustomSetActive(false);
                }
                else
                {
                    if (!this.m_elementTemplate.activeSelf)
                    {
                        this.m_elementTemplate.SetActive(true);
                    }
                    CanvasGroup canvasGroup = this.m_elementTemplate.GetComponent <CanvasGroup>();
                    if (canvasGroup == null)
                    {
                        canvasGroup = this.m_elementTemplate.AddComponent <CanvasGroup>();
                    }
                    canvasGroup.alpha          = 0f;
                    canvasGroup.blocksRaycasts = false;
                }
            }
            if (this.m_content != null)
            {
                this.m_contentRectTransform                  = (this.m_content.transform as RectTransform);
                this.m_contentRectTransform.pivot            = new Vector2(0f, 1f);
                this.m_contentRectTransform.anchorMin        = new Vector2(0f, 1f);
                this.m_contentRectTransform.anchorMax        = new Vector2(0f, 1f);
                this.m_contentRectTransform.anchoredPosition = Vector2.zero;
                this.m_contentRectTransform.localRotation    = Quaternion.identity;
                this.m_contentRectTransform.localScale       = new Vector3(1f, 1f, 1f);
                this.m_lastContentPosition = this.m_contentRectTransform.anchoredPosition;
            }
            if (this.m_extraContent != null)
            {
                RectTransform rectTransform2 = this.m_extraContent.transform as RectTransform;
                rectTransform2.pivot            = new Vector2(0f, 1f);
                rectTransform2.anchorMin        = new Vector2(0f, 1f);
                rectTransform2.anchorMax        = new Vector2(0f, 1f);
                rectTransform2.anchoredPosition = Vector2.zero;
                rectTransform2.localRotation    = Quaternion.identity;
                rectTransform2.localScale       = Vector3.one;
                if (this.m_elementTemplate != null)
                {
                    rectTransform2.sizeDelta = new Vector2((this.m_elementTemplate.transform as RectTransform).rect.width, rectTransform2.sizeDelta.y);
                }
                if (rectTransform2.parent != null && this.m_content != null)
                {
                    rectTransform2.parent.SetParent(this.m_content.transform);
                }
                this.m_extraContent.SetActive(false);
            }
            this.m_isExtraContentEnabled = true;
            if (this.m_elementTemplate != null)
            {
                this.SetElementAmount(this.m_elementAmount);
            }
        }
Пример #2
0
 protected override void Update()
 {
     if (this.m_belongedFormScript != null && this.m_belongedFormScript.IsClosed())
     {
         return;
     }
     if (this.m_useOptimized)
     {
         base.UpdateElementsScroll();
     }
     if (this.m_bDontUpdate || this.m_scrollRect == null)
     {
         return;
     }
     for (int i = 0; i < this.m_elementAmount; i++)
     {
         CUIListElementScript elemenet = base.GetElemenet(i);
         if (elemenet != null)
         {
             elemenet.gameObject.transform.localScale = Vector3.one * this.GetElementScale(i);
         }
     }
     if (this.m_fixingScroll && this.m_selectedElementIndex >= 0 && this.m_selectedElementIndex < this.m_elementAmount)
     {
         this.m_scrollRect.enabled = false;
         float num = this.m_contentRectTransform.anchoredPosition.x + this.m_fixScrollSpeed;
         if ((num > this.m_contentFixScrollTargetPosition && this.m_fixScrollSpeed > 0f) || (num < this.m_contentFixScrollTargetPosition && this.m_fixScrollSpeed < 0f))
         {
             this.m_contentRectTransform.anchoredPosition = new Vector2(this.m_contentFixScrollTargetPosition, this.m_contentRectTransform.anchoredPosition.y);
             this.m_fixScrollSpeed = 0f;
             this.m_fixingScroll   = false;
             this.m_scrollRect.StopMovement();
         }
         else
         {
             this.m_contentRectTransform.anchoredPosition = new Vector2(num, this.m_contentRectTransform.anchoredPosition.y);
         }
     }
     else
     {
         this.m_scrollRect.enabled = true;
         FieldInfo field = this.m_scrollRect.GetType().GetField("m_Dragging", 36);
         if (!(bool)field.GetValue(this.m_scrollRect))
         {
             if (this.m_scrollRectIsDragged)
             {
                 float num2 = Mathf.Abs(this.m_scrollRect.velocity.x);
                 int   num3 = -1;
                 if (this.m_contentRectTransform.anchoredPosition.x > 0f)
                 {
                     num3 = 0;
                 }
                 else if (this.m_contentRectTransform.anchoredPosition.x + this.m_contentSize.x < this.m_scrollAreaSize.x)
                 {
                     num3 = this.m_elementAmount - 1;
                 }
                 else if (num2 <= this.m_scrollRectLastScrollSpeed && num2 < this.m_minSpeedToFixScroll)
                 {
                     for (int j = 0; j < this.m_elementAmount; j++)
                     {
                         if (num3 < 0 && this.IsElementInSelectedArea(j))
                         {
                             num3 = j;
                             break;
                         }
                     }
                 }
                 if (num3 >= 0)
                 {
                     this.SelectElement(num3, true);
                     this.m_scrollRectIsDragged = false;
                 }
             }
             else if (this.m_selectedElementIndex >= 0 && this.m_selectedElementIndex < this.m_elementAmount && this.m_contentRectTransform.anchoredPosition.x != this.m_contentFixScrollTargetPosition)
             {
                 this.m_contentRectTransform.anchoredPosition = new Vector2(this.m_contentFixScrollTargetPosition, this.m_contentRectTransform.anchoredPosition.y);
                 for (int k = 0; k < this.m_elementAmount; k++)
                 {
                     CUIListElementScript elemenet2 = base.GetElemenet(k);
                     if (elemenet2 != null)
                     {
                         elemenet2.gameObject.transform.localScale = Vector3.one * this.GetElementScale(k);
                     }
                 }
             }
         }
         else
         {
             if (!this.m_scrollRectIsDragged)
             {
                 this.DispatchOnStartDraggingEvent();
             }
             this.m_scrollRectIsDragged = true;
         }
         this.m_scrollRectLastScrollSpeed = Mathf.Abs(this.m_scrollRect.velocity.x);
     }
     base.DetectScroll();
 }
Пример #3
0
        private void UpdateSelectedElement(enExpandListSelectingState selectingState)
        {
            Vector2 zero;
            int     num7;

            switch (selectingState)
            {
            case enExpandListSelectingState.Retract:
                if (this.m_timeSlice >= this.m_expandedTime)
                {
                    if ((base.m_selectedElementIndex >= 0) && (base.m_selectedElementIndex < base.m_elementAmount))
                    {
                        this.m_targetContentAnchoredPosition = this.GetTargetContentAnchoredPosition(base.m_selectedElementIndex);
                        this.m_selectingState = enExpandListSelectingState.Move;
                        this.m_timeSlice      = 0f;
                    }
                    else
                    {
                        this.m_selectingState = enExpandListSelectingState.None;
                    }
                    goto Label_055A;
                }
                this.m_timeSlice  += Time.deltaTime;
                base.m_contentSize = Vector2.zero;
                zero = Vector2.zero;
                if (base.m_listType != enUIListType.Horizontal)
                {
                    if (base.m_listType == enUIListType.Vertical)
                    {
                        zero.y += base.m_elementLayoutOffset;
                    }
                    break;
                }
                zero.x += base.m_elementLayoutOffset;
                break;

            case enExpandListSelectingState.Move:
                if (!(this.m_contentAnchoredPosition != this.m_targetContentAnchoredPosition))
                {
                    this.m_selectingState = enExpandListSelectingState.Expand;
                    this.m_timeSlice      = 0f;
                }
                else if (base.m_listType != enUIListType.Horizontal)
                {
                    if (base.m_listType == enUIListType.Vertical)
                    {
                        int num4 = (this.m_targetContentAnchoredPosition.y <= this.m_contentAnchoredPosition.y) ? -1 : 1;
                        this.m_contentAnchoredPosition.y += (Time.deltaTime * this.m_contentFixingSpeed) * num4;
                        if (((num4 > 0) && (this.m_contentAnchoredPosition.y >= this.m_targetContentAnchoredPosition.y)) || ((num4 < 0) && (this.m_contentAnchoredPosition.y <= this.m_targetContentAnchoredPosition.y)))
                        {
                            this.m_contentAnchoredPosition = this.m_targetContentAnchoredPosition;
                        }
                    }
                }
                else
                {
                    int num3 = (this.m_targetContentAnchoredPosition.x <= this.m_contentAnchoredPosition.x) ? -1 : 1;
                    this.m_contentAnchoredPosition.x += (Time.deltaTime * this.m_contentFixingSpeed) * num3;
                    if (((num3 > 0) && (this.m_contentAnchoredPosition.x >= this.m_targetContentAnchoredPosition.x)) || ((num3 < 0) && (this.m_contentAnchoredPosition.x <= this.m_targetContentAnchoredPosition.x)))
                    {
                        this.m_contentAnchoredPosition = this.m_targetContentAnchoredPosition;
                    }
                }
                goto Label_055A;

            case enExpandListSelectingState.Expand:
                if (this.m_timeSlice >= this.m_expandedTime)
                {
                    this.m_selectingState = enExpandListSelectingState.None;
                }
                else
                {
                    this.m_timeSlice  += Time.deltaTime;
                    base.m_contentSize = Vector2.zero;
                    Vector2 offset = Vector2.zero;
                    if (base.m_listType != enUIListType.Horizontal)
                    {
                        if (base.m_listType == enUIListType.Vertical)
                        {
                            offset.y += base.m_elementLayoutOffset;
                        }
                    }
                    else
                    {
                        offset.x += base.m_elementLayoutOffset;
                    }
                    for (int j = 0; j < base.m_elementAmount; j++)
                    {
                        float num6 = 0f;
                        if (j == base.m_selectedElementIndex)
                        {
                            num6 = this.m_timeSlice / this.m_expandedTime;
                            num6 = Mathf.Clamp(num6, 0f, 1f);
                        }
                        stRect item = this.LayoutExpandElement(j, num6, ref this.m_contentSize, ref offset);
                        if (j < base.m_elementsRect.Count)
                        {
                            base.m_elementsRect[j] = item;
                        }
                        else
                        {
                            base.m_elementsRect.Add(item);
                        }
                    }
                    this.ResizeContent(ref this.m_contentSize, false);
                }
                goto Label_055A;

            default:
                goto Label_055A;
            }
            for (int i = 0; i < base.m_elementAmount; i++)
            {
                float num2 = 0f;
                if (i == base.m_lastSelectedElementIndex)
                {
                    num2 = 1f - (this.m_timeSlice / this.m_expandedTime);
                    num2 = Mathf.Clamp(num2, 0f, 1f);
                }
                stRect rect = this.LayoutExpandElement(i, num2, ref this.m_contentSize, ref zero);
                if (i < base.m_elementsRect.Count)
                {
                    base.m_elementsRect[i] = rect;
                }
                else
                {
                    base.m_elementsRect.Add(rect);
                }
            }
            this.ResizeContent(ref this.m_contentSize, false);
            if ((base.m_selectedElementIndex < 0) || (base.m_selectedElementIndex >= base.m_elementAmount))
            {
                if (base.m_listType == enUIListType.Horizontal)
                {
                    if (this.m_contentAnchoredPosition.x > 0f)
                    {
                        this.m_contentAnchoredPosition.x = 0f;
                    }
                    else if ((this.m_contentAnchoredPosition.x + this.m_contentSize.x) < this.m_scrollAreaSize.x)
                    {
                        this.m_contentAnchoredPosition.x = this.m_scrollAreaSize.x - this.m_contentSize.x;
                    }
                }
                else if (base.m_listType == enUIListType.Vertical)
                {
                    if (this.m_contentAnchoredPosition.y < 0f)
                    {
                        this.m_contentAnchoredPosition.y = 0f;
                    }
                    else if ((this.m_contentAnchoredPosition.y - this.m_contentSize.y) > -this.m_scrollAreaSize.y)
                    {
                        this.m_contentAnchoredPosition.y = -this.m_scrollAreaSize.y + this.m_contentSize.y;
                    }
                }
            }
Label_055A:
            num7 = 0;
            while (num7 < base.m_elementAmount)
            {
                stRect rect3 = base.m_elementsRect[num7];
                CUIListElementScript elemenet = base.GetElemenet(num7);
                if (elemenet != null)
                {
                    elemenet.SetRect(ref rect3);
                }
                num7++;
            }
            base.m_contentRectTransform.anchoredPosition = this.m_contentAnchoredPosition;
        }