Example #1
0
        /// <summary>
        /// Start this instance.
        /// </summary>
        public override void Start()
        {
            if (isStartedListView)
            {
                return;
            }
            isStartedListView = true;

            base.Start();
            base.Items = new List <ListViewItem>();

            SelectedItemsCache = SelectedIndicies.Convert <int, string>(GetDataItem);

            DestroyGameObjects = false;

            if (DefaultItem == null)
            {
                throw new NullReferenceException("DefaultItem is null. Set component of type ImageAdvanced to DefaultItem.");
            }
            DefaultItem.gameObject.SetActive(true);
            if (DefaultItem.GetComponentInChildren <Text>() == null)
            {
                throw new MissingComponentException("DefaultItem don't have child with 'Text' component. Add child with 'Text' component to DefaultItem.");
            }

            if (CanOptimize())
            {
                ScrollRect = scrollRect;

                var scrollRectTransform = scrollRect.transform as RectTransform;
                scrollHeight = scrollRectTransform.rect.height;
                scrollWidth  = scrollRectTransform.rect.width;

                layout = Container.GetComponent <LayoutGroup>();
                if (layout is EasyLayout.EasyLayout)
                {
                    LayoutBridge = new EasyLayoutBridge(layout as EasyLayout.EasyLayout, DefaultItem.transform as RectTransform);
                    LayoutBridge.IsHorizontal = IsHorizontal();
                }
                else if (layout is HorizontalOrVerticalLayoutGroup)
                {
                    LayoutBridge = new StandardLayoutBridge(layout as HorizontalOrVerticalLayoutGroup, DefaultItem.transform as RectTransform);
                }

                CalculateItemSize();
                CalculateMaxVisibleItems();
            }

            DefaultItem.gameObject.SetActive(false);

            UpdateItems();

            OnSelect.AddListener(OnSelectCallback);
            OnDeselect.AddListener(OnDeselectCallback);
        }
Example #2
0
        /// <summary>
        /// Start this instance.
        /// </summary>
        public override void Start()
        {
            if (isStartedListView)
            {
                return;
            }
            isStartedListView = true;

            base.Start();

            DestroyGameObjects = false;

            if (DefaultItem == null)
            {
                throw new NullReferenceException("DefaultItem is null. Set component of type ImageAdvanced to DefaultItem.");
            }
            DefaultItem.gameObject.SetActive(true);
            if (DefaultItem.GetComponentInChildren <Text>() == null)
            {
                throw new MissingComponentException("DefaultItem don't have child with 'Text' component. Add child with 'Text' component to DefaultItem.");
            }

            var topFillerObj = new GameObject("top filler");

            topFillerObj.transform.SetParent(Container);
            topFiller = topFillerObj.AddComponent <RectTransform>();
            topFiller.SetAsFirstSibling();
            topFiller.localScale = Vector3.one;

            var bottomFillerObj = new GameObject("bottom filler");

            bottomFillerObj.transform.SetParent(Container);
            bottomFiller            = bottomFillerObj.AddComponent <RectTransform>();
            bottomFiller.localScale = Vector3.one;

            if (CanOptimize())
            {
                ScrollRect = scrollRect;

                scrollHeight    = scrollRect.GetComponent <RectTransform>().rect.height;
                itemHeight      = DefaultItem.GetComponent <RectTransform>().rect.height;
                maxVisibleItems = (int)Math.Ceiling(scrollHeight / itemHeight) + 1;
                layout          = Container.GetComponent <EasyLayout.EasyLayout>();

                var r = scrollRect.gameObject.AddComponent <ResizeListener>();
                r.OnResize.AddListener(Resize);
            }

            UpdateItems();

            DefaultItem.gameObject.SetActive(false);

            OnSelect.AddListener(OnSelectCallback);
            OnDeselect.AddListener(OnDeselectCallback);
        }
