private RouteView CreateRoute(IRoute route, IEnumerable <TownView> towns) { var obj = Instantiate(routePrefab, routeRoot); if (obj == null) { throw new NullReferenceException(); } var view = obj.GetComponent <RouteView>(); var townViews = towns.ToList(); var fromTown = townViews.Single(t => t.townId == route.From.Id); var toTown = townViews.Single(t => t.townId == route.To.Id); view.Initialize(new RouteData(Guid.NewGuid(), fromTown.transform.position, toTown.transform.position, route.FlowPower())); view.OnSelected.Subscribe(_ => OnSelected(view)).AddTo(this); route.OnRecalculation .Where(_ => route.Id == _selectedRouteId.Value) .Subscribe(_ => view.UpdateFlowPower(route.FlowPower())) .AddTo(this); route.OnCargoChanged .Subscribe(items => view.UpdateCargoText(items)) .AddTo(this); return(view); }