public PathTrail(PathTrail copyFrom) { PathFromTo = new List <PathTile>(copyFrom.PathFromTo); PathBreak = new LinkedList <PathTile>(copyFrom.PathBreak); if (PathFromTo.Count != 0) { PathFrom = copyFrom.PathFromTo[0]; PathTo = copyFrom.PathFromTo[copyFrom.PathFromTo.Count - 1]; } }
public void extendPath(PathTrail extP) { if (this.PathTo.Tile == extP.PathFrom.Tile && extP.PathFromTo.Count != 0) //check if the paths line up { extP.PathFrom.PathFrom = this.PathTo.PathFrom; int length = extP.PathFromTo.Count; for (int i = 1; i < length; i++) { this.PathFromTo.Add(extP.PathFromTo[i]); } this.PathTo = extP.PathTo; } else { Debug.Log("Path to Path Extension connections don't match."); Debug.Log(this.PathTo.Tile + " " + extP.PathFrom.Tile); } }
public static void PreviewPath(PlayerUnit player, GameTile fromTile, GameTile toTile) { Clear(); tempTrail.Clear(); tempTrail = GetPathTrail(player, (player.PathTrail != null ? player.PathTrail.PathTo.Tile.PathTile : fromTile.PathTile), toTile.PathTile); if (tempTrail != null) { if (player.PathTrail != null) { previewTrail = new PathTrail(player.PathTrail); previewTrail.extendPath(tempTrail); } else { previewTrail = tempTrail; } previewTrail.CalculateTurns(player); previewTrail.ShowPath(); } else { tempTrail = new PathTrail(); } }
IEnumerator TravelPath() { Vector3 a, b, c = pathTrail.PathFromTo[0].Tile.Position; transform.localPosition = c; yield return(LookAt(pathTrail.PathFromTo[1].Tile.Position)); float t = Time.deltaTime * travelSpeed; bool last = false; bool hasBreak = pathTrail.PathBreak.Count != 0; int moveCost = 0; PathTile pathBreak; if (hasBreak) { pathBreak = pathTrail.PathBreak.First.Value; pathTrail.PathBreak.RemoveFirst(); } else { pathBreak = pathTrail.PathTo; } pathBreak.Tile.Highlight(true, Color.green); int stopIndex = pathTrail.getBreakIndex(pathBreak); for (int i = 1; i <= stopIndex; i++) { if (!last) { FogOfWar.Instance.ClearFog(pathTrail.PathFromTo[i].Tile, 3); tileUI.UpdateUI(pathTrail.PathFromTo[i].Tile); a = c; b = pathTrail.PathFromTo[i - 1].Tile.Position; c = (b + pathTrail.PathFromTo[i].Tile.Position) * 0.5f; moveCost += pathTrail.PathFromTo[i].MoveCost; } else { a = c; b = (c + pathBreak.Tile.Position) * 0.5f; c = pathBreak.Tile.Position; } if (stopIndex == i && !last) { i--; last = true; } for (; t < 1f; t += Time.deltaTime * travelSpeed) { transform.localPosition = Bezier.GetPoint(a, b, c, t); Vector3 d = Bezier.GetDerivative(a, b, c, t); d.y = 0f; if (d != Vector3.zero) { transform.localRotation = Quaternion.LookRotation(d); } yield return(null); } t -= 1f; } position = pathBreak.Tile.Position; transform.position = position; tile = pathBreak.Tile; destination = null; moving = false; FogOfWar.Instance.ClearFog(tile, 3); if (pathTrail != null) { pathTrail.ClearUsedTiles(this); PathTrail.CalculateTurns(this); if (pathTrail.PathFromTo.Count <= 1) { pathTrail = null; } } }