Exemplo n.º 1
0
    /// <summary>
    /// 更新邻居
    /// </summary>
    /// <param name="radiusSquared"></param>
    /// <param name="searchQuad"></param>
    /// <param name="Target"></param>
    public static void UpdateNeighbour(float radiusSquared, Rect searchQuad, Seeker Target)
    {
        openQuadTreeList.Clear();
        openQuadTreeList.Add(quadTree);
        int foundCount = 0;

        while (openQuadTreeList.Count > 0 && foundCount < maxNeighbourCount)
        {
            QuadTree current = openQuadTreeList[0];
            if (current.bounds.Overlaps(searchQuad))
            {
                for (int i = 0; i < current.objects.Count; i++)
                {
                    if (foundCount == maxNeighbourCount)
                    {
                        break;
                    }
                    if (current.objects[i] != Target)
                    {
                        if ((current.objects[i].Pos - Target.Pos).sqrMagnitude < radiusSquared)
                        {
                            Target.AddNeighbours(foundCount, current.objects[i]);
                            foundCount++;
                        }
                    }
                }
                if (current.nodesInUse)
                {
                    openQuadTreeList.Add(current.nodes[0]);
                    openQuadTreeList.Add(current.nodes[1]);
                    openQuadTreeList.Add(current.nodes[2]);
                    openQuadTreeList.Add(current.nodes[3]);
                }
            }
            openQuadTreeList.Remove(current);
        }
    }