private void RepopulateRoute() { // Repopulate attached nodes. this.nodes.ForEach(n => Destroy(n.gameObject)); this.nodes.Clear(); float squaredLength = 0; Node previous = null; foreach (Node node in this.Route.Nodes.Skip(this.NodeIndex)) { NodeDisplay display = this.NewNodeDisplay(false, node); this.nodes.Add(display); if (previous == null && this.isActiveAndEnabled) { display.Select(true); } if (node.Type == NodeType.Teleport) { break; } if (previous != null) { squaredLength += (previous.Position - node.Position).sqrMagnitude; if (squaredLength > SquaredMaxRouteLength) { break; } } previous = node; } // Update route display. Vector3[] positions = this.nodes.Select(n => n.transform.position).ToArray(); this.RouteDisplay.positionCount = positions.Length; this.RouteDisplay.SetPositions(positions); // Update route display material. this.RouteDisplay.material = this.FollowMaterial; foreach (Node node in this.Route.Nodes.Take(this.NodeIndex).Reverse()) { if (node.Type == NodeType.HeartWall) { break; } if (node.Type == NodeType.Heart) { this.RouteDisplay.material = this.HeartMaterial; break; } } // Repopulate detached nodes. this.detachedNodes.ForEach(n => Destroy(n.gameObject)); this.detachedNodes = this.Route.DetachedNodes.Select(n => this.NewNodeDisplay(true, n)).ToList(); }
private void RepopulateRoute() { // Repopulate attached nodes. this.nodes.ForEach(n => Destroy(n.gameObject)); this.nodes.Clear(); float squaredLength = 0; Node previous = null; foreach (Node node in this.Route.Nodes.Skip(this.nodeIndex)) { if (squaredLength > SquaredMaxRouteLength) { break; } GameObject gameObject = (GameObject)Instantiate(this.NodePrefab, this.RouteDisplay.transform); NodeDisplay display = gameObject.GetComponent <NodeDisplay>(); display.Node = node; display.SetMesh(false); this.nodes.Add(display); if (node.Type == NodeType.Waypoint) { break; } if (previous == null) { display.Select(true); } else { squaredLength += (previous.Position - node.Position).sqrMagnitude; } previous = node; } // Update route display. this.RouteDisplay.numPositions = 0; // TODO: Find out if this is needed. Vector3[] positions = this.nodes.Select(n => n.transform.position).ToArray(); this.RouteDisplay.numPositions = positions.Length; this.RouteDisplay.SetPositions(positions); // Repopulate detached nodes. this.detachedNodes.ForEach(n => Destroy(n.gameObject)); this.detachedNodes.Clear(); foreach (Node node in this.Route.DetachedNodes) { GameObject gameObject = (GameObject)Instantiate(this.NodePrefab, this.RouteDisplay.transform); NodeDisplay display = gameObject.GetComponent <NodeDisplay>(); display.Node = node; display.SetMesh(true); this.detachedNodes.Add(display); } }