Ejemplo n.º 1
0
        protected override void Awake()
        {
            base.Awake();

            if (m_virtualContent == null)
            {
                return;
            }

            m_virtualContentTransformChangeListener = m_virtualContent.GetComponent <RectTransformChangeListener>();
            m_virtualContentTransformChangeListener.RectTransformChanged += OnVirtualContentTransformChaged;

            UpdateVirtualContentPosition();

            if (m_useGrid)
            {
                LayoutGroup layoutGroup = m_virtualContent.GetComponent <LayoutGroup>();
                if (layoutGroup != null && !(layoutGroup is GridLayoutGroup))
                {
                    DestroyImmediate(layoutGroup);
                }

                GridLayoutGroup gridLayout = m_virtualContent.GetComponent <GridLayoutGroup>();
                if (gridLayout == null)
                {
                    gridLayout = m_virtualContent.gameObject.AddComponent <GridLayoutGroup>();
                }

                gridLayout.cellSize       = ContainerPrefab.rect.size;
                gridLayout.childAlignment = TextAnchor.UpperLeft;
                gridLayout.startCorner    = GridLayoutGroup.Corner.UpperLeft;
                gridLayout.spacing        = m_gridSpacing;
                if (m_mode == VirtualizingMode.Vertical)
                {
                    gridLayout.startAxis  = GridLayoutGroup.Axis.Horizontal;
                    gridLayout.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
                }
                else
                {
                    gridLayout.startAxis  = GridLayoutGroup.Axis.Vertical;
                    gridLayout.constraint = GridLayoutGroup.Constraint.FixedRowCount;
                }
                m_gridLayoutGroup = gridLayout;
            }
            else
            {
                if (m_mode == VirtualizingMode.Horizontal)
                {
                    //In horizontal mode we destroy VerticalLayoutGroup or GridLayoutGroup if exists

                    LayoutGroup layoutGroup = m_virtualContent.GetComponent <LayoutGroup>();
                    if (layoutGroup != null && !(layoutGroup is HorizontalLayoutGroup))
                    {
                        DestroyImmediate(layoutGroup);
                    }

                    // Create HorizontalLayoutGroup if does not exists

                    HorizontalLayoutGroup horizontalLayout = m_virtualContent.GetComponent <HorizontalLayoutGroup>();
                    if (horizontalLayout == null)
                    {
                        horizontalLayout = m_virtualContent.gameObject.AddComponent <HorizontalLayoutGroup>();
                    }

                    // Setup HorizontalLayoutGroup behavior to arrange ui containers correctly

                    horizontalLayout.childControlHeight    = true;
                    horizontalLayout.childControlWidth     = false;
                    horizontalLayout.childForceExpandWidth = false;

                    m_layoutGroup = horizontalLayout;
                }
                else
                {
                    //In horizontal mode we destroy HorizontalLayoutGroup or GridLayoutGroup if exists

                    LayoutGroup layoutGroup = m_virtualContent.GetComponent <LayoutGroup>();
                    if (layoutGroup != null && !(layoutGroup is VerticalLayoutGroup))
                    {
                        DestroyImmediate(layoutGroup);
                    }

                    // Create VerticalLayoutGroup if does not exists

                    VerticalLayoutGroup verticalLayout = m_virtualContent.GetComponent <VerticalLayoutGroup>();
                    if (verticalLayout == null)
                    {
                        verticalLayout = m_virtualContent.gameObject.AddComponent <VerticalLayoutGroup>();
                    }

                    // Setup VerticalLayoutGroup behavior to arrange ui containers correctly

                    verticalLayout.childControlWidth      = true;
                    verticalLayout.childControlHeight     = false;
                    verticalLayout.childForceExpandHeight = false;

                    m_layoutGroup = verticalLayout;
                }
            }

            // Set ScrollSensitivity to be exactly the same as ContainerSize

            scrollSensitivity = ContainerSize;// * ContainersPerGroup;
        }
        protected override void Awake()
        {
            base.Awake();

            if (m_virtualContent == null)
            {
                return;
            }

            m_virtualContentTransformChangeListener = m_virtualContent.GetComponent <RectTransformChangeListener>();
            m_virtualContentTransformChangeListener.RectTransformChanged += OnVirtualContentTransformChaged;

            UpdateVirtualContentPosition();

            if (m_mode == VirtualizingMode.Horizontal)
            {
                //In horizontal mode we destroy VerticalLayoutGroup if exists

                VerticalLayoutGroup verticalLayout = m_virtualContent.GetComponent <VerticalLayoutGroup>();
                if (verticalLayout != null)
                {
                    DestroyImmediate(verticalLayout);
                }

                // Create HorizontalLayoutGroup if does not exists

                HorizontalLayoutGroup horizontalLayout = m_virtualContent.GetComponent <HorizontalLayoutGroup>();
                if (horizontalLayout == null)
                {
                    horizontalLayout = m_virtualContent.gameObject.AddComponent <HorizontalLayoutGroup>();
                }

                // Setup HorizontalLayoutGroup behavior to arrange ui containers correctly

                horizontalLayout.childControlHeight    = true;
                horizontalLayout.childControlWidth     = false;
                horizontalLayout.childForceExpandWidth = false;
            }
            else
            {
                //In horizontal mode we destroy HorizontalLayoutGroup if exists

                HorizontalLayoutGroup horizontalLayout = m_virtualContent.GetComponent <HorizontalLayoutGroup>();
                if (horizontalLayout != null)
                {
                    DestroyImmediate(horizontalLayout);
                }

                // Create VerticalLayoutGroup if does not exists

                VerticalLayoutGroup verticalLayout = m_virtualContent.GetComponent <VerticalLayoutGroup>();
                if (verticalLayout == null)
                {
                    verticalLayout = m_virtualContent.gameObject.AddComponent <VerticalLayoutGroup>();
                }

                // Setup VerticalLayoutGroup behavior to arrange ui containers correctly

                verticalLayout.childControlWidth      = true;
                verticalLayout.childControlHeight     = false;
                verticalLayout.childForceExpandHeight = false;
            }

            // Set ScrollSensitivity to be exactly the same as ContainerSize

            scrollSensitivity = ContainerSize;
        }
