void SetBlock(Vector3 p, Block b) { RaycastHit hit; int i = 0; Chunck chunck = Chunck.GetChunck(Mathf.FloorToInt(p.x), Mathf.FloorToInt(p.y), Mathf.FloorToInt(p.z)); Vector3 localPos = chunck.transform.position - p; if (b == null) { map = chunck.GetBlock(p); if (map == null) { map = Block.getBlock(BlockList.Blocks[tmp].BlockName); } item = GetItem(map); if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 7f, lm)) { if (hit.transform.gameObject.tag != "Obje") { if (hit.transform.gameObject.tag != "Tree") { if (hit.transform.gameObject.tag != "Player") { GameObject obje = Instantiate(Resources.Load <GameObject>(map.BlockName), BlockHighlight.transform.position + new Vector3(0, 0.5f, 0), Quaternion.identity) as GameObject; obje.GetComponent <Obje>().item = item; Debug.Log("Obje = " + obje.transform.position + "Chunck Pos = " + chunck.transform.position + "P=" + p + "Local Pos=" + localPos); } } } } } map = null; if ((Mathf.FloorToInt(localPos.x) * -1) == (Chunck.Width)) { Chunck c = Chunck.GetChunck(Mathf.FloorToInt(p.x + 5), Mathf.FloorToInt(p.y), Mathf.FloorToInt(p.z)); if (c == null) { return; } c.SetBlock(p + new Vector3(+1, 0, 0), b); } else { Chunck c = Chunck.GetChunck(Mathf.FloorToInt(p.x - 5), Mathf.FloorToInt(p.y), Mathf.FloorToInt(p.z)); if (c == null) { return; } c.SetBlock(p + new Vector3(+1, 0, 0), b); } chunck.SetBlock(p + new Vector3(+1, 0, 0), b); }
bool isBlockTransparent(int x, int y, int z) { if (x >= Width) { Vector3 worldPosition = new Vector3(x, y, z) + transform.position; if (right == null) { right = GetChunck(Mathf.FloorToInt(worldPosition.x), Mathf.FloorToInt(worldPosition.y), Mathf.FloorToInt(worldPosition.z)); } if (right != this && right != null && right.generatedMap == true) { if (right.GetBlock(worldPosition) == null) { return(true); } else { return(false); } } return(true); } if (x < 0) { Vector3 worldPosition = new Vector3(x, y, z) + transform.position; if (left == null) { left = GetChunck(Mathf.FloorToInt(worldPosition.x), Mathf.FloorToInt(worldPosition.y), Mathf.FloorToInt(worldPosition.z)); } if (left != this && left != null && left.generatedMap == true) { if (left.GetBlock(worldPosition) == null) { return(true); } else { return(false); } } return(true); } if (z >= Width) { Vector3 worldPosition = new Vector3(x, y, z) + transform.position; if (front == null) { front = GetChunck(Mathf.FloorToInt(worldPosition.x), Mathf.FloorToInt(worldPosition.y), Mathf.FloorToInt(worldPosition.z)); } if (front != this && front != null && front.generatedMap == true) { if (front.GetBlock(worldPosition) == null) { return(true); } else { return(false); } } return(true); } if (z < 0) { Vector3 worldPosition = new Vector3(x, y, z) + transform.position; if (back == null) { back = GetChunck(Mathf.FloorToInt(worldPosition.x), Mathf.FloorToInt(worldPosition.y), Mathf.FloorToInt(worldPosition.z)); } if (back != this && back != null && back.generatedMap == true) { if (back.GetBlock(worldPosition) == null) { return(true); } else { return(false); } } return(true); } if (y >= Height) { Vector3 worldPosition = new Vector3(x, y, z) + transform.position; if (top == null) { top = GetChunck(Mathf.FloorToInt(worldPosition.x), Mathf.FloorToInt(worldPosition.y), Mathf.FloorToInt(worldPosition.z)); } if (top != this && top != null && top.generatedMap == true) { if (top.GetBlock(worldPosition) == null) { return(true); } else { return(false); } } return(true); } if (y < 0) { Vector3 worldPosition = new Vector3(x, y, z) + transform.position; if (bottom == null) { bottom = GetChunck(Mathf.FloorToInt(worldPosition.x), Mathf.FloorToInt(worldPosition.y), Mathf.FloorToInt(worldPosition.z)); } if (bottom != this && bottom != null && bottom.generatedMap == true) { if (bottom.GetBlock(worldPosition) == null) { return(true); } else { return(false); } } return(true); } if (map[x, y, z] == null) { return(true); } if (map[x, y, z].Trasnsparent) { return(true); } return(false); }