Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit b42cfb7

Browse files
完善无限列表的接口
1 parent 584aac4 commit b42cfb7

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

‎GameFramework/Runtime/UI/InfiniteListView.cs‎

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,25 @@ public void Setup(int renderMax, Action cacheInstantiateComplete, Action<List<In
9797
StartCoroutine(InstantiateRenderCache(renderMax, cacheInstantiateComplete));
9898
}
9999

100+
/// <summary>
101+
///
102+
/// </summary>
103+
/// <param name="num"></param>
104+
/// <param name="extLength">正为绝对值,负为比例</param>
105+
/// <returns></returns>
100106
public InfiniteListView AddItem(int num = 1, float extLength = 0.0f)
101107
{
102108
if (num == 0)
103109
return this;
104110

111+
if (extLength < 0)
112+
{
113+
extLength = Mathf.Abs(extLength) * _itemSize.x;
114+
}
115+
105116
if (num > 0)
106117
{
107118

108-
109119
int idIndex = _items.Count;
110120
for (int i = 0; i < num; i++)
111121
{
@@ -199,8 +209,28 @@ public InfiniteListView AddItem(int num = 1, float extLength = 0.0f)
199209
return this;
200210
}
201211

212+
public void ClearItem()
213+
{
214+
AddItem(-_items.Count);
215+
}
216+
217+
public void SortItem()
218+
{
219+
for (int i = 0; i < _items.Count; i++)
220+
{
221+
var item = _items[i];
222+
item.Id = i;
223+
_items[i] = item;
224+
}
225+
}
226+
202227
private void RebuildItemRenderer(float dragFloat=0.0f)
203228
{
229+
foreach (var item in _renderItems)
230+
{
231+
item.gameObject.SetActive(false);
232+
}
233+
204234
if (_items == null || _items.Count == 0)
205235
return;
206236

@@ -234,10 +264,7 @@ private void RebuildItemRenderer(float dragFloat=0.0f)
234264
}
235265
}
236266

237-
foreach (var item in _renderItems)
238-
{
239-
item.gameObject.SetActive(false);
240-
}
267+
241268

242269
int renderIndex = -1;
243270

@@ -251,7 +278,7 @@ private void RebuildItemRenderer(float dragFloat=0.0f)
251278
{
252279
var item = _items[i];
253280
Vector2 renderPostion = _dragPosition + item.Position;
254-
Debug.Log($"id:{item.Id} _dragPosition: {_dragPosition} item.Position: {item.Position} renderPostion£o {renderPostion}");
281+
//Debug.Log($"id:{item.Id} _dragPosition: {_dragPosition} item.Position: {item.Position} renderPostion�� {renderPostion}");
255282
if (OutRenderBounds(renderPostion))
256283
{
257284
item.RenderItem = null;
@@ -395,6 +422,11 @@ public void Rebuild(CanvasUpdate executing)
395422
//RebuildItemRenderer();
396423
}
397424

425+
public void Rebuild()
426+
{
427+
RebuildItemRenderer();
428+
}
429+
398430
#endregion
399431

400432
private void ClampDragPosition(float floatDrag = 0.0f)
@@ -408,7 +440,7 @@ private void ClampDragPosition(float floatDrag = 0.0f)
408440
{
409441
_dragPosition = Vector2.zero;
410442
}
411-
Debug.Log($"_dragPosition: {_dragPosition} {_dragMin} {_dragMax}");
443+
//Debug.Log($"_dragPosition: {_dragPosition} {_dragMin} {_dragMax}");
412444
}
413445

414446
private bool OutRenderBounds(Vector2 renderPosition)
@@ -421,7 +453,6 @@ private bool OutRenderBounds(Vector2 renderPosition)
421453

422454
return false;
423455
}
424-
425456
}
426457

427458

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /