public void Initialize(GridPos localGP, GridRect space, GridPosR.OrientationFlag adjacentConnection, GridPosR.OrientationFlag diagonalConnection) { LocalGridPosText.text = localGP.ToString(); LocalGridPos = localGP; BoxCollider.size = new Vector3(space.size.x, space.size.z, 1); BoxCollider.center = new Vector3((space.position.x + 0.5f) * space.size.x, (space.position.z - 0.5f) * space.size.z, 0); ImageBorderContainer.anchoredPosition = new Vector2(space.position.x * space.size.x, space.position.z * space.size.z); SetConnection(adjacentConnection, diagonalConnection); }
public void SetConnection(GridPosR.OrientationFlag adjacentConnection, GridPosR.OrientationFlag diagonalConnection) { foreach (GridPosR.Orientation orientation in Enum.GetValues(typeof(GridPosR.Orientation))) { MainImageBorders[(int)orientation].enabled = !adjacentConnection.HasFlag(orientation.ToFlag()); GridPosR.Orientation next = GridPosR.RotateOrientationClockwise90(orientation); if (!adjacentConnection.HasFlag(orientation.ToFlag()) && !adjacentConnection.HasFlag(next.ToFlag())) { SideImageBorders[((int)orientation) * 2].enabled = false; SideImageBorders[((int)orientation) * 2 + 1].enabled = false; } else if (adjacentConnection.HasFlag(orientation.ToFlag()) && adjacentConnection.HasFlag(next.ToFlag())) { if (diagonalConnection.HasFlag(orientation.ToFlag())) { SideImageBorders[((int)orientation) * 2].enabled = false; SideImageBorders[((int)orientation) * 2 + 1].enabled = false; } else { SideImageBorders[((int)orientation) * 2].enabled = true; SideImageBorders[((int)orientation) * 2 + 1].enabled = true; } } else { if (adjacentConnection.HasFlag(orientation.ToFlag())) { SideImageBorders[((int)orientation) * 2].enabled = true; SideImageBorders[((int)orientation) * 2 + 1].enabled = false; } else { SideImageBorders[((int)orientation) * 2].enabled = false; SideImageBorders[((int)orientation) * 2 + 1].enabled = true; } } } }
/// <summary> /// /// </summary> /// <param name="gridPos"></param> /// <param name="connectionMatrix"></param> /// <param name="offset"></param> /// <param name="adjacentConnection"></param> /// <param name="diagonalConnection">Up->TopRight, Right->BottomRight, Down->BottomLeft, Left->TopLeft</param> /// <returns></returns> public static void GetConnection(this GridPos gridPos, bool[,] connectionMatrix, GridPos offset, out GridPosR.OrientationFlag adjacentConnection, out GridPosR.OrientationFlag diagonalConnection) { adjacentConnection = GridPosR.OrientationFlag.None; diagonalConnection = GridPosR.OrientationFlag.None; GridPos localGP = gridPos + offset; if (localGP.x < 0 || localGP.x >= connectionMatrix.GetLength(0) || localGP.z < 0 || localGP.z >= connectionMatrix.GetLength(1)) { return; } if (localGP.x + 1 < connectionMatrix.GetLength(0) && connectionMatrix[localGP.x + 1, localGP.z]) { adjacentConnection |= GridPosR.OrientationFlag.Right; } if (localGP.x - 1 >= 0 && connectionMatrix[localGP.x - 1, localGP.z]) { adjacentConnection |= GridPosR.OrientationFlag.Left; } if (localGP.z + 1 < connectionMatrix.GetLength(1) && connectionMatrix[localGP.x, localGP.z + 1]) { adjacentConnection |= GridPosR.OrientationFlag.Up; } if (localGP.z - 1 >= 0 && connectionMatrix[localGP.x, localGP.z - 1]) { adjacentConnection |= GridPosR.OrientationFlag.Down; } if (localGP.x + 1 < connectionMatrix.GetLength(0) && localGP.z + 1 < connectionMatrix.GetLength(1) && connectionMatrix[localGP.x + 1, localGP.z + 1]) { diagonalConnection |= GridPosR.OrientationFlag.Up; } if (localGP.x + 1 < connectionMatrix.GetLength(0) && localGP.z - 1 >= 0 && connectionMatrix[localGP.x + 1, localGP.z - 1]) { diagonalConnection |= GridPosR.OrientationFlag.Right; } if (localGP.x - 1 >= 0 && localGP.z - 1 >= 0 && connectionMatrix[localGP.x - 1, localGP.z - 1]) { diagonalConnection |= GridPosR.OrientationFlag.Down; } if (localGP.x - 1 >= 0 && localGP.z + 1 < connectionMatrix.GetLength(1) && connectionMatrix[localGP.x - 1, localGP.z + 1]) { diagonalConnection |= GridPosR.OrientationFlag.Left; } }