/// <summary> /// 两个相邻的拼图是否足够接近 /// </summary> /// <param name="A">当前选中的拼图的位置</param> /// <param name="B">需要移动的另一个拼图的位置</param> /// <param name="type">邻居类型</param> /// <returns>是否足够接近</returns> bool IsClosedToConnect(Vector3 A, Vector3 B, NeighborType type) { // 保存当前拼图在 Y 轴大小的一半 Vector3 Y = new Vector3(0, size.y / 2, 0); // 保存当前拼图在 X 轴大小的一半 Vector3 X = new Vector3(size.x / 2, 0, 0); Vector3 a, b; switch (type) { // 邻居在上面 case NeighborType.Top: // 当前对象 加上 Y 轴的偏移的一半 a = A + Y; // 邻居 减去 Y 轴的偏移的一半 b = B - Y; break; // 邻居在下面 case NeighborType.Bottom: // 当前对象 减去 Y 轴的偏移的一半 a = A - Y; // 邻居 加上 Y 轴的偏移的一半 b = B + Y; break; // 邻居在左边 case NeighborType.Left: // 当前对象 减去 X 轴的偏移的一半 a = A - X; // 邻居 加上 X 轴的偏移的一半 b = B + X; break; // 邻居在右边 case NeighborType.Right: // 当前对象 加上 X 轴的偏移的一半 a = A + X; // 邻居 减去 X 轴的偏移的一半 b = B - X; break; // 不是邻居,返回 false default: return(false); } // 测试当前 距离是否小于 设置的大小,并返回结果 return(Vector3.Distance(a, b) < manager.largestSize); }
private Item GetNeighboringItem(NeighborType type, Bag bag, double accumulatedWeight, double accumulatedValue) { if (type == NeighborType.WeightNeighbor) { var lowerLimit = accumulatedWeight * 0.65; var totalAllowence = (bag.WeightCapacity - bag.AccumulatedWeight) + lowerLimit; var fittingItem = bag.Items .Where(item => item.Weight >= lowerLimit && item.Weight <= totalAllowence) .Select(item => item) .Where(item => item.Value < accumulatedValue) .OrderBy(item => item.Value) .FirstOrDefault(); if (fittingItem != null) { var replacement = fittingItem; } return(fittingItem); } else { return(null); } }
public AccommodationPotentialNeighbors(Claim claim, NeighborType type) { ClaimId = claim.ClaimId; ClaimName = claim.Name; UserName = claim.Player.PrefferedName; Type = type; AccommodationRequestId = claim.AccommodationRequest_Id; }
public void SetNeighbor(NeighborType neighborType, Grid waypoint) { Grid neighbor = GetNeighbor(neighborType); if (neighbor == null || GetManhattanDistance(neighbor) > GetManhattanDistance(waypoint)) { _neighbor[(int)neighborType] = waypoint; } }
private bool RuleMatches(NeighborType neighbor, TileBase tile, TileBase referenceTile) { switch (neighbor) { case NeighborType.This: return(CheckNeighborType(tile, referenceTile)); case NeighborType.NotThis: return(!CheckNeighborType(tile, referenceTile)); } return(true); }
/// <summary> /// 获取两个拼图需要移动的偏移 /// </summary> /// <param name="A">当前选中的拼图的位置</param> /// <param name="B">需要移动的另一个拼图的位置</param> /// <param name="type">第二个拼图关于第一个拼图的位置</param> /// <returns></returns> Vector3 GetNeighborOffset(Vector3 A, Vector3 B, NeighborType type) { // 邻居在 Y 轴上的偏移 Vector3 Y = new Vector3(0, size.y, 0); // 邻居在 X 轴上的偏移 Vector3 X = new Vector3(size.x, 0, 0); // 邻居要移动到的位置 Vector3 pos = Vector3.zero; // 判断邻居的类型,计算偏移 switch (type) { // 邻居在上面 case NeighborType.Top: // 在 Y 轴上增加偏移 pos = A + Y; break; // 邻居在下面 case NeighborType.Bottom: // 在 Y 轴上减少偏移 pos = A - Y; break; // 邻居在左边 case NeighborType.Left: // 在 X 轴上减少偏移 pos = A - X; break; // 邻居在右边 case NeighborType.Right: // 在 X 轴上增加偏移 pos = A + X; break; // 不是邻居 default: break; } // 返回要移动的偏移 return(pos - B); }
/// <summary> /// 获取最近的邻居 /// </summary> /// <param name="go">要获取邻居的对象</param> /// <param name="type">邻居的类型</param> /// <returns>找到的邻居</returns> GameObject GetCloestNeighbor(GameObject go, out NeighborType type) { type = NeighborType.None; // 获取所有邻居 和邻居的类型 CheckNeighbros(go); for (int i = 0; i < neighborCache.Count; i++) { type = neighborTypes[i]; // 如果可以连接,返回 if (IsClosedToConnect(go.transform.localPosition, neighborCache[i].transform.localPosition, type)) { return(neighborCache[i]); } } return(null); }
public static bool FindNeighbor(Vector3Int cell, List <PlacedHexagon> hexagons, Grid grid, NeighborType neighborType, out PlacedHexagon neighbor) { var neighbors = GetNeighborsIndexed(cell, hexagons, grid); neighbor = new PlacedHexagon(null, Vector3Int.down); switch (neighborType) { case NeighborType.Top: if (!neighbors.ContainsKey(0)) { return(false); } neighbor = neighbors[0]; break; case NeighborType.Down: if (!neighbors.ContainsKey(3)) { return(false); } neighbor = neighbors[3]; break; case NeighborType.BottomLeft: if (!neighbors.ContainsKey(4)) { return(false); } neighbor = neighbors[4]; break; default: throw new ArgumentOutOfRangeException(nameof(neighborType), neighborType, null); } return(true); }
public static void FixNormals( Vector3[] first, int firstWidth, int firstHeight, Vector3[] second, int secondWidth, int secondHeight, NeighborType relation) { if (relation == NeighborType.TopBottom) { FixNormalEdge( first, firstWidth, (x) => firstHeight * (firstWidth - 1) + x, second, secondWidth, (x) => x ); } else if (relation == NeighborType.LeftRight) { FixNormalEdge( first, firstHeight, (y) => y * firstWidth + (firstWidth - 1), second, secondHeight, (y) => y * secondWidth ); } else { throw new System.ArgumentException("Unsupported NeighborType " + relation); } }
public void SetNeighborCell(NeighborType neighborType, Cell cell) { m_neighborCells[(int)neighborType] = cell; }
public void SetNeighborCube(NeighborType type, BackgroundCube cube) { neighborCubes[(int)type] = cube; }
public Grid GetNeighbor(NeighborType neighborType) { return(_neighbor[(int)neighborType]); }
public List <GridTile> FindNeighbors(GridTile[] grid, int gridX, int gridY, NeighborType type, int radius = 1) { List <GridTile> neighborsToReturn = new List <GridTile>(); for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { if (x == 0 && y == 0) { continue; //inside current node } int checkX = gridX + x; int checkY = gridY + y; //check if in bounds //need to figure out logic to replace get lengths if (checkX >= 0 && checkX < gridMap.width && checkY >= 0 && checkY < gridMap.height) { switch (type) { case NeighborType.Vertical: //same vertical plane if (x == 0) { neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); } break; case NeighborType.Horizontal: //same horizontal plane if (y == 0) { neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); } break; case NeighborType.Cross: //vertical and horizontal planes are both the same if (x == 0 || y == 0) { neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); } break; case NeighborType.Diagonal: //test if location has the same x and y compared to the base node if (Mathf.Abs(checkX - gridX) == Mathf.Abs(checkY - gridY)) { neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); } break; case NeighborType.All: //add all results neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); break; } } } } //return return(neighborsToReturn); }
Transform drawTile(Vector2 vector, Transform centerTile, NeighborType neighborType) { Vector3 v3 = new Vector3(); float xVal = centerTile.position.x; float zVal = centerTile.position.z; int virtualX = 0; int virtualZ = 0; switch (neighborType) { case NeighborType.leftTop: v3 = new Vector3(xVal - TileRadious, Perlin.Noise(vector.x / NoiseSeed, vector.y / NoiseSeed) * NoiseLevel, zVal + TileRadious); virtualX = centerTile.GetComponent <Tile>().VirtualX - 1; virtualZ = centerTile.GetComponent <Tile>().VirtualZ + 1; break; case NeighborType.midTop: v3 = new Vector3(xVal, Perlin.Noise(vector.x / NoiseSeed, vector.y / NoiseSeed) * NoiseLevel, TileRadious + zVal); virtualX = centerTile.GetComponent <Tile>().VirtualX; virtualZ = centerTile.GetComponent <Tile>().VirtualZ + 1; break; case NeighborType.rightTop: v3 = new Vector3(TileRadious + xVal, Perlin.Noise(vector.x / NoiseSeed, vector.y / NoiseSeed) * NoiseLevel, zVal + TileRadious); virtualX = centerTile.GetComponent <Tile>().VirtualX + 1; virtualZ = centerTile.GetComponent <Tile>().VirtualZ + 1; break; case NeighborType.right: v3 = new Vector3(TileRadious + xVal, Perlin.Noise(vector.x / NoiseSeed, vector.y / NoiseSeed) * NoiseLevel, zVal); virtualX = centerTile.GetComponent <Tile>().VirtualX + 1; virtualZ = centerTile.GetComponent <Tile>().VirtualZ; break; case NeighborType.rightBottom: v3 = new Vector3(TileRadious + xVal, Perlin.Noise(vector.x / NoiseSeed, vector.y / NoiseSeed) * NoiseLevel, zVal - TileRadious); virtualX = centerTile.GetComponent <Tile>().VirtualX + 1; virtualZ = centerTile.GetComponent <Tile>().VirtualZ - 1; break; case NeighborType.midBottom: v3 = new Vector3(xVal, Perlin.Noise(vector.x / NoiseSeed, vector.y / NoiseSeed) * NoiseLevel, zVal - TileRadious); virtualX = centerTile.GetComponent <Tile>().VirtualX; virtualZ = centerTile.GetComponent <Tile>().VirtualZ - 1; break; case NeighborType.leftBottom: v3 = new Vector3(xVal - TileRadious, Perlin.Noise(vector.x / NoiseSeed, vector.y / NoiseSeed) * NoiseLevel, zVal - TileRadious); virtualX = centerTile.GetComponent <Tile>().VirtualX - 1; virtualZ = centerTile.GetComponent <Tile>().VirtualZ - 1; break; case NeighborType.left: v3 = new Vector3(xVal - TileRadious, Perlin.Noise(vector.x / NoiseSeed, vector.y / NoiseSeed) * NoiseLevel, zVal); virtualX = centerTile.GetComponent <Tile>().VirtualX - 1; virtualZ = centerTile.GetComponent <Tile>().VirtualZ; break; } Transform tile = Instantiate(tilePrefeb, v3, Quaternion.Euler(0, 0, 0)); tile.GetComponent <Tile>().VirtualX = virtualX; tile.GetComponent <Tile>().VirtualZ = virtualZ; tile.GetComponent <Tile>().MoveAble = true; return(tile); }
public MapNeighborRelation(MapData firstMember, MapData secondMember, NeighborType neighborType) { this.firstMember = firstMember; this.secondMember = secondMember; this.neighborType = neighborType; }
public DisplayNeighborRelation(MapData firstMember, MapData secondMember, NeighborType neighborType) : base(firstMember, secondMember, neighborType) { }
public static List <TGridType> FindNeighbors <TGridType>(TGridType[,] grid, int gridX, int gridY, NeighborType type, int radius = 1) { List <TGridType> neighborsToReturn = new List <TGridType>(); for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { if (x == 0 && y == 0) { continue; //inside current node } int checkX = gridX + x; int checkY = gridY + y; Debug.Log(grid); //check if in bounds if (checkX >= 0 && checkX < grid.GetLength(0) && checkY >= 0 && checkY < grid.GetLength(1)) { switch (type) { case NeighborType.Vertical: //same vertical plane if (x == 0) { neighborsToReturn.Add(grid[checkX, checkY]); } break; case NeighborType.Horizontal: //same horizontal plane if (y == 0) { neighborsToReturn.Add(grid[checkX, checkY]); } break; case NeighborType.Cross: //vertical and horizontal planes are both the same if (x == 0 || y == 0) { neighborsToReturn.Add(grid[checkX, checkY]); } break; case NeighborType.Diagonal: //test if location has the same x and y compared to the base node if (Math.Abs(checkX - gridX) == Math.Abs(checkY - gridY)) { neighborsToReturn.Add(grid[checkX, checkY]); } break; case NeighborType.All: //add all results neighborsToReturn.Add(grid[checkX, checkY]); break; } } } } //return return(neighborsToReturn); }