private static bool IsDirectionPreserved(IAsciiMap map, IAsciiField field, PathDirection direction) { var nextField = map.GetFieldInDirection(direction, field); return(nextField != null && IsPassableCharacter(nextField.Character)); }
public PathPoint(int x, int y, string dir) { this.X = x; this.Y = y; switch (dir.ToUpper()) { case "W": this.Dir = PathDirection.West; break; case "E": this.Dir = PathDirection.East; break; case "S": this.Dir = PathDirection.South; break; case "N": default: this.Dir = PathDirection.North; break; } }
private IEnumerator RotateAICar(PathDirection mergePathDir, float waitTimeForRotate) { Vector3 objectRotation = Vector3.zero; yield return(new WaitForSeconds(waitTimeForRotate)); if (mergePathDir == PathDirection.Top) { objectRotation = new Vector3(gameObject.transform.rotation.eulerAngles.x, gameObject.transform.rotation.eulerAngles.y, gameObject.transform.rotation.eulerAngles.z); } if (mergePathDir == PathDirection.Left) { objectRotation = new Vector3(gameObject.transform.rotation.eulerAngles.x, gameObject.transform.rotation.eulerAngles.y + 90, gameObject.transform.rotation.eulerAngles.z); } if (mergePathDir == PathDirection.Right) { objectRotation = new Vector3(gameObject.transform.rotation.eulerAngles.x, gameObject.transform.rotation.eulerAngles.y - 90, gameObject.transform.rotation.eulerAngles.z); } gameObject.transform.rotation = Quaternion.Euler(objectRotation); }
private AIMovePoint GetNextPoint(int currentPointIndex, ref PathDirection pathDirection) { int num = currentPointIndex + ((pathDirection == PathDirection.Forwards) ? 1 : (-1)); if (num < 0) { if (LoopMode == Mode.Loop) { num = Points.Count - 1; } else { num = 1; pathDirection = PathDirection.Forwards; } } else if (num >= Points.Count) { if (LoopMode == Mode.Loop) { num = 0; } else { num = Points.Count - 2; pathDirection = PathDirection.Backwards; } } return(Points[num]); }
//인접 타일 체크 private bool CheckChildNode(Vector3Int curPos, PathDirection direction, out Vector3Int childNodePos) { switch (direction) { case PathDirection.Up: curPos.z += 1; break; case PathDirection.Down: curPos.z -= 1; break; case PathDirection.Left: curPos.x -= 1; break; case PathDirection.Right: curPos.x += 1; break; } childNodePos = curPos; if (curPos.x < 0 || curPos.x >= tileList.Count || curPos.z < 0 || curPos.z >= tileList[0].Count) { return(false); } return(tileList[curPos.x][curPos.z].CheckRoadTile()); // 검사한 노드가 갈수 있는 노드인지 체크해서 리턴 }
private Vector3 GetPathRotationAccordingToDir() { Vector3 rotationVec3 = Vector3.zero; float rotationY = currentPath.transform.rotation.eulerAngles.y; if (ChoosePathDirection() == PathDirection.Top) { currentDir = PathDirection.Top; rotationVec3 = currentPath.transform.rotation.eulerAngles; } else if (ChoosePathDirection() == PathDirection.Left) { currentDir = PathDirection.Left; rotationVec3 = transform.rotation.eulerAngles; rotationVec3.y = rotationY - 90; } else if (ChoosePathDirection() == PathDirection.Right) { currentDir = PathDirection.Right; rotationVec3 = transform.rotation.eulerAngles; rotationVec3.y = rotationY + 90; } PrepareMergePathForSpawn(); return(rotationVec3); }
public IAsciiField GetFieldInDirection(PathDirection pathDirection, IAsciiField lastValidField) { IAsciiField field = null; switch (pathDirection) { case PathDirection.East: field = GetField(lastValidField.Row, lastValidField.Column + 1); break; case PathDirection.North: field = GetField(lastValidField.Row - 1, lastValidField.Column); break; case PathDirection.South: field = GetField(lastValidField.Row + 1, lastValidField.Column); break; case PathDirection.West: field = GetField(lastValidField.Row, lastValidField.Column - 1); break; default: break; } return(field); }
private static bool IsDirectionValid(IAsciiMap map, IAsciiField field, PathDirection direction) { var nextField = map.GetFieldInDirection(direction, field); return(nextField != null && !nextField.AlreadyVisited && IsPassableCharacter(nextField.Character)); }
public Transform GetNextPathNode() { if (pathType == PathType.Circuit) { if (pathDirection == PathDirection.Clockwise) { if (currentPathIndex == nodes.Length - 1) { currentPathIndex = 0; } else { currentPathIndex++; } } else { if (currentPathIndex == 0) { currentPathIndex = nodes.Length - 1; } else { currentPathIndex--; } } } else if (pathType == PathType.Linear) { if (pathDirection == PathDirection.Clockwise) { if (currentPathIndex == nodes.Length - 1) { pathDirection = PathDirection.Counterclockwise; currentPathIndex--; } else { currentPathIndex++; } } else { if (currentPathIndex == 0) { pathDirection = PathDirection.Clockwise; currentPathIndex++; } else { currentPathIndex--; } } } return(nodes[currentPathIndex]); }
public ArcToPathCommand(float rx, float ry, float xAxisRotate, PathArcSize largeArc, PathDirection sweep, float x, float y) { Rx = rx; Ry = ry; XAxisRotate = xAxisRotate; LargeArc = largeArc; Sweep = sweep; X = x; Y = y; }
/// <summary> /// Interact with the target. /// </summary> /// <param name="character">The character that wants to interactact with the target.</param> public void Interact(GameObject character) { if (m_EnableOnInteract) { enabled = true; } else if (m_ChangeDirectionsOnInteract) { // If the platform is already moving and is interacted with then it should change directions. m_Direction = m_Direction == PathDirection.Forward ? PathDirection.Backwards : PathDirection.Forward; } }
public static AM.SweepDirection ToSweepDirection(this PathDirection pathDirection) { switch (pathDirection) { default: case PathDirection.Clockwise: return(AM.SweepDirection.Clockwise); case PathDirection.CounterClockwise: return(AM.SweepDirection.CounterClockwise); } }
public AIMovePoint GetNextPoint(AIMovePoint current, ref PathDirection pathDirection) { int num = 0; foreach (AIMovePoint point in Points) { if (point == current) { return(GetNextPoint(num, ref pathDirection)); } num++; } return(null); }
private void OnTriggerEnter(Collider other) { if (other.transform.tag == "mergePathTag") { PathDirection mergePathDir = other.GetComponent <MergePath>().mergePathDir; if (mergePathDir == PathDirection.Left) { StartCoroutine(RotateAICar(mergePathDir, 0.5f)); } if (mergePathDir == PathDirection.Right) { StartCoroutine(RotateAICar(mergePathDir, 1f)); } } }
public static void FindPath(IAsciiMap map, IAsciiField currentField, PathDirection currentDirection) { map.AddPathCharacter(currentField); var directionToMoveNext = ScanArea(map, currentField, currentDirection); IAsciiField nextField = map.GetFieldInDirection(directionToMoveNext, currentField); if (IsAsciiEndCharacter(nextField.Character)) { map.AddPathCharacter(nextField); } else { FindPath(map, nextField, directionToMoveNext); } }
/// <summary> /// Updates the moving platform to move to the next waypoint. /// </summary> protected void UpdateWaypoint() { // The state should always reflect the state of the next waypoint. If moving in reverse then the state has to be updated before the index changes. if (m_Direction == PathDirection.Backwards) { UpdateState(); } m_PreviousWaypoint = m_NextWaypoint; m_NextWaypointEvent = null; switch (m_MovementType) { case PathMovementType.Target: if (m_NextWaypoint != m_TargetWaypoint) { GoToNextWaypoint(); } break; case PathMovementType.Loop: GoToNextWaypoint(); break; case PathMovementType.PingPong: if (m_Direction == PathDirection.Backwards) { if (m_NextWaypoint == 0) { m_Direction = PathDirection.Forward; } } else { if (m_NextWaypoint == (m_Waypoints.Length - 1)) { m_Direction = PathDirection.Backwards; } } GoToNextWaypoint(); break; } // The state should always reflect the state of the next waypoint. If moving in reverse then the state has to be updated before the index changes. if (m_Direction == PathDirection.Forward) { UpdateState(); } m_NextWaypointEvent = null; }
public void ChangeDirection() { switch (pathDirection) { case PathDirection.Forward: pathDirection = PathDirection.Backward; break; case PathDirection.Backward: pathDirection = PathDirection.Forward; break; default: break; } }
public static PathDirection ConnectionDirection(this PathDirection input, PathDirection other) { var dir = PathDirection.None; input.GetFlags().ForEach(direction => { switch (direction) { case PathDirection.None: dir = PathDirection.None; break; case PathDirection.Bottom: if (other.HasFlag(PathDirection.Top)) { dir = PathDirection.Bottom; } break; case PathDirection.Left: if (other.HasFlag(PathDirection.Right)) { dir = PathDirection.Left; } break; case PathDirection.Right: if (other.HasFlag(PathDirection.Left)) { dir = PathDirection.Right; } break; case PathDirection.Top: if (other.HasFlag(PathDirection.Bottom)) { dir = PathDirection.Top; } break; default: dir = PathDirection.None; break; } }); return(dir); }
private static PathDirection ChoosePathDirection() { if (currentDir == PathDirection.Left) { return(PathDirection.Right); } else if (currentDir == PathDirection.Right) { return(PathDirection.Left); } else { PathDirection[] validDirections = new[] { PathDirection.Top, PathDirection.Left }; PathDirection selectedDirection = validDirections[Random.Range(0, validDirections.Length)]; return(selectedDirection); } }
private void ChooseAndSpawnSidePlace(PathDirection dir) { //GameObject choosenPlace = sidePlaces[Random.Range(0, sidePlaces.Length)]; Transform choosenPlace = placeContainer.transform.GetChild(Random.Range(0, placeContainer.transform.childCount)); choosenPlace.rotation = Quaternion.Euler(Vector3.zero); if (dir == PathDirection.Top) { //instantiatedPlace = Instantiate(choosenPlace, // gameObject.transform.GetChild(0).transform.GetChild(2).transform.position, // Quaternion.identity); choosenPlace.position = gameObject.transform.GetChild(0).transform.GetChild(2).transform.position; choosenPlace.rotation = Quaternion.identity; } else if (dir == PathDirection.Left) { Vector3 objectRotation = new Vector3(choosenPlace.transform.rotation.eulerAngles.x, choosenPlace.transform.rotation.eulerAngles.y + 90, choosenPlace.transform.rotation.eulerAngles.z); //instantiatedPlace = Instantiate(choosenPlace, // gameObject.transform.GetChild(0).transform.GetChild(2).transform.position, // Quaternion.Euler(objectRotation)); choosenPlace.position = gameObject.transform.GetChild(0).transform.GetChild(2).transform.position; choosenPlace.rotation = Quaternion.Euler(objectRotation); } else if (dir == PathDirection.Right) { Vector3 objectRotation = new Vector3(choosenPlace.transform.rotation.eulerAngles.x, choosenPlace.transform.rotation.eulerAngles.y - 90, choosenPlace.transform.rotation.eulerAngles.z); //instantiatedPlace = Instantiate(choosenPlace, // gameObject.transform.GetChild(0).transform.GetChild(0).transform.position, // Quaternion.Euler(objectRotation)); choosenPlace.position = gameObject.transform.GetChild(0).transform.GetChild(0).transform.position; choosenPlace.rotation = Quaternion.Euler(objectRotation); } //(instantiatedPlace as GameObject).transform.parent = gameObject.transform; choosenPlace.gameObject.SetActive(true); }
public void SetupCorridor(Room room, IntRange length, IntRange roomWidth, IntRange roomHeight, int columns, int rows, bool firstCorridor) { direction = (PathDirection)Random.Range(0, 4); PathDirection oppositeDirection = (PathDirection)(((int)room.enteringCorridor + 2) % 4); if (!firstCorridor && direction == oppositeDirection) { int directionInt = (int)direction; directionInt++; directionInt = directionInt % 4; direction = (PathDirection)directionInt; } corridorLength = length.Random; int maxLength = length.m_Max; switch (direction) { case PathDirection.North: startXPos = Random.Range(room.xPos, room.xPos + room.roomWidth - 1); startZPos = room.zPos + room.roomHeight; maxLength = rows - startZPos - roomHeight.m_Min; break; case PathDirection.East: startXPos = room.xPos + room.roomWidth; startZPos = Random.Range(room.zPos, room.zPos + room.roomHeight - 1); maxLength = columns - startXPos - roomWidth.m_Min; break; case PathDirection.South: startXPos = Random.Range(room.xPos, room.xPos + room.roomWidth); startZPos = room.zPos; maxLength = startZPos - roomHeight.m_Min; break; case PathDirection.West: startXPos = room.xPos; startZPos = Random.Range(room.zPos, room.zPos + room.roomHeight); maxLength = startXPos - roomWidth.m_Min; break; } corridorLength = Mathf.Clamp(corridorLength, 1, maxLength); }
public void SetupRoom(IntRange widthRange, IntRange heightRange, int columns, int rows, Corridor corridor) { enteringCorridor = corridor.direction; roomWidth = widthRange.Random; roomHeight = heightRange.Random; switch (corridor.direction) { case PathDirection.North: roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionZ); zPos = corridor.EndPositionZ; xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX); xPos = Mathf.Clamp(xPos, 0, columns - roomWidth); break; case PathDirection.East: roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndPositionX); xPos = corridor.EndPositionX; zPos = Random.Range(corridor.EndPositionZ - roomHeight + 1, corridor.EndPositionZ); zPos = Mathf.Clamp(zPos, 0, rows - roomHeight); break; case PathDirection.South: roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndPositionZ); zPos = corridor.EndPositionZ - roomHeight + 1; xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX); xPos = Mathf.Clamp(xPos, 0, columns - roomWidth); break; case PathDirection.West: roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndPositionX); xPos = corridor.EndPositionX - roomWidth + 1; zPos = Random.Range(corridor.EndPositionZ - roomHeight + 1, corridor.EndPositionZ); zPos = Mathf.Clamp(zPos, 0, rows - roomHeight); break; } }
public void DirectionChecker(PathDirection checkingDirection) { Vector3 playerPos = Player.instance.CurBody.transform.position; if (checkingDirection == PathDirection.Z_DIR) { if (playerPos.z > transform.position.z) { enterVector = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1); exitVector = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1); } else if (playerPos.z < transform.position.z) { enterVector = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1); exitVector = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1); } } else if (checkingDirection == PathDirection.X_DIR) { if (playerPos.x > transform.position.x) { enterVector = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z); exitVector = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z); } else if (playerPos.x < transform.position.x) { enterVector = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z); exitVector = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z); } } enterVector = new Vector3(enterVector.x, 1.0f, enterVector.z); exitVector = new Vector3(exitVector.x, 1.0f, exitVector.z); if (Player.instance.Navigator.CalculatePath(enterVector).status == NavMeshPathStatus.PathPartial && Player.instance.Navigator.CalculatePath(exitVector).status == NavMeshPathStatus.PathComplete) { Vector3 tempVector = enterVector; enterVector = exitVector; exitVector = tempVector; } }
private bool hasValidPathDirection(PlayerPiece piece, PathDirection direction1, PathDirection direction2) { int rowIndex = piece.currentCell.rowIndex; int columnIndex = piece.currentCell.colIndex; PathDirection currentDirection = direction1; int nbMaxDirChanges = direction1 == direction2 ? 0 : 1; int nbDirectionChanges = 0; for (int i = 0;; ++i) { if (i >= piece.moveCells.Count) { return(true); } int previousRowIndex = rowIndex; int previousColIndex = columnIndex; bool rowMoveOk = updateRowIndexForPathDirection(ref rowIndex, currentDirection); bool colMoveOk = updateColumnIndexForPathDirection(ref columnIndex, currentDirection); if (!rowMoveOk || !colMoveOk) { if (nbDirectionChanges == nbMaxDirChanges) { return(false); } rowIndex = previousRowIndex; columnIndex = previousColIndex; currentDirection = currentDirection == direction1 ? direction2 : direction1; if (i != 0) { ++nbDirectionChanges; } } else { bool cellSelected = hasSelectedCellAt(rowIndex, columnIndex, piece); if (!cellSelected) { return(false); } } } }
public bool ContinuesInDirection(Location location, PathDirection direction) { int index = spline.splineNodesArray.IndexOf(location.Node); if (index < 0) { return(false); } bool result = false; if (direction == PathDirection.Forward) //if we're going forward then see if the next is below the count { result = ((index + 1) < spline.splineNodesArray.Count); } else //if we're going backwards see if the prev index is greater than 0 { result = ((index - 1) >= 0); } return(result); }
private static bool updateIndexForPathDirection(ref int index, int maxIndex, PathDirection direction, PathDirection minDirection, PathDirection maxDirection) { if (direction == minDirection) { if (index == 0) { return(false); } --index; return(true); } if (direction == maxDirection) { if (index == maxIndex) { return(false); } ++index; return(true); } return(true); }
public static Vector2Int?GetNeighbour(this PathCell cell, PathDirection direction, PathCell[,] cells) { Vector2Int neighbour; switch (direction) { case PathDirection.LEFT: neighbour = cell.LeftNeighbour; break; case PathDirection.UP: neighbour = cell.TopNeighbour; break; case PathDirection.RIGHT: neighbour = cell.RightNeighbour; break; case PathDirection.DOWN: neighbour = cell.BottomNeighour; break; default: return(null); } var isInBounds = cells.Contains(neighbour); var visited = isInBounds ? cells[neighbour.x, neighbour.y].Visited : false; if (isInBounds && !visited) { return(neighbour); } else { return(null); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { mouseDownPos = Input.mousePosition; pathDirection = PathDirection.begin; } if (Input.GetMouseButtonUp(0)) { pathDirection = PathDirection.idle; if (Input.mousePosition.y > mouseDownPos.y) { Debug.Log("Drag up!"); pathDirection = PathDirection.up; } else if (Input.mousePosition.y < mouseDownPos.y) { Debug.Log("Drag down!"); pathDirection = PathDirection.down; swipeValue = Mathf.Sign(Input.mousePosition.y - mouseDownPos.y); } if (Input.mousePosition.x > mouseDownPos.x) { Debug.Log("Drag right!"); pathDirection = PathDirection.right; } else if (Input.mousePosition.x < mouseDownPos.x) { Debug.Log("Drag left!"); pathDirection = PathDirection.left; swipeValue = Mathf.Sign(Input.mousePosition.x - mouseDownPos.x); } } }
public bool GetNeighbor(Location start, PathDirection direction, List <string> filterTypes, out Location neighbor) { //this is now handled by Paths neighbor = null; /* * if (!ContinuesInDirection (start, direction)) { //if there are no more paths in that direction we're done * return false; * } * //no need to check index because ContinuesInDirection verified it * int startIndex = spline.splineNodesArray.IndexOf (start.Node); * int currentIndex = startIndex; * int increment = 1; * if (direction == PathDirection.Backwards) { //reverse direction * increment = -1; * } * //add the first increment * currentIndex += increment; * * bool keepLooking = true; * bool foundNeighbor = false; * while (keepLooking) { * if (currentIndex < spline.splineNodesArray.Count && currentIndex >= 0) { * Location currentLocation = spline.splineNodesArray [currentIndex].GetComponent <Location> (); * if (!filterTypes.Contains (currentLocation.State.Type)) { * neighbor = currentLocation; * keepLooking = false; * foundNeighbor = true; * } * } else { * keepLooking = false; * } * currentIndex += increment; * } * return foundNeighbor; */ return(false); }
public DirectionCost(PathDirection dir, int cost, Point point) { this.direction = dir; this.cost = cost; this.point = point; }
public void InitPath() { // Depth-First Search algorithm int totalNodes = SideLength * SideLength; Node[] stack = new Node[totalNodes]; Node current = stack[0] = new Node( 0, 0 ); int stackSize = 1; bool[,] visited = new bool[SideLength, SideLength]; visited[0, 0] = true; while ( true ) { PathDirection[] choices = new PathDirection[4]; int count = 0; if ( current.X > 0 && !visited[current.X - 1, current.Y] ) choices[count++] = PathDirection.Left; if ( current.Y > 0 && !visited[current.X, current.Y - 1] ) choices[count++] = PathDirection.Up; if ( current.X < SideLength - 1 && !visited[current.X + 1, current.Y] ) choices[count++] = PathDirection.Right; if ( current.Y < SideLength - 1 && !visited[current.X, current.Y + 1] ) choices[count++] = PathDirection.Down; if ( count > 0 ) { PathDirection dir = choices[Utility.Random( count )]; switch ( dir ) { case PathDirection.Left: current = new Node( current.X - 1, current.Y ); break; case PathDirection.Up: current = new Node( current.X, current.Y - 1 ); break; case PathDirection.Right: current = new Node( current.X + 1, current.Y ); break; default: current = new Node( current.X, current.Y + 1 ); break; } stack[stackSize++] = current; if ( current.X == SideLength - 1 && current.Y == SideLength - 1 ) break; visited[current.X, current.Y] = true; } else { current = stack[--stackSize - 1]; } } m_Path = new Node[stackSize]; for ( int i = 0; i < stackSize; i++ ) { m_Path[i] = stack[i]; } if ( m_User != null ) { m_User.CloseGump( typeof( GameGump ) ); m_User = null; } }
public PathSelectedEventArgs(PathDirection direction) { this.Direction = direction; }
public void SetTargetEnabled(PathDirection direction, bool isEnabled) { targets[direction].IsEnabled = isEnabled; }
protected void onPathSelected(PathDirection direction) { var handler = PathSelected; if (handler != null) handler(this, new PathSelectedEventArgs(direction)); }
public DirectionCost(PathDirection dir, int cost, Point point) { this.direction = dir; this.cost = cost; this.point = point; }
private void createArrow(PathDirection direction, Point center, int radius, double rotationAngle) { var arrow = new ArrowCursorTarget(canvas, center, radius); arrow.Shape.LayoutTransform = new RotateTransform(rotationAngle, center.X, center.Y); arrow.CursorSelect += () => onPathSelected(direction); targets.Add(direction, arrow); }