Ejemplo n.º 1
0
    public void Render(BuildingsRender buildingsRender)
    {
        var meshFilter = gameObject.AddComponent<MeshFilter>();
        var meshRenderer = gameObject.AddComponent<MeshRenderer>();

        Material material;
        if (buildingsRender.MaterialMap.TryGetValue(Building.Type, out material))
        {
            meshRenderer.material = material;
        }
        
        var verticies = new List<Vector3>();
        var triangles = new List<int>();

        foreach (var position in Building.Positions)
        {
            var tile = Map.TerrainData.GetTile(position.x, position.y);

            verticies.Add(tile.Corner1 + Offset);
            verticies.Add(tile.Corner2 + Offset);
            verticies.Add(tile.Corner3 + Offset);

            triangles.Add(triangles.Count);
            triangles.Add(triangles.Count);
            triangles.Add(triangles.Count);
        }
        var mesh = new Mesh();
        meshFilter.mesh = mesh;
        mesh.vertices = verticies.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.Optimize();
        mesh.RecalculateNormals();
    }
Ejemplo n.º 2
0
    public void Render(BuildingsRender buildingsRender)
    {
        var meshFilter   = gameObject.AddComponent <MeshFilter>();
        var meshRenderer = gameObject.AddComponent <MeshRenderer>();

        Material material;

        if (buildingsRender.MaterialMap.TryGetValue(Building.Type, out material))
        {
            meshRenderer.material = material;
        }

        var verticies = new List <Vector3>();
        var triangles = new List <int>();

        foreach (var position in Building.Positions)
        {
            var tile = Map.TerrainData.GetTile(position.x, position.y);

            verticies.Add(tile.Corner1 + Offset);
            verticies.Add(tile.Corner2 + Offset);
            verticies.Add(tile.Corner3 + Offset);

            triangles.Add(triangles.Count);
            triangles.Add(triangles.Count);
            triangles.Add(triangles.Count);
        }
        var mesh = new Mesh();

        meshFilter.mesh = mesh;
        mesh.vertices   = verticies.ToArray();
        mesh.triangles  = triangles.ToArray();
        mesh.Optimize();
        mesh.RecalculateNormals();
    }
Ejemplo n.º 3
0
    public void Render(BuildingsRender buildingsRender)
    {
        var floorCount = 1;
        foreach (var floor in Building.Floors)
        {
            var floorObj = new GameObject();
            floorObj.transform.parent = transform;
            floorObj.name = "Floor_" + floorCount++;

            var floorScript = floorObj.AddComponent<BuildingFloorRender>();
            floorScript.Floor = floor;
            floorScript.Render(buildingsRender);
        }
    }
Ejemplo n.º 4
0
    public void Render(BuildingsRender buildingsRender)
    {
        var floorCount = 1;

        foreach (var floor in Building.Floors)
        {
            var floorObj = new GameObject();
            floorObj.transform.parent = transform;
            floorObj.name             = "Floor_" + floorCount++;

            var floorScript = floorObj.AddComponent <BuildingFloorRender>();
            floorScript.Floor = floor;
            floorScript.Render(buildingsRender);
        }
    }
Ejemplo n.º 5
0
    private GameObject RenderWalls(BuildingsRender buildingsRender)
    {
        var wallObj = new GameObject();

        wallObj.name = "Walls";

        var meshFilter   = wallObj.AddComponent <MeshFilter>();
        var meshRenderer = wallObj.AddComponent <MeshRenderer>();
        var meshCollider = wallObj.AddComponent <MeshCollider>();

        Material material;

        if (buildingsRender.MaterialMap.TryGetValue("house", out material))
        {
            meshRenderer.material = material;
        }

        vertices  = new List <Vector3>();
        triangles = new List <int>();

        foreach (var edge in Floor.WallEdges)
        {
            var edgePair = edge.GetPoints(Floor.Map);
            var point1   = MatchHighest(edgePair.V1, 0.0f);
            var point2   = MatchHighest(edgePair.V2, 0.0f);

            RenderPointPair(point1, point2, Vector3.up * Floor.Height);
            RenderPointPair(point2, point1, Vector3.up * Floor.Height);
        }

        var mesh = new Mesh();

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.Optimize();
        mesh.RecalculateNormals();

        meshFilter.mesh         = mesh;
        meshCollider.sharedMesh = mesh;

        vertices  = null;
        triangles = null;

        return(wallObj);
    }
