private void ScheduleShipConstruction(OnGoingShipConstruction onGoingShipConstruction) { if (!shipConstructions.ContainsKey(onGoingShipConstruction.constructor)) { IEnumerator enumerator = ConstructionCoroutine(onGoingShipConstruction); onGoingShipConstruction.enumerator = enumerator; shipConstructions.Add(onGoingShipConstruction.constructor, onGoingShipConstruction); StartCoroutine(enumerator); } }
public void ScheduleShipConstruction(ShipConstructor target, ShipConstruction shipConstruction) { ShipConstruction shipConstructionCopy = new ShipConstruction(shipConstruction.shipType, shipConstruction.constructionTime, shipConstruction.resourceCosts); //Makes a copy if (!shipConstructions.ContainsKey(target)) { OnGoingShipConstruction onGoingShipConstruction = new OnGoingShipConstruction(target); onGoingShipConstruction.shipConstructions.Add(shipConstructionCopy); IEnumerator enumerator = ConstructionCoroutine(onGoingShipConstruction); onGoingShipConstruction.enumerator = enumerator; shipConstructions.Add(target, onGoingShipConstruction); StartCoroutine(enumerator); } else { shipConstructions[target].shipConstructions.Add(shipConstructionCopy); } }
private IEnumerator ConstructionCoroutine(OnGoingShipConstruction onGoingShipConstruction) { while (onGoingShipConstruction.shipConstructions.Count != 0) { if (onGoingShipConstruction.constructor == null) { break; } if (onGoingShipConstruction.shipConstructions[0].constructionTime <= 0) { SpawnShipConstruction(onGoingShipConstruction.constructor, onGoingShipConstruction.shipConstructions[0]); onGoingShipConstruction.shipConstructions.RemoveAt(0); } else { onGoingShipConstruction.shipConstructions[0].constructionTime--; } yield return(new WaitForSeconds(1f)); } shipConstructions.Remove(onGoingShipConstruction.constructor); }