Ejemplo n.º 1
0
    void FindFlockmates()
    {
        int   r = sets.radius;
        float x = Xf + facing.x * 8;
        float y = Yf + facing.y * 8;

        //adding 2 here so the radius is from the bounding box's edges
        flock = ugrid.Query(x - r, y - r, x + 2 + r, y + 2 + r, ID); //TODO: variable sizes (not 2)
    }
    private void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireCube(
            sets.bounds.center.ToV3(),
            new Vector3(sets.bounds.width, 0, sets.bounds.height));
        Gizmos.DrawLine(
            new Vector3(0, 1, sets.bounds.height / 2),
            new Vector3(sets.bounds.width, 1, sets.bounds.height / 2));
        Gizmos.DrawLine(
            new Vector3(sets.bounds.width / 2, 1, 0),
            new Vector3(sets.bounds.width / 2, 1, sets.bounds.height));

        Gizmos.color = Color.green;
        Gizmos.DrawWireCube(
            queryTest.center.ToV3(),
            queryTest.size.ToV3());

        //TODO: this is stupid
        if (Application.isPlaying)
        {
            List <MonoBehaviour> ugh      = new List <MonoBehaviour>(4);
            List <BoidBase>      results  = new List <BoidBase>(1);
            List <UGridBoid>     results2 = new List <UGridBoid>(1);
            List <IGridElt>      results3 = new List <IGridElt>(1);

            switch (type)
            {
            case QtTestType.Quadtree:
                results = qt.Query(queryTest.xMin, queryTest.yMax, queryTest.xMax, queryTest.yMin);
                break;

            case QtTestType.LooseQuadtree:
                results = qt.Query(queryTest.xMin, queryTest.yMax, queryTest.xMax, queryTest.yMin);
                break;

            case QtTestType.UGrid:
                results2 = uGrid.Query(queryTest.xMin, queryTest.yMin, queryTest.xMax, queryTest.yMax);
                break;

            case QtTestType.LooseDGrid:
                results3 = ldGrid.Query(queryTest.xMin, queryTest.yMin, queryTest.xMax, queryTest.yMax);
                break;

            default:
                break;
            }
            for (int i = 0; i < results.Count; i++)
            {
                ugh.Add((MonoBehaviour)results[i]);
            }
            for (int i = 0; i < results2.Count; i++)
            {
                ugh.Add((MonoBehaviour)results2[i]);
            }
            for (int i = 0; i < results3.Count; i++)
            {
                ugh.Add((MonoBehaviour)results3[i]);
            }

            Gizmos.color = Color.green;
            for (int i = 0; i < ugh.Count; i++)
            {
                Gizmos.DrawCube(ugh[i].transform.position, new Vector3(3, 3, 3));
            }
        }

        if (Application.isPlaying && drawTree)
        {
            if (type == QtTestType.Quadtree || type == QtTestType.LooseQuadtree)
            {
                qt.Traverse(QtGizmo.Draw);
            }
            else if (type == QtTestType.UGrid)
            {
                uGrid.Traverse(UGridGizmo.Draw);
            }
            else if (type == QtTestType.LooseDGrid)
            {
                ldGrid.Traverse(LooseGridGizmo.Draw);
            }
        }
    }