Beispiel #1
0
            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);
            }
Beispiel #2
0
        public void Recycle(int hashCode, ScrollItem item)
        {
            var pool = GetPoll(hashCode);

            if (pool == null)
            {
                Debug.LogError("没有当前池: " + hashCode);

                return;
            }

            pool.Recycle(item);
        }
Beispiel #3
0
        /// <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;
        }
Beispiel #4
0
 private void OnSnapNearestChanged(ScrollItem item)
 {
     UpdateAllDots();
 }
Beispiel #5
0
 public void Recycle(ScrollItem item)
 {
     item.gameObject.SetActive(false);
 }