/// <summary> /// 预处理地形的函数 /// 通过不同的算法产生地形数据 /// </summary> private void CalcuateMap() { for (int x = 0; x < length; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < width; z++) { Block block = GetTheoreticalBlock(new Vector3(x, y, z) + _selfPos); if (block != null) { if (GetTheoreticalBlock(new Vector3(x, y + 1, z) + _selfPos) == null && block == BlockMap.GetBlock("Dirt")) { _map[x, y, z] = BlockMap.GetBlock("Grass"); } else { _map[x, y, z] = block; } } } } } }
private void BlockContrller() { RaycastHit hitInfo; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo, 10f)) { Vector3 pos = hitInfo.point - hitInfo.normal / 2; //Vector3 pos = new Vector3(hitX, hitY, hitZ); _hightBlock.transform.position = DataUtil.CeilToInt(pos); if (Input.GetMouseButton(0)) { Chunk6Load chunk = GetChunkByWorldPos(DataUtil.CeilToInt(pos)); chunk.SetBlock(pos, null); } else if (Input.GetKeyDown(KeyCode.Q)) { pos = hitInfo.point + hitInfo.normal / 2; Chunk6Load chunk = GetChunkByWorldPos(DataUtil.CeilToInt(pos)); chunk.SetBlock(pos, BlockMap.GetBlock("TNT")); } } else { _hightBlock.transform.position = new Vector3(10000, 10000, 10000); } }
/// <summary> /// 预处理地形的函数 /// 通过不同的算法产生地形数据 /// </summary> private void CalculateMap() { _map = new Block[length, height, width]; for (int x = 0; x < length; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < width; z++) { Block block = GetTheoreticalBlock(new Vector3(x, y, z) + transform.position); if (block != null) { if (GetTheoreticalBlock(new Vector3(x, y + 1, z) + transform.position) == null) { _map[x, y, z] = BlockMap.GetBlock("Grass"); } else { _map[x, y, z] = BlockMap.GetBlock("Dirt"); } } } } } //yield return null; StartCoroutine(CalculateMesh()); }
private void BlockContrllre() { RaycastHit hitInfo; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo, 10f)) { Vector3 pos = hitInfo.point - hitInfo.normal / 2; //Vector3 pos = new Vector3(hitX, hitY, hitZ); _hightBlock.transform.position = new Vector3( Mathf.FloorToInt(pos.x), Mathf.FloorToInt(pos.y), Mathf.FloorToInt(pos.z)); if (Input.GetMouseButtonDown(0)) { Chunk5Ctrl chunk = Chunk5Ctrl.GetChunk(FloorToIntVector3(pos)); chunk.SetChunk(pos, null); } else if (Input.GetKeyDown(KeyCode.Q)) { pos = hitInfo.point + hitInfo.normal / 2; Chunk5Ctrl chunk = Chunk5Ctrl.GetChunk(FloorToIntVector3(pos)); chunk.SetChunk(pos, BlockMap.GetBlock("TNT")); } } else { _hightBlock.transform.position = new Vector3(10000, 10000, 10000); } }
/// <summary> /// 预处理地形的函数 /// 通过不同的算法产生地形数据 /// </summary> private void CalculateMap() { _mesh = new Mesh(); _mesh.name = "Chunck"; _map = new Block[length, height, width]; for (int x = 0; x < length; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < width; z++) { if (y == height - 1) { if (Random.value > 0.7f) { _map[x, y, z] = BlockMap.GetBlock("Grass"); } else { _map[x, y, z] = null; } } else { _map[x, y, z] = BlockMap.GetBlock("Dirt"); } } } } CalculateMesh(); }
private void Start() { inventoryItem = new Block[width, height]; inventoryNum = new int[width, height]; BlockMap.GetBlock("Dirt").SetTexture(texDirt); AddItem(BlockMap.GetBlock("Dirt"), 67); AddItem(BlockMap.GetBlock("Dirt"), 5); AddItem(BlockMap.GetBlock("Dirt"), 5); AddItem(BlockMap.GetBlock("Dirt"), 111); }
public Block GetTheoreticalBlock(Vector3 pos) { Random.InitState(seed); Vector3 offset = new Vector3(Random.value * 100000, Random.value * 100000, Random.value * 100000); float noiseX = Mathf.Abs(pos.x + offset.x) / 20; float noiseY = Mathf.Abs(pos.y + offset.y) / 20; float noiseZ = Mathf.Abs(pos.z + offset.z) / 20; float noiseValue = SimplexNoise.Noise.Generate(noiseX, noiseY, noiseZ); noiseValue += (20.0f - pos.y) / 18; noiseValue /= pos.y / 4; return(noiseValue > 0.2f ? BlockMap.GetBlock("Dirt") : null); }
public Block GetTheoreticalBlock(Vector3 pos) { System.Random random = new System.Random(seed); Vector3 offset = new Vector3((float)random.NextDouble() * 100000, (float)random.NextDouble() * 100000, (float)random.NextDouble() * 100000); float noiseX = Mathf.Abs(pos.x + offset.x) / 20; float noiseY = Mathf.Abs(pos.y + offset.y) / 20; float noiseZ = Mathf.Abs(pos.z + offset.z) / 20; //float noiseValue = SimplexNoise.Noise.Generate(noiseX, noiseY, noiseZ); double noiseValue = noise.GetValue(noiseX, noiseY, noiseZ); noiseValue += (20.0f - pos.y) / 18; noiseValue /= pos.y / 4; return(noiseValue > 0.2f ? BlockMap.GetBlock("Dirt") : null); }
public static List <GameObject> Render(Planet planet, int regionIndex, int chunkIndex) { var tileRegion = planet.HexSphere.Regions[regionIndex]; var chunk = planet.Regions[regionIndex].Chunks[chunkIndex]; var gameObjects = new List <GameObject>(); foreach (var(layer, layerIndex) in chunk.Layers.WithIndex()) { foreach (var(blockId, index) in layer.Blocks.WithIndex()) { var tile = tileRegion.Tiles[index]; var block = BlockMap.GetBlock(blockId); var bottomRadius = planet.BaseRadius + (chunkIndex * planet.ChunkHeight + layerIndex) * planet.BlockHeight; if (!block.IsRendered) { continue; } var mesh = TileToMeshMapper.Map(tile, bottomRadius, planet.BlockHeight); var go = new GameObject("Block"); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); go.GetComponent <MeshFilter>().mesh = mesh; go.GetComponent <MeshRenderer>().material = (block as RenderedBlock)?.Material; if (block.IsSolid) { go.AddComponent <MeshCollider>(); go.GetComponent <MeshCollider>().sharedMesh = mesh; } go.transform.position = PointHelpers.ProjectToRadius(tile.Center, bottomRadius).AsVector(); gameObjects.Add(go); } } return(gameObjects); }
/// <summary> /// 预处理地形 /// </summary> IEnumerator CalculateMap() { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < width; z++) { map[x, y, z] = BlockMap.GetBlock("TestDir"); } } } yield return(null); StartCoroutine(CalculateMesh()); }
/// <summary> /// 预处理地形的函数 /// 通过不同的算法产生地形数据 /// </summary> private void CalculateMap() { _mesh = new Mesh(); _mesh.name = "Chunck"; _map = new Block[length, height, width]; for (int x = 0; x < length; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < width; z++) { //if (y == height - 1) // _map[x, y, z] = BlockMap.GetBlock("Grass"); //else // _map[x, y, z] = BlockMap.GetBlock("Dirt"); _map[x, y, z] = BlockMap.GetBlock("TestDir"); } } } CalculateMesh(); }