Ejemplo n.º 6
0
    public void Render(BuildingsRender buildingsRender)
    {
        GameObject prefab;
        if (!buildingsRender.PrefabMap.TryGetValue("pillar", out prefab))
        {
            Debug.Log("Cannot find pillar prefab");
            return;
        }

        var floorTilesObj = RenderFloorTiles(buildingsRender);
        floorTilesObj.transform.parent = transform;

        var wallObj = RenderWalls(buildingsRender);
        wallObj.transform.parent = transform;
        
        var transPos = MatchHighest(transform.localPosition, Floor.BaseHeight);
        gameObject.transform.localPosition = transPos;
    }
Ejemplo n.º 7
0
    private GameObject RenderFloorTiles(BuildingsRender buildingsRender)
    {
        var floorTilesObj = new GameObject();

        floorTilesObj.name = "Tiles";

        var meshFilter   = floorTilesObj.AddComponent <MeshFilter>();
        var meshRenderer = floorTilesObj.AddComponent <MeshRenderer>();
        var meshCollider = floorTilesObj.AddComponent <MeshCollider>();

        Material material;

        if (buildingsRender.MaterialMap.TryGetValue("house", out material))
        {
            meshRenderer.material = material;
        }

        vertices  = new List <Vector3>();
        triangles = new List <int>();

        foreach (var position in Floor.Positions)
        {
            var tile = Floor.Map.TerrainData.GetTile(position.x, position.y);

            RenderFloorTile(tile, Floor.FloorHeight, false);
            RenderFloorTile(tile, 0.0f, true);
        }

        var mesh = new Mesh();

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.Optimize();
        mesh.RecalculateNormals();

        meshFilter.mesh         = mesh;
        meshCollider.sharedMesh = mesh;

        vertices  = null;
        triangles = null;

        return(floorTilesObj);
    }
Ejemplo n.º 8
0
    private GameObject RenderFloorTiles(BuildingsRender buildingsRender)
    {
        var floorTilesObj = new GameObject();
        floorTilesObj.name = "Tiles";

        var meshFilter = floorTilesObj.AddComponent<MeshFilter>();
        var meshRenderer = floorTilesObj.AddComponent<MeshRenderer>();
        var meshCollider = floorTilesObj.AddComponent<MeshCollider>();
        
        Material material;
        if (buildingsRender.MaterialMap.TryGetValue("house", out material))
        {
            meshRenderer.material = material;
        }

        vertices = new List<Vector3>();
        triangles = new List<int>();
        
        foreach (var position in Floor.Positions)
        {
            var tile = Floor.Map.TerrainData.GetTile(position.x, position.y);

            RenderFloorTile(tile, Floor.FloorHeight, false);
            RenderFloorTile(tile, 0.0f, true);
        }

        var mesh = new Mesh();
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.Optimize();
        mesh.RecalculateNormals();
        
        meshFilter.mesh = mesh;
        meshCollider.sharedMesh = mesh;

        vertices = null;
        triangles = null;

        return floorTilesObj;
    }
Ejemplo n.º 9
0
    public void Render(BuildingsRender buildingsRender)
    {
        GameObject prefab;

        if (!buildingsRender.PrefabMap.TryGetValue("pillar", out prefab))
        {
            Debug.Log("Cannot find pillar prefab");
            return;
        }

        var floorTilesObj = RenderFloorTiles(buildingsRender);

        floorTilesObj.transform.parent = transform;

        var wallObj = RenderWalls(buildingsRender);

        wallObj.transform.parent = transform;

        var transPos = MatchHighest(transform.localPosition, Floor.BaseHeight);

        gameObject.transform.localPosition = transPos;
    }
Ejemplo n.º 10
0
    private GameObject RenderWalls(BuildingsRender buildingsRender)
    {
        var wallObj = new GameObject();
        wallObj.name = "Walls";

        var meshFilter = wallObj.AddComponent<MeshFilter>();
        var meshRenderer = wallObj.AddComponent<MeshRenderer>();
        var meshCollider = wallObj.AddComponent<MeshCollider>();
        
        Material material;
        if (buildingsRender.MaterialMap.TryGetValue("house", out material))
        {
            meshRenderer.material = material;
        }

        vertices = new List<Vector3>();
        triangles = new List<int>();

        foreach (var edge in Floor.WallEdges)
        {
            var edgePair = edge.GetPoints(Floor.Map);
            var point1 = MatchHighest(edgePair.V1, 0.0f);
            var point2 = MatchHighest(edgePair.V2, 0.0f);
            
            RenderPointPair(point1, point2, Vector3.up * Floor.Height);
            RenderPointPair(point2, point1, Vector3.up * Floor.Height);
        }
        
        var mesh = new Mesh();
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.Optimize();
        mesh.RecalculateNormals();
        
        meshFilter.mesh = mesh;
        meshCollider.sharedMesh = mesh;

        vertices = null;
        triangles = null;

        return wallObj;
    }
