コード例 #1
0
    /// <summary>
    /// Gets the cell to be displayed. You can have numerous cell types, allowing variety in your list.
    /// Some examples of this would be headers, footers, and other grouping cells.
    /// </summary>
    /// <param name="scroller">The scroller requesting the cell</param>
    /// <param name="dataIndex">The index of the data that the scroller is requesting</param>
    /// <param name="cellIndex">The index of the list. This will likely be different from the dataIndex if the scroller is looping</param>
    /// <returns>The cell for the scroller to use</returns>
    public EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex)
    {
        // first, we get a cell from the scroller by passing a prefab.
        // if the scroller finds one it can recycle it will do so, otherwise
        // it will create a new cell.
        NoteUiItem cellView = scroller.GetCellView(_cellViewPrefab) as NoteUiItem;

        // set the name of the game object to the cell's data index.
        // this is optional, but it helps up debug the objects in
        // the scene hierarchy.
        cellView.name = "Cell " + dataIndex.ToString();

        // update data and view
        cellView.SetData(_data[dataIndex]);

        // set state
        if (_state == State.Default)
        {
            cellView.SetState(NoteUiItem.State.Normal);
        }
        else if (_state == State.Selection)
        {
            cellView.SetState(NoteUiItem.State.Selection);
        }

        // return the cell to the scroller
        return(cellView);
    }
コード例 #2
0
 private void ItemLongClickHandler(NoteUiItem item)
 {
     if (_state == State.Default)
     {
         SetState(State.Selection);
     }
 }
コード例 #3
0
 private void ItemClickHandler(NoteUiItem item)
 {
     if (_state == State.Default)
     {
         _selectedNoteData = item.data;
         SetState(State.Edit);
     }
 }
コード例 #4
0
    private void CellViewInstantiated(EnhancedScroller enhancedScroller, EnhancedScrollerCellView cellview)
    {
        NoteUiItem item = cellview as NoteUiItem;

        item.OnClick     += ItemClickHandler;
        item.OnLongClick += ItemLongClickHandler;
        item.OnSelect    += ItemSelectHandler;
    }
コード例 #5
0
    private void ItemSelectHandler(NoteUiItem item, bool selected)
    {
        if (selected)
        {
            _selectedNotesData.Add(item.data);
        }
        else
        {
            _selectedNotesData.Remove(item.data);

            // if last element been deselected, change state to default
            if (_selectedNotesData.Count == 0)
            {
                SetState(State.Default);
            }
        }
    }