Example #3
0
        // Token: 0x0600475C RID: 18268 RVA: 0x00182604 File Offset: 0x00180A04
        private List <ListViewStringComponent> GetNewComponents()
        {
            this.componentsCache = (from x in this.componentsCache
                                    where x != null
                                    select x).ToList <ListViewStringComponent>();
            List <ListViewStringComponent> new_components = new List <ListViewStringComponent>();

            this.strings.ForEach(delegate(string x, int i)
            {
                if (i >= this.visibleItems)
                {
                    return;
                }
                if (this.components.Count > 0)
                {
                    new_components.Add(this.components[0]);
                    this.components.RemoveAt(0);
                }
                else if (this.componentsCache.Count > 0)
                {
                    this.componentsCache[0].gameObject.SetActive(true);
                    new_components.Add(this.componentsCache[0]);
                    this.componentsCache.RemoveAt(0);
                }
                else
                {
                    ImageAdvanced imageAdvanced = UnityEngine.Object.Instantiate <ImageAdvanced>(this.DefaultItem);
                    imageAdvanced.gameObject.SetActive(true);
                    ListViewStringComponent listViewStringComponent = imageAdvanced.GetComponent <ListViewStringComponent>();
                    if (listViewStringComponent == null)
                    {
                        listViewStringComponent            = imageAdvanced.gameObject.AddComponent <ListViewStringComponent>();
                        listViewStringComponent.Background = imageAdvanced;
                        listViewStringComponent.Text       = imageAdvanced.GetComponentInChildren <Text>();
                    }
                    Utilites.FixInstantiated(this.DefaultItem, imageAdvanced);
                    listViewStringComponent.gameObject.SetActive(true);
                    new_components.Add(listViewStringComponent);
                }
            });
            this.components.ForEach(delegate(ListViewStringComponent x)
            {
                x.gameObject.SetActive(false);
            });
            this.componentsCache.AddRange(this.components);
            this.components.Clear();
            return(new_components);
        }
Example #4
0
        /// <summary>
        /// Start this instance.
        /// </summary>
        public override void Start()
        {
            if (isStartedListView)
            {
                return;
            }
            isStartedListView = true;

            base.Start();
            base.Items = new List <ListViewItem>();

            SelectedItemsCache = SelectedIndicies.ConvertAll <string>(GetDataItem);

            DestroyGameObjects = false;

            if (DefaultItem == null)
            {
                throw new NullReferenceException("DefaultItem is null. Set component of type ImageAdvanced to DefaultItem.");
            }
            DefaultItem.gameObject.SetActive(true);
            if (DefaultItem.GetComponentInChildren <Text>() == null)
            {
                throw new MissingComponentException("DefaultItem don't have child with 'Text' component. Add child with 'Text' component to DefaultItem.");
            }

            var topFillerObj = new GameObject("top filler");

            topFillerObj.transform.SetParent(Container);
            topFiller = topFillerObj.AddComponent <RectTransform>();
            topFiller.SetAsFirstSibling();
            topFiller.localScale = Vector3.one;

            var bottomFillerObj = new GameObject("bottom filler");

            bottomFillerObj.transform.SetParent(Container);
            bottomFiller            = bottomFillerObj.AddComponent <RectTransform>();
            bottomFiller.localScale = Vector3.one;

            if (CanOptimize())
            {
                ScrollRect = scrollRect;

                var scrollRectTransform = scrollRect.transform as RectTransform;
                scrollHeight = scrollRectTransform.rect.height;
                scrollWidth  = scrollRectTransform.rect.width;

                var itemRectTransform = DefaultItem.transform as RectTransform;
                itemHeight = itemRectTransform.rect.height;
                itemWidth  = itemRectTransform.rect.width;

                layout = Container.GetComponent <EasyLayout.EasyLayout>();

                CalculateMaxVisibleItems();
            }

            DefaultItem.gameObject.SetActive(false);

            UpdateItems();

            OnSelect.AddListener(OnSelectCallback);
            OnDeselect.AddListener(OnDeselectCallback);
        }