示例#1
0
            public void RetrieveNonAlloc(List <QTCircleCollider> toFill, QTCircleCollider collider)
            {
                Rect bounds = collider.GetGlobalBounds();

                dynamicQT.RetrieveNonAlloc(toFill, bounds);
                staticQT.RetrieveNonAlloc(toFill, bounds);
            }
示例#2
0
        // ------------------------------------------------
        // This algo remove objects in O(n)
        // ------------------------------------------------
        void FilterListWithCircleCircleCollision(List <QTCircleCollider> list,
                                                 QTCircleCollider collider)
        {
            int removeIndex = -1;
            int removeCount = 0;

            for (int i = 0; i < list.Count; i++)
            {
                QTCircleCollider c = list[i];

                if (!Overlap(collider, c))
                {
                    removeCount++;

                    if (removeIndex == -1)
                    {
                        removeIndex = i;
                    }
                }
                else
                {
                    if (removeIndex != -1)
                    {
                        // swap with the first remove item
                        list[removeIndex] = c;
                        removeIndex++;
                    }
                }
            }

            if (removeIndex > -1)
            {
                list.RemoveRange(removeIndex, removeCount);
            }
        }
示例#3
0
        public List <QTCircleCollider> Retrieve(QTCircleCollider collider)
        {
            _buffer.Clear();

            QuadTrees qt = _quadTrees[collider.layer];

            qt.RetrieveNonAlloc(_buffer, collider);

            FilterListWithCircleCircleCollision(_buffer, collider);

            return(_buffer);
        }
示例#4
0
            public void Insert(QTCircleCollider collider)
            {
                QuadTree <QTCircleCollider> quadTree = collider.@static ? staticQT : dynamicQT;

                quadTree.Insert(collider, collider.GetGlobalBounds());
            }
示例#5
0
 bool Overlap(QTCircleCollider a, QTCircleCollider b)
 {
     return(Vector2.Distance(a.center, b.center) < a.radius + b.radius);
 }
示例#6
0
        public void Register(QTCircleCollider collider)
        {
            QuadTrees qt = _quadTrees[collider.layer];

            qt.Insert(collider);
        }