Ejemplo n.º 1
0
    private void Start()
    {
        allBoids         = new List <Boid>();
        inMyArea         = new List <Boid>();
        testAreaBoundary = new Rectangle(Random.Range(minX + 4, maxX - 4), Random.Range(minZ + 4, maxZ - 4), 5, 5);

        for (int i = 0; i < numberOfBoidsToSpawn; i++)
        {
            Vector3 spawnPos = new Vector3(Random.Range(minX, maxX), 0, Random.Range(minZ, maxZ));
            Boid    boid     = Instantiate(boidPrefab, spawnPos, Quaternion.identity).GetComponent <Boid>();
            allBoids.Add(boid);
        }
        theTree = new QuadTree();
        theTree.InitilizeTree(0, 0, maxX, maxZ, maxInOneQuad);

        theTree.debugEvent += DebugLinesQuads;
        for (int i = 0; i < allBoids.Count; i++)
        {
            theTree.AddObjectToTree(allBoids[i].transform.position.x, allBoids[i].transform.position.z, allBoids[i]);
        }

        theTree.DebugTree();

        ConvertObjsFromTree();
        for (int i = 0; i < inMyArea.Count; i++)
        {
            Debug.Log(inMyArea[i]);
        }
        drawGiz = true;
    }
Ejemplo n.º 2
0
    private void BuildQuadTree()
    {
        theTree.ClearTree();

        for (int i = 0; i < allBoids.Count; i++)
        {
            theTree.AddObjectToTree(allBoids[i].transform.position.x, allBoids[i].transform.position.z, allBoids[i]);
        }

        theTree.DebugTree();
    }