public new static OpenWaterChunkLayer CreateEmpty( Material material, bool useCollider, bool useHexData, bool useUVCoordinates, bool useUV2Coordinates ) { GameObject resultObj = new GameObject("Open Water Chunk Layer"); OpenWaterChunkLayer resultMono = resultObj.AddComponent <OpenWaterChunkLayer>(); resultMono.GetComponent <MeshRenderer>().material = material; resultMono._useCollider = useCollider; if (useCollider) { resultMono._meshCollider = resultObj.AddComponent <MeshCollider>(); } resultMono._useHexData = useHexData; resultMono._useUVCoordinates = useUVCoordinates; resultMono._useUV2Coordinates = useUV2Coordinates; return(resultMono); }
public static MapMeshChunk CreateEmpty() { GameObject resultObj = new GameObject("Map Mesh Chunk"); MapMeshChunk resultMono = resultObj.AddComponent <MapMeshChunk>(); resultMono.Hexes = new Hex[ HexMeshConstants.CHUNK_SIZE_X * HexMeshConstants.CHUNK_SIZE_Z ]; GameObject resultCanvasObj = new GameObject( "World Space UI Canvas" ); Canvas resultCanvasMono = resultCanvasObj.AddComponent <Canvas>(); CanvasScaler resultCanvasScalerMono = resultCanvasObj.AddComponent <CanvasScaler>(); resultCanvasObj.transform.SetParent( resultObj.transform, false ); resultMono.WorldSpaceUICanvas = resultCanvasMono; resultCanvasScalerMono.dynamicPixelsPerUnit = 10f; resultCanvasObj.transform.rotation = Quaternion.Euler( 90, 0, 0 ); resultCanvasObj.transform.position += Vector3.up * .005f; resultMono._terrainLayer = TerrainChunkLayer.CreateEmpty( Resources.Load <Material>("Terrain"), true, true, false, false ); resultMono._terrainLayer.transform.SetParent( resultObj.transform, false ); resultMono._riversLayer = RiversChunkLayer.CreateEmpty( Resources.Load <Material>("River"), false, true, true, false ); resultMono._riversLayer.transform.SetParent( resultObj.transform, false ); resultMono._roadsLayer = RoadsChunkLayer.CreateEmpty( Resources.Load <Material>("Road"), false, true, true, false ); resultMono._roadsLayer.transform.SetParent( resultObj.transform, false ); resultMono._openWaterLayer = OpenWaterChunkLayer.CreateEmpty( Resources.Load <Material>("Water"), false, true, false, false ); resultMono._openWaterLayer.transform.SetParent( resultObj.transform, false ); resultMono._waterShoreLayer = WaterShoreChunkLayer.CreateEmpty( Resources.Load <Material>("WaterShore"), false, true, true, false ); resultMono._waterShoreLayer.transform.SetParent( resultObj.transform, false ); resultMono._estuariesLayer = EstuariesChunkLayer.CreateEmpty( Resources.Load <Material>("Estuary"), false, true, true, true ); resultMono._estuariesLayer.transform.SetParent( resultObj.transform, false ); MapMeshChunkLayer walls = MapMeshChunkLayer.CreateEmpty( Resources.Load <Material>("Urban"), false, false, false, false ); walls.name = "Walls Layer"; walls.transform.SetParent(resultObj.transform, false); resultMono._features = FeatureContainer.GetFeatureContainer( walls ); resultMono._features.transform.SetParent( resultObj.transform, false ); resultMono._features.name = "Features Layer"; return(resultMono); }
/// <summary> /// Triangulate the mesh geometry of an individual hex. /// </summary> /// <param name="source"> /// The hex to whose mesh geometry is to be triangluated. /// </param> /// <param name="hexOuterRadius"> /// The outer radius of the hex to be triangulated. /// </param> /// <param name="adjacencyGraph"> /// /// </param> /// <param name="riverDigraph"></param> /// <param name="roadUndirectedGraph"></param> /// <param name="elevationDigraph"></param> /// <param name="wrapSize"></param> private void TriangulateHex( Hex source, Dictionary <HexDirections, Hex> neighbors, List <HexDirections> borderDirections, float hexOuterRadius, HexRiverData riverData, Dictionary <HexDirections, bool> roadEdges, Dictionary <HexDirections, ElevationEdgeTypes> elevationEdgeTypes, int wrapSize, TerrainChunkLayer terrainLayer, RiversChunkLayer riversLayer, RoadsChunkLayer roadsLayer, OpenWaterChunkLayer openWaterLayer, WaterShoreChunkLayer waterShoreLayer, EstuariesChunkLayer estuariesLayer, FeatureContainer features ) { foreach ( KeyValuePair <HexDirections, Hex> pair in neighbors ) { // Initialize triangulation data. HexDirections direction = pair.Key; Hex neighbor = pair.Value; TerrainTriangulationData terrainTriData = new TerrainTriangulationData(); terrainTriData.terrainCenter = source.Position; terrainTriData = GetCenterEdgeVertices( direction, terrainTriData, hexOuterRadius ); if (direction <= HexDirections.Southeast) { terrainTriData = GetConnectionEdgeVertices( source, neighbor, direction, terrainTriData, hexOuterRadius ); } // Triangulate layers for non-border edge. terrainTriData = terrainLayer.TriangulateHexTerrainEdge( source, neighbor, terrainTriData, neighbors, direction, riverData, features, roadEdges, elevationEdgeTypes, hexOuterRadius, wrapSize ); terrainTriData = roadsLayer.TriangulateHexRoadEdge( source, neighbor, terrainTriData, direction, riverData, features, roadEdges, elevationEdgeTypes, hexOuterRadius, wrapSize ); terrainTriData = riversLayer.TriangulateHexRiverEdge( source, neighbor, direction, roadEdges, riverData, terrainTriData, hexOuterRadius, wrapSize ); WaterTriangulationData waterTriData = new WaterTriangulationData(); waterTriData = GetWaterData( source, neighbor, waterTriData, direction, hexOuterRadius, wrapSize ); waterTriData = openWaterLayer.TriangulateHexOpenWaterEdge( source, neighbor, neighbors, direction, waterTriData, terrainTriData, hexOuterRadius, wrapSize ); waterTriData = waterShoreLayer.TriangulateHexWaterShoreEdge( source, neighbor, neighbors, direction, riverData, waterTriData, hexOuterRadius, wrapSize ); waterTriData = estuariesLayer.TriangulateHexEstuaryEdge( source, neighbor, direction, riverData, waterTriData, hexOuterRadius, wrapSize ); } bool anyEdge = false; foreach (KeyValuePair <HexDirections, bool> pair in roadEdges) { if (pair.Value) { anyEdge = true; break; } } // Add feature or special to hex. if (!source.IsUnderwater) { if ( !riverData.HasRiver && !anyEdge ) { features.AddFeature( source, source.Position, hexOuterRadius, wrapSize ); } if (source.IsSpecial) { features.AddSpecialFeature( source, source.Position, hexOuterRadius, wrapSize ); } } }