Ejemplo n.º 3
0
 protected virtual void Awake()
 {
     ((UIBehaviour)this).Awake();
     if (Object.op_Equality((Object)this.m_virtualContent, (Object)null))
     {
         return;
     }
     this.m_virtualContentTransformChangeListener = (RectTransformChangeListener)((Component)this.m_virtualContent).GetComponent <RectTransformChangeListener>();
     this.m_virtualContentTransformChangeListener.RectTransformChanged += new RectTransformChanged(this.OnVirtualContentTransformChaged);
     this.UpdateVirtualContentPosition();
     if (this.m_useGrid)
     {
         LayoutGroup component = (LayoutGroup)((Component)this.m_virtualContent).GetComponent <LayoutGroup>();
         if (Object.op_Inequality((Object)component, (Object)null) && !(component is GridLayoutGroup))
         {
             Object.DestroyImmediate((Object)component);
         }
         GridLayoutGroup gridLayoutGroup1 = (GridLayoutGroup)((Component)this.m_virtualContent).GetComponent <GridLayoutGroup>();
         if (Object.op_Equality((Object)gridLayoutGroup1, (Object)null))
         {
             gridLayoutGroup1 = (GridLayoutGroup)((Component)this.m_virtualContent).get_gameObject().AddComponent <GridLayoutGroup>();
         }
         GridLayoutGroup gridLayoutGroup2 = gridLayoutGroup1;
         Rect            rect             = this.ContainerPrefab.get_rect();
         Vector2         size             = ((Rect) ref rect).get_size();
         gridLayoutGroup2.set_cellSize(size);
         ((LayoutGroup)gridLayoutGroup1).set_childAlignment((TextAnchor)0);
         gridLayoutGroup1.set_startCorner((GridLayoutGroup.Corner) 0);
         gridLayoutGroup1.set_spacing(this.m_gridSpacing);
         if (this.m_mode == VirtualizingMode.Vertical)
         {
             gridLayoutGroup1.set_startAxis((GridLayoutGroup.Axis) 0);
             gridLayoutGroup1.set_constraint((GridLayoutGroup.Constraint) 1);
         }
         else
         {
             gridLayoutGroup1.set_startAxis((GridLayoutGroup.Axis) 1);
             gridLayoutGroup1.set_constraint((GridLayoutGroup.Constraint) 2);
         }
         this.m_gridLayoutGroup = gridLayoutGroup1;
     }
     else if (this.m_mode == VirtualizingMode.Horizontal)
     {
         LayoutGroup component = (LayoutGroup)((Component)this.m_virtualContent).GetComponent <LayoutGroup>();
         if (Object.op_Inequality((Object)component, (Object)null) && !(component is HorizontalLayoutGroup))
         {
             Object.DestroyImmediate((Object)component);
         }
         HorizontalLayoutGroup horizontalLayoutGroup = (HorizontalLayoutGroup)((Component)this.m_virtualContent).GetComponent <HorizontalLayoutGroup>();
         if (Object.op_Equality((Object)horizontalLayoutGroup, (Object)null))
         {
             horizontalLayoutGroup = (HorizontalLayoutGroup)((Component)this.m_virtualContent).get_gameObject().AddComponent <HorizontalLayoutGroup>();
         }
         ((HorizontalOrVerticalLayoutGroup)horizontalLayoutGroup).set_childControlHeight(true);
         ((HorizontalOrVerticalLayoutGroup)horizontalLayoutGroup).set_childControlWidth(false);
         ((HorizontalOrVerticalLayoutGroup)horizontalLayoutGroup).set_childForceExpandWidth(false);
         this.m_layoutGroup = (HorizontalOrVerticalLayoutGroup)horizontalLayoutGroup;
     }
     else
     {
         LayoutGroup component = (LayoutGroup)((Component)this.m_virtualContent).GetComponent <LayoutGroup>();
         if (Object.op_Inequality((Object)component, (Object)null) && !(component is VerticalLayoutGroup))
         {
             Object.DestroyImmediate((Object)component);
         }
         VerticalLayoutGroup verticalLayoutGroup = (VerticalLayoutGroup)((Component)this.m_virtualContent).GetComponent <VerticalLayoutGroup>();
         if (Object.op_Equality((Object)verticalLayoutGroup, (Object)null))
         {
             verticalLayoutGroup = (VerticalLayoutGroup)((Component)this.m_virtualContent).get_gameObject().AddComponent <VerticalLayoutGroup>();
         }
         ((HorizontalOrVerticalLayoutGroup)verticalLayoutGroup).set_childControlWidth(true);
         ((HorizontalOrVerticalLayoutGroup)verticalLayoutGroup).set_childControlHeight(false);
         ((HorizontalOrVerticalLayoutGroup)verticalLayoutGroup).set_childForceExpandHeight(false);
         this.m_layoutGroup = (HorizontalOrVerticalLayoutGroup)verticalLayoutGroup;
     }
     this.set_scrollSensitivity(this.ContainerSize);
 }