Ejemplo n.º 11
0
    public void Render(BuildingsRender buildingsRender)
    {
        GameObject prefab;
        if (!buildingsRender.PrefabMap.TryGetValue("pillar", out prefab))
        {
            Debug.Log("Cannot find pillar prefab");
            return;
        }
        
        var meshFilter = gameObject.AddComponent<MeshFilter>();
        var meshRenderer = gameObject.AddComponent<MeshRenderer>();
        var meshCollider = gameObject.AddComponent<MeshCollider>();

        Material material;
        if (buildingsRender.MaterialMap.TryGetValue(Building.Type, out material))
        {
            meshRenderer.material = material;
        }
        
        vertices = new List<Vector3>();
        triangles = new List<int>();

        highest = Building.GetHighestPoint(Map.TerrainData) + 0.2f;
        lowest = Building.GetLowestPoint(Map.TerrainData) - 0.2f;

        var buildingWall = new PolygonSoup();

        foreach (var position in Building.Positions)
        {
            var tile = Map.TerrainData.GetTile(position.x, position.y);

            RenderFloor(tile, highest, false);

            var surrounded = true;
            for (var i = 0; i < 3; i++)
            {
                var edgePosition = tile.GetEdgePosition(i);
                if (!Building.HasPosition(edgePosition))
                {
                    var edgePoints = tile.GetEdgeCorners(i);
                    buildingWall.AddPair(edgePoints);

                    surrounded = false;
                    RenderDownwall(tile, highest, highest - 1.0f, i);
                }
            }
            
            RenderFloor(tile, highest - 1.0f, true);

            if (!surrounded)
            {
                RenderPillar(prefab, tile, highest, false);
                RenderPillar(prefab, tile, highest - 1.0f, true, highest - lowest);
            }
        }

        var offsetPoints = buildingWall.Offset(-0.5f, highest);
        RenderPoints(offsetPoints, false);
        offsetPoints = buildingWall.Offset(-1.0f, highest);
        RenderPoints(offsetPoints, true);

        var mesh = new Mesh();
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.Optimize();
        mesh.RecalculateNormals();
        
        meshFilter.mesh = mesh;
        meshCollider.sharedMesh = mesh;

        vertices = null;
        triangles = null;
    }
Ejemplo n.º 12
0
    public void Render(BuildingsRender buildingsRender)
    {
        GameObject prefab;

        if (!buildingsRender.PrefabMap.TryGetValue("pillar", out prefab))
        {
            Debug.Log("Cannot find pillar prefab");
            return;
        }

        var meshFilter   = gameObject.AddComponent <MeshFilter>();
        var meshRenderer = gameObject.AddComponent <MeshRenderer>();
        var meshCollider = gameObject.AddComponent <MeshCollider>();

        Material material;

        if (buildingsRender.MaterialMap.TryGetValue(Building.Type, out material))
        {
            meshRenderer.material = material;
        }

        vertices  = new List <Vector3>();
        triangles = new List <int>();

        highest = Building.GetHighestPoint(Map.TerrainData) + 0.2f;
        lowest  = Building.GetLowestPoint(Map.TerrainData) - 0.2f;

        var buildingWall = new PolygonSoup();

        foreach (var position in Building.Positions)
        {
            var tile = Map.TerrainData.GetTile(position.x, position.y);

            RenderFloor(tile, highest, false);

            var surrounded = true;
            for (var i = 0; i < 3; i++)
            {
                var edgePosition = tile.GetEdgePosition(i);
                if (!Building.HasPosition(edgePosition))
                {
                    var edgePoints = tile.GetEdgeCorners(i);
                    buildingWall.AddPair(edgePoints);

                    surrounded = false;
                    RenderDownwall(tile, highest, highest - 1.0f, i);
                }
            }

            RenderFloor(tile, highest - 1.0f, true);

            if (!surrounded)
            {
                RenderPillar(prefab, tile, highest, false);
                RenderPillar(prefab, tile, highest - 1.0f, true, highest - lowest);
            }
        }

        var offsetPoints = buildingWall.Offset(-0.5f, highest);

        RenderPoints(offsetPoints, false);
        offsetPoints = buildingWall.Offset(-1.0f, highest);
        RenderPoints(offsetPoints, true);

        var mesh = new Mesh();

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.Optimize();
        mesh.RecalculateNormals();

        meshFilter.mesh         = mesh;
        meshCollider.sharedMesh = mesh;

        vertices  = null;
        triangles = null;
    }