Ejemplo n.º 1
0
        /// <summary>
        /// This function just takes the Demo data and displays it
        /// </summary>
        /// <param name="data"></param>
        public void SetData(ref SmallList <Data> data, int startingIndex, SelectedDelegate selected)
        {
            // loop through the sub cells to display their data (or disable them if they are outside the bounds of the data)
            for (var i = 0; i < rowCellViews.Length; i++)
            {
                var dataIndex = startingIndex + i;

                // if the sub cell is outside the bounds of the data, we pass null to the sub cell
                rowCellViews[i].SetData(dataIndex, dataIndex < data.Count ? data[dataIndex] : null, selected);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This function just takes the Demo data and displays it
        /// </summary>
        /// <param name="data"></param>
        public void SetData(int dataIndex, Data data, SelectedDelegate selected)
        {
            // set the selected delegate
            this.selected = selected;

            // this cell was outside the range of the data, so we disable the container.
            // Note: We could have disable the cell gameobject instead of a child container,
            // but that can cause problems if you are trying to get components (disabled objects are ignored).
            container.SetActive(data != null);

            if (data != null)
            {
                // set the text if the cell is inside the data range
                text.text = data.someText;
            }

            // if there was previous data assigned to this cell view,
            // we need to remove the handler for the selection change
            if (_data != null)
            {
                _data.selectedChanged -= SelectedChanged;
            }

            // link the data to the cell view
            DataIndex = dataIndex;
            _data     = data;

            if (data != null)
            {
                // set up a handler so that when the data changes
                // the cell view will update accordingly. We only
                // want a single handler for this cell view, so
                // first we remove any previous handlers before
                // adding the new one
                _data.selectedChanged -= SelectedChanged;
                _data.selectedChanged += SelectedChanged;

                // update the selection state UI
                SelectedChanged(data.Selected);
            }
        }