Exemplo n.º 1
0
        private ElementBuffer GetUsableBuffer(int index)
        {
            int prefabIndex = this.Adapter.ElementIndex2PrefabIndex(index);
            List <ElementBuffer> buffers = this.bufferPool[prefabIndex];

            for (int i = 0; i < buffers.Count; i++)
            {
                if (!buffers[i].IsUsing)
                {
                    return(buffers[i]);
                }
            }

            GameObject go = GameObject.Instantiate <GameObject>(this.Adapter.GetElementPrefab(index));

            if (gameObject.activeInHierarchy == false)
            {
                go.SetActive(true);
            }
            go.transform.SetParent(content);
            go.transform.localScale = Vector3.one;
            go.SetActive(false);
            ElementBuffer buffer = new ElementBuffer(go);

            this.bufferPool[prefabIndex].Add(buffer);

            return(buffer);
        }
Exemplo n.º 2
0
 private void SetElement(float distance2Top, ElementPositionInfo elementPositionInfo)
 {
     if (distance2Top >= this.visualRange.x && distance2Top <= this.visualRange.y && !elementPositionInfo.Visible)
     {
         if (elementPositionInfo.Invisible)
         {
             ElementBuffer buffer = GetUsableBuffer(elementPositionInfo.ElementIndex);
             if (buffer != null)
             {
                 buffer.Use(elementPositionInfo);
                 buffer.SetSize(this.GetElementSize(elementPositionInfo.ElementIndex));
                 this.Adapter.FillElementData(buffer, elementPositionInfo.ElementIndex);
             }
         }
         else if (elementPositionInfo.VisibleAndNeedRefresh)
         {
             ElementBuffer buffer = elementPositionInfo.Buffer;
             if (buffer != null)
             {
                 buffer.Use(elementPositionInfo);
                 buffer.SetSize(this.GetElementSize(elementPositionInfo.ElementIndex));
                 this.Adapter.FillElementData(buffer, elementPositionInfo.ElementIndex);
             }
         }
     }
 }
Exemplo n.º 3
0
 private void PrepareRefreshAllBuffers()
 {
     for (int i = 0; i < this.bufferPool.Length; i++)
     {
         List <ElementBuffer> buffers = this.bufferPool[i];
         for (int j = 0; j < buffers.Count; j++)
         {
             ElementBuffer buffer = buffers[j];
             buffer.PositionInfo.State = ElementState.visibleAndNeedRefresh;
         }
     }
 }
Exemplo n.º 4
0
        private Vector2 GetElementSize(int index)
        {
            Vector2       size   = Vector2.zero;
            ElementBuffer buffer = null;

            if (this.elementPositionInfoMapper.ContainsKey(index))
            {
                buffer = this.elementPositionInfoMapper[index].Buffer;
            }
            if (buffer != null && buffer.Element.TryGetElementSize(out size))
            {
            }
            else
            {
                size = Adapter.GetElementSize(index);
            }
            return(size);
        }
Exemplo n.º 5
0
        public virtual ElementBuffer ElementBufferInIndex(int index)
        {
            ElementBuffer obj = null;

            for (int i = 0; i < bufferPool.Length; i++)
            {
                List <ElementBuffer> buffers = bufferPool[i];
                for (int j = 0; j < buffers.Count; j++)
                {
                    if (buffers[j].ElementIndex == index && buffers[j].IsUsing)
                    {
                        obj = buffers[j];
                        break;
                    }
                }
            }

            return(obj);
        }
Exemplo n.º 6
0
        private void RecycleBuffers()
        {
            float currentPos   = 0f;
            float distance2Top = 0f;

            if (this.Vertical)
            {
                currentPos = content.localPosition.y;
            }
            else if (this.Horizontal)
            {
                currentPos = content.localPosition.x;
            }

            for (int i = 0; i < this.bufferPool.Length; i++)
            {
                List <ElementBuffer> buffers = this.bufferPool[i];
                for (int j = 0; j < buffers.Count; j++)
                {
                    ElementBuffer buffer = buffers[j];

                    if (this.Vertical)
                    {
                        distance2Top = -buffer.PositionInfo.LocalPos.y - currentPos;
                    }
                    else if (this.Horizontal)
                    {
                        distance2Top = buffer.PositionInfo.LocalPos.x + currentPos;
                    }

                    if (buffer.IsUsing && (distance2Top < this.visualRange.x || distance2Top > this.visualRange.y))
                    {
                        buffer.Recycle();
                        buffer.PositionInfo.State = ElementState.invisible;
                    }
                }
            }
        }
Exemplo n.º 7
0
 public abstract void FillElementData(ElementBuffer elementBuffer, int elementIndex);
Exemplo n.º 8
0
 public void SetBuffer(ElementBuffer buffer)
 {
     this.buffer = buffer;
 }