Beispiel #1
0
    private const float GPPU = 1f; // Grid Points Per Unit.

    #endregion Fields

    #region Methods

    // Use this for initialization
    public void init(Rect bounds, int partitions)
    {
        // Make our new bounds smaller than the given bounds by one partition length because shortcuts.
        this.bounds = bounds;

        // Set up our partition list of entities.
        entityPartitions = new List<PhysicsEntity>[partitions, partitions];
        for (int x = 0; x < partitions; x++)
        {
            for (int y = 0; y < partitions; y++)
            {
                entityPartitions[x,y] = new List<PhysicsEntity>();
            }
        }

        // set up our array of gridpoints.
        gridPoints = new GridPoint[(int)(bounds.width * GPPU), (int)(bounds.height * GPPU)];
        // Set up our array of vertices that we will be passing in to the grid mesh.
        Vector3[] meshPoints = new Vector3[gridPoints.GetLength(0) * gridPoints.GetLength(1)];
        int index = 0;

        for (int y = 0; y < gridPoints.GetLength(1); y++)
        {
            for (int x = 0; x < gridPoints.GetLength(0); x++)
            {
                GridPoint point = new GridPoint();
                point.init(new Vector3((float)x / GPPU, 0, (float)y / GPPU));
                gridPoints[x,y] = point;
                meshPoints[index++] = point.position;
            }
        }

        meshFilter.mesh = makeGrid(meshPoints, gridPoints.GetLength(0), gridPoints.GetLength(1));
    }