void Start() { // mesh = new Mesh (); // // AddFrontFace (); // AddBackFace (); // AddLeftFace (); // AddRightFace (); // AddTopFace (); // AddBottomFace (); // // mesh.vertices = vertices.ToArray (); // mesh.triangles = triangles.ToArray (); // // mesh.RecalculateBounds (); // mesh.RecalculateNormals (); // // GetComponent<MeshFilter> ().mesh = mesh; position = new Vector3int(this.transform.position); if (Map.Instance.ChunkExists(position)) { Debug.Log("此方块已存在" + position); Destroy(this); } else { Map.Instance.chunks.Add(position, this.gameObject); this.name = "(" + position.x + "," + position.y + "," + position.z + ")"; StartFunction(); } }
public static byte GetTerrainBlock(Vector3int worldPosition) { //LibNoise噪音对象 Perlin noise = new LibNoise.Generator.Perlin(1f, 1f, 1f, 8, GameManager.randomSeed, QualityMode.High); //为随机数指定种子,这样每次随机的都是同样的值 Random.InitState(GameManager.randomSeed); //因为柏林噪音在(0,0)点是上下左右对称的,所以我们设置一个很远很远的地方作为新的(0,0)点 Vector3 offset = new Vector3(Random.value * 100000, Random.value * 100000, Random.value * 100000); float noiseX = Mathf.Abs((worldPosition.x + offset.x) / 20); float noiseY = Mathf.Abs((worldPosition.y + offset.y) / 20); float noiseZ = Mathf.Abs((worldPosition.z + offset.z) / 20); double noiseValue = noise.GetValue(noiseX, noiseY, noiseZ); noiseValue += (20 - worldPosition.y) / 15f; noiseValue /= worldPosition.y / 5f; if (noiseValue > 0.5f) { return(1); } return(0); }
public IEnumerator SpawnChunk(Vector3int pos) { spawningChunk = true; Instantiate(chunkPrefab, pos, Quaternion.identity); yield return(0); spawningChunk = false; }
//生成Chunk public void CreateChunk(Vector3int pos) { if (spawningChunk) { return; } StartCoroutine(SpawnChunk(pos)); }
public static bool isEmpty(float x, float y, float z) { Vector3int pos = FromRealtoGrid(x, y, z); if (grid[pos.x, pos.y, pos.z] == null) { return(true); } return(false); }
//通过Chunk的坐标来判断它是否存在 public bool ChunkExists(Vector3int woeldPosition) { return(this.ChunkExists(woeldPosition.x, woeldPosition.y, woeldPosition.z)); }