public bool CheckNeighbors() { int isPopulated = 0; int isValid = 0; Vector3 cubePosition = HexMath.AxialToCube(HexMath.PixelToHex(transform.position)); RaycastHit hit; int direction; for (int i = 0; i < 6; i++) { if (Physics.Raycast(HexMath.HexToPixel(HexMath.CubeToAxial(cubePosition + HexMath.direction[i])) + Vector3.forward, Vector3.back, out hit)) { Hex hex = hit.collider.GetComponent <Hex>(); if (hex != null) { isPopulated++; direction = i + 3; if (direction > 5) { direction -= 6; } if (hex.CheckValidity(direction, fieldType[i])) { isValid++; } } } } return((isPopulated != 0) && (isPopulated == isValid)); }
public void Update() { if (loader != null) { //TODO: calculate loaders position to the current chunk instead of raycast Vector2 pixelCoords = new Vector2(loader.position.x, loader.position.z); Vector3 hexCoords = HexMath.PixelToHex(pixelCoords.x, pixelCoords.y, Game.World.HexData); //Tile(-33,-8) -> Chunk(-3,-1) //-33/13 = -2.5 ~= -3, -8/13 = -0.6 ~= -1 int chunkSize = Game.GameConfig.chunkSize; float x = Mathf.Round(hexCoords.x / chunkSize); float z = Mathf.Round(hexCoords.y / chunkSize); float y = Mathf.Round(hexCoords.z / chunkSize); Vector3 chunkCoords = new Vector3(x, y, z); Debug.Log(chunkCoords); /*if (Game.World.Chunks.ContainsKey(chunkCoords)) { Debug.Log("Exists"); ChangeChunk(chunkCoords); //currentChunk = Game.World.Chunks[chunkCoords]; //Game.ThreadQueuer.StartThreadedFunction(ManageChunks); }*/ ChangeChunk(chunkCoords); } UpdateChunks(); }
// Update is called once per frame void Update() { if (pointer != null) { Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition); position = HexMath.HexToPixel(HexMath.PixelToHex(position)); pointer.transform.position = position; if (Input.GetMouseButtonDown(0) && pointer.CheckNeighbors()) { pointer.EndDrag(); pointer = null; pointer = InstantiateHex(); pointer.BeginDrag(); } } }