public AbstractSquare LocateNeighbor(Vector3 p, Direction d) { Vector3 offset = new Vector3(0, 0, 0); switch (d) { case Direction.Up: offset = new Vector3(0, 0, -1); break; case Direction.Down: offset = new Vector3(0, 0, 1); break; case Direction.North: offset = new Vector3(0, -1, 0); break; case Direction.South: offset = new Vector3(0, 1, 0); break; case Direction.East: offset = new Vector3(1, 0, 0); break; case Direction.West: offset = new Vector3(-1, 0, 0); break; case Direction.Northeast: offset = new Vector3(1, -1, 0); break; case Direction.Northwest: offset = new Vector3(-1, -1, 0); break; case Direction.Southeast: offset = new Vector3(1, 1, 0); break; case Direction.Southwest: offset = new Vector3(-1, 1, 0); break; } Vector3 neighborPosition = p + offset; if (neighborPosition.x >= 0 && neighborPosition.x <= map.GetUpperBound(0) && neighborPosition.y >= 0 && neighborPosition.y <= map.GetUpperBound(1) && neighborPosition.z >= 0 && neighborPosition.z <= map.GetUpperBound(2)) { return(map[p.x, p.y, p.z]); } else { return(parentMap.GetSquare(this, neighborPosition)); } }
public AbstractSquare LocateNeighbor(Vector3 p, Direction d) { Vector3 offset = new Vector3(0, 0, 0); switch (d) { case Direction.Up: offset = new Vector3(0, 0, -1); break; case Direction.Down: offset = new Vector3(0, 0, 1); break; case Direction.North: offset = new Vector3(0, -1, 0); break; case Direction.South: offset = new Vector3(0, 1, 0); break; case Direction.East: offset = new Vector3(1, 0, 0); break; case Direction.West: offset = new Vector3(-1, 0, 0); break; case Direction.NorthEast: offset = new Vector3(1, -1, 0); break; case Direction.NorthWest: offset = new Vector3(-1, -1, 0); break; case Direction.SouthEast: offset = new Vector3(1, 1, 0); break; case Direction.SouthWest: offset = new Vector3(-1, 1, 0); break; } Vector3 neighborPosition = p + offset; if (neighborPosition.X >= 0 && neighborPosition.X <= map.GetUpperBound(0) && neighborPosition.Y >= 0 && neighborPosition.Y <= map.GetUpperBound(1) && neighborPosition.Z >= 0 && neighborPosition.Z <= map.GetUpperBound(2)) { return(map[p.X, p.Y, p.Z]); } else { return(ParentMap.GetSquare(this, neighborPosition)); } }