// Use this for initialization void Start() { _buidlingsSubPanel = this.transform.GetChild(0); _resourcesSubPanel = this.transform.GetChild(1); //Instantiate buttons foreach (GameObject building in Builder.Buildings) { IBuildingCost buildCost = building.GetComponent <IBuildingCost>(); buildCost.Init(); GameObject go = Instantiate(ButtonTemplate, _buidlingsSubPanel); Button button = go.GetComponent <Button>(); button.onClick.AddListener(() => ClickBuild(building)); _buttons[buildCost] = button; IEnumerable <IResource> cost = buildCost.GetResources(); string costText = string.Join(Environment.NewLine, cost.Select((r) => r.ToString()).ToArray()); button.GetComponentInChildren <Text>().text = building.name + Environment.NewLine + costText; } //Instantiate resource texts for Builder foreach (IResource resource in Builder.Resources) { GameObject text = Instantiate(TextTemplate, _resourcesSubPanel); _texts.Add(resource, text.GetComponent <Text>()); } }
void OnLeftClick() { IBuildingCost cost = BuildingTemplate.GetComponent <IBuildingCost>(); if (_isLegitPlacement && Builder.CanPayBuilding(cost)) { // Pay building Builder.PayBuilding(cost); if (_playerObject) { //Online _playerObject.Cmd_InstantiateBuilding(PrefabIdHelper.GoIdBuilding[BuildingTemplate], Builder.Id, _buildingPreview.transform.position); } else { // Offline dev GameObject go = Instantiate(BuildingTemplate, _buildingPreview.transform.position, Quaternion.identity, _world.transform); Attackable building = go.GetComponent <Attackable>(); building.Allegiance = Builder.Allegiance; building.IsActive = true; } Destroy(_buildingPreview); Destroy(this.gameObject); } }
// Use this for initialization void Start() { //Should find cause to building being null 1/2 if (Building == null) { return; } _upgradesSubPanel = this.transform.GetChild(1); //Instantiate buttons foreach (GameObject upgrade in Building.Upgrades) { IBuildingCost buildCost = upgrade.GetComponent <IBuildingCost>(); buildCost.Init(); GameObject go = Instantiate(ButtonTemplate, _upgradesSubPanel); Button button = go.GetComponent <Button>(); button.onClick.AddListener(() => ClickUpgrade(upgrade)); _buttons[buildCost] = button; IEnumerable <IResource> cost = buildCost.GetResources(); string costText = string.Join(Environment.NewLine, cost.Select((r) => r.ToString()).ToArray()); button.GetComponentInChildren <Text>().text = upgrade.name + Environment.NewLine + costText; } }
void OnLeftClick() { IBuildingCost cost = BuildingTemplate.GetComponent <IBuildingCost>(); if (_isLegitPlacement && Builder.CanPayBuilding(cost)) { // Pay building Builder.PayBuilding(cost); BuildingTemplate.transform.position = _buildingPreview.transform.position; Destroy(_buildingPreview); GameObject newBuilding = Builder.InstantiateBuilding(BuildingTemplate); newBuilding.transform.SetParent(_world.transform); newBuilding.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); newBuilding.GetComponent <Building>().Creator = Builder; newBuilding.GetComponent <Building>().allegiance = Builder.allegiance; Destroy(_buildingPreview); Destroy(this.gameObject); } }
private void InstantiateButtons() { foreach (GameObject building in Builder.Buildings) { IBuildingCost buildCost = building.GetComponent <IBuildingCost>(); buildCost.Init(); GameObject go = Instantiate(ButtonTemplate, _buidlingsSubPanel); Button button = go.GetComponent <Button>(); button.onClick.AddListener(() => ClickBuild(building)); _buttons[buildCost] = button; IEnumerable <Resource> cost = buildCost.GetResources(); string costText = string.Join(Environment.NewLine, cost.Select((r) => r.ToString()).ToArray()); button.GetComponentInChildren <Text>().text = building.name + Environment.NewLine + costText; } }
public void PayBuilding(IBuildingCost buildingCost) { buildingCost.PurchaseWith(Resources); }
public bool CanPayBuilding(IBuildingCost buildingCost) { return(buildingCost.CanBePurchasedWith(Resources)); }