示例#1
0
文件: CityGen.cs 项目: nothke/Muprox
    void DoStreets(Street[,] streets)
    {
        float dist = (tileSize - streetWidth) / 2;

        foreach (var street in streets)
        {
            street.exists = Random.value > 0.2f;

            Plot leftPlot  = street.isNS ? street.E as Plot : street.S as Plot;
            Plot rightPlot = street.isNS ? street.W as Plot : street.N as Plot;

            bool surrounded = false;

            if ((leftPlot && leftPlot.type != Plot.Type.Water) ||
                (rightPlot && rightPlot.type != Plot.Type.Water))
            {
                surrounded = true;
            }

            if (!surrounded)
            {
                street.exists = false;
                continue;
            }

            Mesh mesh = null;

            Material mat;

            if (!street.exists)
            {
                float width  = street.isNS ? streetWidth : tileSize - streetWidth;
                float height = street.isNS ? tileSize - streetWidth : streetWidth;

                mesh = MeshX.Quad(Vector3.zero, width, height, Vector3.up);
                mat  = plotMat;
            }
            else
            {
                Vector3   direction = street.isNS ? Vector3.forward : Vector3.right;
                Vector3[] points    = new Vector3[] { direction * -dist, direction *dist };


                Shape leftShape  = GetShape(leftPlot);
                Shape rightShape = GetShape(rightPlot);

                Mesh streetMeshR = MeshX.Sweep(leftShape.GetPoints2D(), points);
                Mesh streetMeshL = MeshX.Sweep(rightShape.GetPoints2DMirrored(), points);

                mesh = MeshX.Combine(new Mesh[] { streetMeshL, streetMeshR });
                mat  = streetMat;
            }

            GameObject streetGO = gameObject.InitializeSeparateMesh(mesh, mat);
            streetGO.AddComponent <MeshCollider>();

            streetGO.transform.position = street.Position() * tileSize;
        }
    }
示例#2
0
文件: CityGen.cs 项目: nothke/Muprox
    void Generate()
    {
        // create meshes
        foreach (var plot in city.plots)
        {
            if (Random.value < 0.3f)
            {
                plot.type = Plot.Type.Water;
            }

            if (plot.type == Plot.Type.Water)
            {
                continue;
            }

            Mesh       quad   = MeshX.Quad(Vector3.zero, tileSize - streetWidth, tileSize - streetWidth, Vector3.up);
            GameObject plotGO = gameObject.InitializeSeparateMesh(quad, plotMat);
            plotGO.AddComponent <MeshCollider>();

            plotGO.transform.localPosition = plot.Position() * tileSize;

            PlaceBuildings(plot);
        }

        DoStreets(city.horizontalStreets);
        DoStreets(city.verticalStreets);

        foreach (var corner in city.corners)
        {
            if (!corner.HasNeighbourStreets())
            {
                continue;
            }

            Mesh       quad     = MeshX.Quad(Vector3.zero, streetWidth, streetWidth, Vector3.up);
            GameObject cornerGO = gameObject.InitializeSeparateMesh(quad, cornerMat);

            cornerGO.transform.localPosition = corner.Position() * tileSize;
            cornerGO.AddComponent <MeshCollider>();
        }

        float dist = (tileSize - streetWidth) / 2;
    }