public Mesh GetTerrainOutterMesh(TerrainTallFeature feature)
    {
        Mesh mesh;

        if (outterDictionary.TryGetValue(feature, out mesh))
        {
            return(mesh);
        }
        mesh = generateOutterMesh(feature);
        outterDictionary.Add(feature, mesh);
        return(mesh);
    }
Esempio n. 2
0
    public void SetFeature(TerrainViewFeature viewFeature, TerrainTallFeature tallFeature)
    {
        this.viewFeature = viewFeature;
        this.tallFeature = tallFeature;

        Vector3 position = transform.position;

        position.y         = (this.tallFeature.Tall - 1) * TALL_HEIGHT;
        transform.position = position;

        tallFeature.Tall = 0;

        mfSurface.sharedMesh = TerrainMeshGenerator.Instance.GetTerrainSurfaceMesh(viewFeature);
        mfInner.sharedMesh   = TerrainMeshGenerator.Instance.GetTerrainInnerMesh(viewFeature);
        mfOutter.sharedMesh  = TerrainMeshGenerator.Instance.GetTerrainOutterMesh(tallFeature);
    }
    private void terrainViewFeatureOfPosition(Vector2Int position, out TerrainViewFeature terrainViewFeature, out TerrainTallFeature terrainTallFeature)
    {
        int x = position.x;
        int y = position.y;

        terrainViewFeature = new TerrainViewFeature(false, false, false, false, false, false, false, false, false);
        terrainTallFeature = new TerrainTallFeature(0, false, false, false, false);

        bool waterCenter = island.TerrainTypeOfCell(position) == TerrainType.Water;

        if (waterCenter)
        {
            bool waterFront      = island.TerrainTypeOfCell(new Vector2Int(x, y - 1)) == TerrainType.Water;
            bool waterLeft       = island.TerrainTypeOfCell(new Vector2Int(x - 1, y)) == TerrainType.Water;
            bool waterBack       = island.TerrainTypeOfCell(new Vector2Int(x, y + 1)) == TerrainType.Water;
            bool waterRight      = island.TerrainTypeOfCell(new Vector2Int(x + 1, y)) == TerrainType.Water;
            bool waterFrontLeft  = island.TerrainTypeOfCell(new Vector2Int(x - 1, y - 1)) == TerrainType.Water;
            bool waterBackLeft   = island.TerrainTypeOfCell(new Vector2Int(x - 1, y + 1)) == TerrainType.Water;
            bool waterBackRight  = island.TerrainTypeOfCell(new Vector2Int(x + 1, y + 1)) == TerrainType.Water;
            bool waterFrontRight = island.TerrainTypeOfCell(new Vector2Int(x + 1, y - 1)) == TerrainType.Water;

            terrainViewFeature.WaterCenter = waterCenter;
            terrainViewFeature.WaterF      = waterFront;
            terrainViewFeature.WaterL      = waterLeft;
            terrainViewFeature.WaterB      = waterBack;
            terrainViewFeature.WaterR      = waterRight;
            terrainViewFeature.WaterFL     = waterFront && waterLeft && waterFrontLeft;
            terrainViewFeature.WaterBL     = waterBack && waterLeft && waterBackLeft;
            terrainViewFeature.WaterBR     = waterBack && waterRight && waterBackRight;
            terrainViewFeature.WaterFR     = waterFront && waterRight && waterFrontRight;
        }

        TerrainTall tall      = island.TerrainTallOfCell(position);
        bool        tallFront = island.TerrainTallOfCell(new Vector2Int(x, y - 1)) < tall;
        bool        tallLeft  = island.TerrainTallOfCell(new Vector2Int(x - 1, y)) < tall;
        bool        tallBack  = island.TerrainTallOfCell(new Vector2Int(x, y + 1)) < tall;
        bool        tallRight = island.TerrainTallOfCell(new Vector2Int(x + 1, y)) < tall;

        terrainTallFeature.Front = tallFront;
        terrainTallFeature.Left  = tallLeft;
        terrainTallFeature.Back  = tallBack;
        terrainTallFeature.Right = tallRight;

        terrainTallFeature.Tall = (int)tall;

        return;
    }
    private Mesh generateOutterMesh(TerrainTallFeature feature)
    {
        if (!feature.Front && !feature.Left && !feature.Back && !feature.Right)
        {
            return(null);
        }

        Mesh mesh = new Mesh();

        mesh.vertices = outterVertices;
        mesh.normals  = outterNormals;
        mesh.uv       = outterUVs;

        List <int> triangleList = new List <int>();

        if (feature.Front)
        {
            triangleList.AddRange(outterTriangles[2]);
        }
        if (feature.Left)
        {
            triangleList.AddRange(outterTriangles[3]);
        }
        if (feature.Back)
        {
            triangleList.AddRange(outterTriangles[0]);
        }
        if (feature.Right)
        {
            triangleList.AddRange(outterTriangles[1]);
        }


        mesh.triangles = triangleList.ToArray();

        return(mesh);
    }
Esempio n. 5
0
    public void SetTerrainFeature(Vector2Int position, TerrainViewFeature viewFeature, TerrainTallFeature tallFeature)
    {
        TerrainCellView terrainCellView = getCellView(position);

        terrainCellView.SetFeature(viewFeature, tallFeature);
    }