private void ClearAllSelectionsAndHighlightedObjects() { MeshGrid.UnselectAllCells(); MaterialGrid.UnselectAllCells(); TextureGrid.UnselectAllCells(); DataGridUtil.ClearAllHighlighted(MeshGrid); DataGridUtil.ClearAllHighlighted(MaterialGrid); DataGridUtil.ClearAllHighlighted(TextureGrid); }
//TODO: add mutability to meshes (complicated) //TODO: Bad DesignPattern, fix pattern. private void Awake() { GridGameObject = this.gameObject; Grid = MeshGrid.Make(GridGameObject, BorderThickness, GridWidth, GridHeight); if (Instance == null) { Instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } }
private void OnValidate() { Grid = MeshGrid.Make(GridGameObject, BorderThickness, GridWidth, GridHeight); }
// Generates an "outdoor" terrain one large island sporting, foliage, bodies of water, etc. public void GenerateTerrain() { DateTime before = DateTime.Now; DestroyImmediate(parent); //Destroy(parent); mapGrid = new GameGrid(width, height); parent = new GameObject("MAP"); parent.AddComponent <MeshFilter>(); parent.AddComponent <MeshRenderer>(); parent.AddComponent <MeshGrid>(); //mapMaterial=parent.GetComponent<MeshRenderer>().material; parent.GetComponent <MeshRenderer>().material = Resources.Load("test/MapMaterial", typeof(Material)) as Material; meshGrid = parent.GetComponent <MeshGrid>(); if (seed == 0) { seed = UnityEngine.Random.Range(0, int.MaxValue); } // Apply perlin noise GameGrid.GenerateNoiseMap(mapGrid.grid, seed, perlinModifier, octaves, persistance, lacrinarity); float[,] falloff = FalloffGenerator.GenerateFalloffMap(width, height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { //mapGrid.grid[x, y].HeightMap=(mapGrid.grid[x, y].HeightMap*10)-falloff[x, y]*10; // Set first layer of terrain if ((mapGrid.grid[x, y].HeightMap * 10) - falloff[x, y] * 10 >= 1.5) { mapGrid.setCellTileHeight(x, y, 0); mapGrid.setCellType(x, y, 1); } else { mapGrid.setCellType(x, y, 0); } if ((mapGrid.grid[x, y].HeightMap * 10) - falloff[x, y] * 10 >= 5.0) { mapGrid.setCellTileHeight(x, y, 1); } } } //waterGroups=mapGrid.FindConnectedGroups(mapGrid, 0); //mapGrid = Grid.RemoveWater(waterGroups, mapGrid,Mathf.RoundToInt(waterGroups.Count / 1.5f)); // Use Moore Automata to smooth the map if (smoothCount > 0) { GameGrid.SmoothMooreCellularAutomata(mapGrid.grid, smoothCount); GameGrid.SmoothHeightCellularAutomata(mapGrid.grid, smoothCount); } // Removes tiles at the edge, map gen leaves random cells behind. mapGrid.EdgeEraser(); Color[] colourMap = new Color[width * height]; // Deal with the Texture for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float currentHeight = mapGrid.grid[x, y].TileHeight; for (int i = 0; i < regions.Length; i++) { if (currentHeight <= regions[i].height) { colourMap[x * height + y] = regions[i].colour; break; } } } } // If cell.Type >= 1 set walkable to true //Grid.CheckWalkable(mapGrid.grid); // Render the gird //RenderGrid(); /* * * THIS IS THE WORK * WORK ON THIS!!! * * */ //meshGrid.Init(mapGrid.grid); MapDisplay display = FindObjectOfType <MapDisplay>(); if (drawMode == DrawMode.NoiseMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapGrid.grid)); //display.DrawNoiseMap(mapGrid.grid); } else if (drawMode == DrawMode.ColourMap) { display.DrawTexture(TextureGenerator.TextureFromColourMap(colourMap, mapChunkSize, mapChunkSize)); } else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapGrid.grid, meshSettings, 0), TextureGenerator.TextureFromColourMap(colourMap, mapChunkSize, mapChunkSize)); } DateTime after = DateTime.Now; TimeSpan duration = after.Subtract(before); Debug.Log("Terrain Gen took: " + duration.Milliseconds + " ms"); }