private ScrollItem GetItem(string name, List <ScrollItem> items) { bool spawn = true; ScrollItem scrollItem = null; foreach (var item in items) { if (!item.IsActive) { spawn = false; scrollItem = item; break; } } if (spawn) { var template = templateDict[name]; var go = Object.Instantiate(template, Vector3.zero, Quaternion.identity); scrollItem = go.AddComponent <ScrollItem>(); items.Add(scrollItem); } return(scrollItem); }
public void Recycle(int hashCode, ScrollItem item) { var pool = GetPoll(hashCode); if (pool == null) { Debug.LogError("没有当前池: " + hashCode); return; } pool.Recycle(item); }
/// <summary> /// Item填充数据 /// </summary> /// <param name="item"></param> /// <param name="index"></param> private void FillItemData(ScrollItem item, int index) { if (Target.Loop) { int itemCount = SourceDatas.Count; if (index >= 0) { index %= itemCount; } else { index = itemCount + ((index + 1) % itemCount) - 1; } } if (index < 0 || index >= SourceDatas.Count) { return; } var data = SourceDatas[index]; item.name = index.ToString(); bool isNewCreated = false; if (!binders.TryGetValue(item, out var binder)) { isNewCreated = true; binder = binderCreator(); binder.Controller = this; binder.Target = item; binder.Initialize(); binders.Add(item, binder); } if (!isNewCreated) { if (!binder.resetFlag) { binder.Reset(); } } binder.Index = index; binder.Data = data; binder.Bind(data, index); binder.resetFlag = false; }
private void OnSnapNearestChanged(ScrollItem item) { UpdateAllDots(); }
public void Recycle(ScrollItem item) { item.gameObject.SetActive(false); }