private void SetShipConstructionButtonClickCallback(ShipConstructor constructor, GameObject button, ShipConstruction shipConstruction) { button.GetComponent <Button>().onClick.AddListener(() => { constructor.BuildShip(shipConstruction.shipType); }); }
private void SpawnShipConstruction(ShipConstructor constructor, ShipConstruction shipConstruction) { Player player = PlayerDatabase.Instance.GetObjectPlayer(constructor.gameObject); Vector3 thisPosition = constructor.gameObject.transform.position; Vector3 spawnPosition = new Vector3(thisPosition.x + constructor.relativeConstructionSpawn.x, thisPosition.y + constructor.relativeConstructionSpawn.y, thisPosition.z + constructor.relativeConstructionSpawn.z); Spawner.Instance.SpawnShip(shipConstruction.shipType, player, spawnPosition, Quaternion.identity, true); }
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 void SpawnShips() { // make sure racers is at least 1 if (racerCount < 1) { racerCount = 1; } for (int i = 0; i < RaceSettings.racers; i++) { // if there arn't any spawns then we can't spawn the ship if (i > (RaceSettings.trackData.spawnPositions.Count - 1)) { Debug.LogError("Could not spawn ship! Reason: Not enough spawn locations."); return; } bool isAI = true; // racer index 0 is always player if (i == 0) { isAI = false; } // TODO: random ship for AI (once all ships are setup) GameObject newShip = new GameObject("SPAWNED SHIP"); ShipConstructor c = newShip.AddComponent <ShipConstructor>(); // position ship at spawn newShip.transform.position = RaceSettings.trackData.spawnPositions[i]; newShip.transform.rotation = RaceSettings.trackData.spawnRotations[i]; c.SpawnShip(isAI); } }
private void OnSelectionChange(List <GameObject> selectedGOs) { foreach (Transform child in constructionSection.transform) { GameObject.Destroy(child.gameObject); } if (selectedGOs.Count == 1) { ShipConstructor constructor = selectedGOs[0].GetComponent <ShipConstructor>(); if (constructor != null) { List <ShipConstruction> shipConstructions = constructor.ShipConstructions; int size = shipConstructions.Count; for (int i = 0; i < size; i++) { Ship ship = ShipFactory.getInstance().CreateShip(shipConstructions[i].shipType); float buttonPositionX = (constructionButtonPrefabOriginalPosX - 10) + (constructionButtonPrefabWidth * i) + 10; //10 It's the offset between buttons GameObject button = Instantiate(constructionButtonPrefab, constructionSection.transform); RectTransform rectTransform = button.GetComponent <RectTransform>(); rectTransform.anchoredPosition3D = new Vector3(buttonPositionX, rectTransform.localPosition.y, rectTransform.localPosition.z); //Debug.Log("( " + constructionButtonPrefabOriginalPosX + "- 10 )" + " + " + "( " + constructionButtonPrefabWidth + " * " + i + ") + 10 = " + buttonPositionX); button.GetComponentInChildren <RawImage>().texture = ship.shipIcon; button.SetActive(true); SetShipConstructionButtonClickCallback(constructor, button, shipConstructions[i]); } } else { StationConstructor stationConstructor = selectedGOs[0].GetComponent <StationConstructor>(); if (stationConstructor != null) { List <StationConstruction> stationConstructions = stationConstructor.stationConstructions; int size = stationConstructions.Count; for (int i = 0; i < size; i++) { Station station = StationFactory.getInstance().CreateStation(stationConstructions[i].stationType); float buttonPositionX = (constructionButtonPrefabOriginalPosX - 10) + (constructionButtonPrefabWidth * i) + 10; //10 It's the offset between buttons GameObject button = Instantiate(constructionButtonPrefab, constructionSection.transform); RectTransform rectTransform = button.GetComponent <RectTransform>(); rectTransform.anchoredPosition3D = new Vector3(buttonPositionX, rectTransform.localPosition.y, rectTransform.localPosition.z); //Debug.Log("( " + constructionButtonPrefabOriginalPosX + "- 10 )" + " + " + "( " + constructionButtonPrefabWidth + " * " + i + ") + 10 = " + buttonPositionX); button.GetComponentInChildren <RawImage>().texture = station.stationIcon; button.SetActive(true); //SetShipConstructionButtonClickCallback(constructor, button, stationConstructions[i]); SetStationConstructionButtonClickCallback(stationConstructor, button, stationConstructions[i]); } } } ResearchController researchController = selectedGOs[0].GetComponent <ResearchController>(); if (researchController != null) { List <ResearchTree> researchTrees = researchController.researchTrees; for (int i = 0, j = 0; i < researchTrees.Count; i++) { if (researchTrees[i].NextNode != null) { float buttonPositionX = (constructionButtonPrefabOriginalPosX - 10) + (constructionButtonPrefabWidth * j) + 10; //10 It's the offset between buttons GameObject button = Instantiate(constructionButtonPrefab, constructionSection.transform); RectTransform rectTransform = button.GetComponent <RectTransform>(); float yPosition = rectTransform.position.y - 550; rectTransform.anchoredPosition3D = new Vector3(buttonPositionX, yPosition, rectTransform.localPosition.z); //Debug.Log("( " + constructionButtonPrefabOriginalPosX + "- 10 )" + " + " + "( " + constructionButtonPrefabWidth + " * " + i + ") + 10 = " + buttonPositionX); button.GetComponentInChildren <RawImage>().texture = researchTrees[i].NextNode.research.texture; button.SetActive(true); //SetShipConstructionButtonClickCallback(constructor, button, stationConstructions[i]); SetResearchButtonCallback(researchController, researchTrees[i], button); j++; } } } } }
public OnGoingShipConstruction(long id) { shipContructorID = id; constructor = MapObject.FindByID(id).gameObject.GetComponent <ShipConstructor>(); shipConstructions = new List <ShipConstruction>(); }
public OnGoingShipConstruction(ShipConstructor constructor) { this.constructor = constructor; shipContructorID = constructor.gameObject.GetComponent <MapObject>().id; shipConstructions = new List <ShipConstruction>(); }