Esempio n. 1
0
 private void setPermanentUnUsed(float vertexOffset)
 {
     for (int division = 0; division <= divisionCount; division++)
     {
         if (grid.checkDivision(division))
         {
             for (int x = 0; x < width; x++)
             {
                 for (int y = 0; y < height; y++)
                 {
                     if (!grid.getCreated(division, x, y))
                     {
                         Vector3 cellOffset = new Vector3(x * cellSize, y * cellSize, 0);
                         Vector3 vertice;
                         VerticeForGridLevelGenerator tempVertice = null;
                         vertice = new Vector3(-vertexOffset, -vertexOffset, 0) + cellOffset + gridOffset;
                         test(division, tempVertice, vertice);
                         vertice = new Vector3(-vertexOffset, vertexOffset, 0) + cellOffset + gridOffset;
                         test(division, tempVertice, vertice);
                         vertice = new Vector3(vertexOffset, -vertexOffset, 0) + cellOffset + gridOffset;
                         test(division, tempVertice, vertice);
                         vertice = new Vector3(vertexOffset, vertexOffset, 0) + cellOffset + gridOffset;
                         test(division, tempVertice, vertice);
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 void test(int division, VerticeForGridLevelGenerator tempVertice, Vector3 vertice)
 {
     tempVertice = verticesofGrid[division].verticesofGrid.Find(f => f.vertice.x == vertice.x && f.vertice.y == vertice.y);
     if (tempVertice != null)
     {
         tempVertice.setPermanentUnUsed();
     }
 }
Esempio n. 3
0
    void MakeDiscreteProceduralGrid()
    {
        // Debug.Log(grid);
        // Debug.Log(grid.getTotalCreatedTiles());
        vertices  = new Vector3[grid.getTotalCreatedTiles() * 4];
        triangles = new int[grid.getTotalCreatedTiles() * 6];
        VerticeForGridLevelGenerator vertice, tempVertice;
        int   v = 0, t = 0;
        float vertexOffset = cellSize * 0.5f;

        for (int division = 0; division <= divisionCount; division++)
        {
            if (grid.checkDivision(division))
            {
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        if (grid.getCreated(division, x, y))
                        {
                            Vector3 cellOffset = new Vector3(x * cellSize, y * cellSize, 0);
                            // Debug.Log(v);
                            vertices[v]     = new Vector3(-vertexOffset, -vertexOffset, 0) + cellOffset + gridOffset;
                            vertices[v + 1] = new Vector3(-vertexOffset, vertexOffset, 0) + cellOffset + gridOffset;
                            vertices[v + 2] = new Vector3(vertexOffset, -vertexOffset, 0) + cellOffset + gridOffset;
                            vertices[v + 3] = new Vector3(vertexOffset, vertexOffset, 0) + cellOffset + gridOffset;

                            for (int i = 0; i < 4; i++)
                            {
                                // Debug.Log(verticesofGrid[division]);
                                tempVertice = verticesofGrid[division].verticesofGrid.Find(f => f.vertice.x == vertices[v + i].x && f.vertice.y == vertices[v + i].y);
                                if (tempVertice != null)
                                {
                                    if (tempVertice.usedCount < 2)
                                    {
                                        tempVertice.IncreaseUseCount();
                                    }
                                    else
                                    {
                                        tempVertice.setUsed();
                                    }
                                }
                                else
                                {
                                    vertice = new VerticeForGridLevelGenerator(vertices[v + i]);
                                    verticesofGrid[division].verticesofGrid.Add(vertice);
                                }
                            }

                            // linePoints.Add(vertices[v]);
                            // linePoints.Add(vertices[v + 1]);

                            triangles[t]     = v;
                            triangles[t + 1] = triangles[t + 4] = v + 1;
                            triangles[t + 2] = triangles[t + 3] = v + 2;
                            triangles[t + 5] = v + 3;

                            v += 4;
                            t += 6;
                        }
                        // else
                        // {
                        //     Vector3 cellOffset = new Vector3(x * cellSize, y * cellSize, 0);
                        //     Vector3 verticeTemp;
                        //     tempVertice = null;
                        //     verticeTemp = new Vector3(-vertexOffset, -vertexOffset, 0) + cellOffset + gridOffset;
                        //     test(tempVertice, verticeTemp);
                        //     verticeTemp = new Vector3(-vertexOffset, vertexOffset, 0) + cellOffset + gridOffset;
                        //     test(tempVertice, verticeTemp);
                        //     verticeTemp = new Vector3(vertexOffset, -vertexOffset, 0) + cellOffset + gridOffset;
                        //     test(tempVertice, verticeTemp);
                        //     verticeTemp = new Vector3(vertexOffset, vertexOffset, 0) + cellOffset + gridOffset;
                        //     test(tempVertice, verticeTemp);
                        // }
                    }
                }
                setPermanentUnUsed(vertexOffset);
            }
        }
    }