public override Train CreateTrain(TrainInfo element) { TrainElement locomotive = locomotivesPool.RealeseObject().GetComponent <TrainElement>(); locomotive.Position = element.headPosition.position; locomotive.Rotation = element.headPosition.rotateDegree; Train train = null; if (element.type == TypeTrain.Suburban) { train = new SuburbanTrain(locomotive, element.trainColor, element.fromArrive, element.turnsDelayCount); } else if (element.type == TypeTrain.Express) { train = new ExpressTrain(locomotive, element.trainColor, element.fromArrive, element.turnsDelayCount); } for (int i = 0; i < element.carriagePositions.Count; i++) { TrainElement carriage = carriagesPool.RealeseObject().GetComponent <TrainElement>(); train.AddCarriage(carriage, element.carriagePositions[i]); } return(train); }
// --------------- Manage of carriage --------------------- public void AddCarriage(TrainElement carriage, StateTrainElement state) { carriage.SetColor(trainColor); carriage.Position = state.position; carriage.Rotation = state.rotateDegree; head.AddCarriage(carriage); }
// -------------- Initialize ------------------ public Train(TrainElement head, Color color, TileSides from, int rate) { this.head = head; trainColor = color; fromArrive = from; isEnable = true; clockPerTurn = rate; head.SetColor(color); }
public virtual void DisconnectBackCarriage() { if (backTrainElement == null) { return; } backTrainElement.DisconnectFrontCarriage(); backTrainElement = null; }
// --------------------- Connection ---------------------- public virtual void AddCarriage(TrainElement carriage) { if (backTrainElement != null) { backTrainElement.AddCarriage(carriage); } else { ConnectBackCarriage(carriage); } }
public SuburbanTrain(TrainElement head, Color color, TileSides from, int rate) : base(head, color, from, rate) { }
protected override void ConnectFrontCarriage(TrainElement carriage) { frontTrainElement = carriage; }
public virtual void ConnectBackCarriage(TrainElement carriage) { backTrainElement = carriage; carriage.ConnectFrontCarriage(this); }
protected virtual void ConnectFrontCarriage(TrainElement carriage) { }
public ExpressTrain(TrainElement head, Color color, TileSides from, int rate) : base(head, color, from, rate) { }