public void PreviewAction(CubeData data) { if (mode == PreviewMode.cube) { byte d; if (controlType == CharacherCubeControlType.add) { d = data.ToByte(); } else { d = 0; } grid.SetCubeData(transform.position, data.ToByte()); } else { if (controlType == CharacherCubeControlType.copy) { Debug.Log("getorientate:" + PreviewOrientate); GetDataFromPreviewBox(PreviewOrientate); } else { SetDataFromPreviewBox(PreviewOrientate); } } }
void SetDataFromPreviewBox(CubeOrientate orientate) { var allPoint = GetCurrentCubePoints(orientate); for (int i = 0; i < datas.Length; i++) { CubeData data = CubeData.ToCubeData(datas[i]); if (data.active) { data.orientate = data.orientate.AddOrientate(orientate); data.isTransparent = true; grid.SetCubeData(allPoint[i], data.ToByte()); BuilderAI.pendingPosList.Enqueue(allPoint[i]); } } }
void GetDataFromPreviewBox(CubeOrientate orientate) { var allPoint = GetCurrentCubePoints(orientate); for (int i = 0; i < allPoint.Length; i++) { CubeData data = CubeData.ToCubeData(grid.GetCubeData(allPoint[i])); if (!data.isTransparent && data.active) { data.orientate = data.orientate.SubOrientate(orientate); datas[i] = data.ToByte(); } else { datas[i] = byte.MinValue; } } }
void CubeControlUpdate() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject() && CheckGround()) { animator.SetTrigger("Build"); ParticleSystem p = Instantiate(destroy); if (controlType == CharacherCubeControlType.add) { CubeData data = new CubeData(true, false, CubeOrientate.front, cubeType); grid.SetCubeData(va, data.ToByte()); p.transform.position = va; } else { grid.SetCubeData(vr, byte.MinValue); p.transform.position = vr; } p.Play(); } }
IEnumerator Building(Vector3 target) { Vector3 dir = (target - transform.position).normalized; dir.y = 0; transform.forward = dir; animator.SetTrigger("Build"); ParticleSystem partic = Instantiate(p); partic.transform.position = target; partic.Play(); CubeData data = CubeData.ToCubeData(grid.GetCubeData(target)); data.isTransparent = false; grid.SetCubeData(target, data.ToByte()); SetInfo(); yield return(new WaitForSeconds(0.5f)); }
public static byte[] GetTerrainData(CubeChunk chunk) { byte[] data = new byte[CHUNK_WIDTH * CHUNK_WIDTH * CHUNK_WIDTH]; for (int y = 0; y < CHUNK_WIDTH; y++) { for (int z = 0; z < CHUNK_WIDTH; z++) { for (int x = 0; x < CHUNK_WIDTH; x++) { float cubeX = chunk.transform.position.x + x * CUBE_SIDE_LENGTH + CUBE_SIDE_LENGTH / 2f; float cubeY = chunk.transform.position.y + y * CUBE_SIDE_LENGTH + CUBE_SIDE_LENGTH / 2f; float cubeZ = chunk.transform.position.z + z * CUBE_SIDE_LENGTH + CUBE_SIDE_LENGTH / 2f; Vector3 p = new Vector3(cubeX, cubeY, cubeZ); float perlin = Mathf.PerlinNoise((p.x + TerrainSeed) * 0.010f, (p.z + TerrainSeed) * 0.010f) * 37f; float currentHeight = p.y; float heightDiff = Mathf.Abs(perlin - currentHeight); if (perlin > currentHeight) { CubeType temp; if (heightDiff < CUBE_SIDE_LENGTH) { temp = CubeType.grass; } else { if (currentHeight > 0) { temp = GetProbability(0.8f) ? CubeType.clay : CubeType.stone; } else if (currentHeight > -5 * CUBE_SIDE_LENGTH) { temp = GetProbability(0.5f) ? CubeType.stone : CubeType.clay; } else if (currentHeight > -10 * CUBE_SIDE_LENGTH) { temp = GetProbability(0.4f) ? CubeType.coal : CubeType.clay; } else if (currentHeight > -20 * CUBE_SIDE_LENGTH) { temp = GetProbability(0.2f) ? CubeType.copper : CubeType.stone; } else if (currentHeight > -30 * CUBE_SIDE_LENGTH) { temp = GetProbability(0.05f) ? CubeType.gold : CubeType.stone; } else { temp = GetProbability(0.01f) ? CubeType.diamond : CubeType.magma; } } CubeData d = new CubeData(true, false, CubeOrientate.front, temp); data[x + y * CHUNK_WIDTH * CHUNK_WIDTH + z * CHUNK_WIDTH] = d.ToByte(); } else { data[x + y * CHUNK_WIDTH * CHUNK_WIDTH + z * CHUNK_WIDTH] = byte.MinValue; } } } } return(data); }