/// <summary> /// Creates grey boxes at each point the player has clicked before, but /// the player pawn hasn't caught up to yet. /// </summary> /// <param name="tilemap">The map</param> /// <returns>The line segments to render</returns> IEnumerable <SegmentProperties> GenerateCheckpointLines(IMap tilemap) { var segments = new List <SegmentProperties>(); foreach (var c in commandCheckpoints) { var worldSpace = GridSpaceConversion.GetWorldSpaceFromLogical(c, tilemap); var square = LineElements.SquareSelectionSegments(worldSpace, Color.grey); segments.AddRange(square); } return(segments); }
public void LogicalTick() { if (currentMotionPath.Any()) { animator.SetBool("IsMoving", true); } else { animator.SetBool("IsMoving", false); } while (currentMotionPath.Any()) { var nextPosLogical = currentMotionPath.Dequeue(); if (nextPosLogical == LogicalLocation) { continue; } else { var nextPosWorld = GridSpaceConversion.GetWorldSpaceFromLogical( nextPosLogical, tilePlacedComponent.Tilemap); float angle = 180.0f; if (nextPosLogical.x > LogicalLocation.x) { angle = 90.0f; } else if (nextPosLogical.x < LogicalLocation.x) { angle = -90.0f; } else if (nextPosLogical.y > LogicalLocation.y) { angle = 0.0f; } logicalLocation = nextPosLogical; gameObject.transform.localPosition = nextPosWorld; gameObject.transform.localRotation = Quaternion.AngleAxis(angle, Vector3.back) * Quaternion.Euler(-90.0f, 0.0f, 0.0f); break; } } }
/// <summary> /// Creates line segments from a logical-coordinate-based path /// </summary> /// <param name="path">The logical path</param> /// <param name="tilemap">The map where the path originated from</param> /// <returns>A list of segments that can be drawn</returns> public static IEnumerable <SegmentProperties> SegmentsFromPath(LogicalPath path, IMap tilemap) { var points = new List <Vector3>(); foreach (var cell in path.Path) { var world = GridSpaceConversion.GetWorldSpaceFromLogical(cell, tilemap); points.Add(world); } if (points.Count <= 1) { return(new List <SegmentProperties>()); } Vector3 facingDir = Vector3.back; const float width = 0.08f; Color color = Color.white; var segments = new SegmentProperties[points.Count - 1]; Vector3 lastPoint = points.First(); int segIndex = 0; for (int n = 1; n < points.Count; ++n) { var point = points[n]; segments[segIndex++] = new SegmentProperties { Start = lastPoint, End = point, FacingDirection = facingDir, Style = SegmentStyle.Dashed, Width = width, Color = color }; lastPoint = point; } return(segments); }
/// <summary> /// Creates a box around where the user has their mouse targeted. /// The appears might vary depending on the validity of that location /// </summary> /// <param name="tilemap">The map</param> /// <returns>The line segments to render</returns> IEnumerable <SegmentProperties> GenerateSelectionBoxLines(IMap tilemap) { if (lastMouseLocationOffGrid) { return(new List <SegmentProperties>()); } List <SegmentProperties> segments = new List <SegmentProperties>(); var selectedCellWorldSpace = GridSpaceConversion.GetWorldSpaceFromLogical(lastMouseLocation, tilemap); Color boxColor = Color.white; if (!pendingTargetActive) { boxColor = Color.red; segments.AddRange(LineElements.XSegments(selectedCellWorldSpace, boxColor)); } segments.AddRange(LineElements.SquareSelectionSegments(selectedCellWorldSpace, boxColor)); return(segments); }