From 7ed5caade6dd1791a876998050b8a6f587ea892d Mon Sep 17 00:00:00 2001 From: Bian-Sh Date: Fri, 24 Apr 2020 15:47:08 +0800 Subject: [PATCH] Update BaseController.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 当 Cell 模板没有继承 basecell 的时候会无法赋值,此处应该有报错提醒,增之。 2. 当数据量够小时,生成 cell 的index会溢出导致各种问题,改之。 --- Assets/ReuseScroller/Scripts/BaseController.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Assets/ReuseScroller/Scripts/BaseController.cs b/Assets/ReuseScroller/Scripts/BaseController.cs index a4841a6..5e5e595 100755 --- a/Assets/ReuseScroller/Scripts/BaseController.cs +++ b/Assets/ReuseScroller/Scripts/BaseController.cs @@ -72,6 +72,7 @@ protected override void OnValidate() { base.OnValidate(); if (cellObject && !cellObject.GetComponent>()) { cellObject = null; + Debug.LogWarning("指定的 cellTemplate 不包含BaseCell 的实现类!"); } } @@ -180,10 +181,14 @@ private void UpdateCells() { } private void FillCells() { - if (cells.Count == 0) CreateCell(0); - - while (CellsTailEdge + spacing <= ActiveTailEdge) { - CreateCell(cells.Last.Value.dataIndex + 1); + if (cellData.Count > 0) + { + if (cells.Count == 0) CreateCell(0); + while (CellsTailEdge + spacing <= ActiveTailEdge) + { + if (cells.Last.Value.dataIndex == cellData.Count - 1) break; //数据量够了 + CreateCell(cells.Last.Value.dataIndex + 1); + } } }