void OnConstructionComplete(UnitTower tower) { if (tower != currentTower) { return; } upgradeOption = currentTower.ReadyToBeUpgrade(); butSell.SetActive(true); txtSell.text = "" + currentTower.GetValueSell(); if (upgradeOption > 0) { butUpgrade.SetActive(true); txtUpgrade.text = "" + currentTower.GetCost(); if (upgradeOption > 1) { butUpgradeAlt1.SetActive(true); txtUpgradeAlt1.text = "" + currentTower.GetCost(1); } else { butUpgradeAlt1.SetActive(false); } } else { butUpgrade.SetActive(false); butUpgradeAlt1.SetActive(false); } }
public void _Show(UnitTower tower, bool showControl = false) { isOn = true; thisObj.SetActive(showControl); rscObj.SetActive(!showControl); currentTower = tower; if (showControl) { if (currentTower.IsInConstruction()) { StartCoroutine(WaitForConstruction()); floatingButtons.SetActive(false); butSell.SetActive(false); butUpgradeAlt1.SetActive(false); butUpgrade.SetActive(false); } else { floatingButtons.SetActive(true); butSell.SetActive(true); txtSell.text = "" + currentTower.GetValueSell(); upgradeOption = currentTower.ReadyToBeUpgrade(); if (upgradeOption > 0) { butUpgrade.SetActive(true); txtUpgrade.text = "" + currentTower.GetCost(); if (upgradeOption > 1) { butUpgradeAlt1.SetActive(true); txtUpgradeAlt1.text = "" + currentTower.GetCost(1); } else { butUpgradeAlt1.SetActive(false); } } else { butUpgrade.SetActive(false); butUpgradeAlt1.SetActive(false); } } } else { int cost = currentTower.GetCost(); txtRsc.text = cost.ToString(); } Update(); txtName.text = tower.unitName; txtDesp1.text = tower.GetDespStats(); txtDesp2.text = tower.GetDespGeneral(); thisObj.SetActive(isOn); }
public bool _BuildTowerDragNDrop(UnitTower tower) { if (tower.type == _TowerType.Resource && !GameControl.IsGameStarted()) { return(false); // "Cant Build Tower before spawn start"; } UnitTower sampleTower = GetSampleTower(tower); int cost = sampleTower.GetCost(); bool isSuffCost = ResourceManager.HasSufficientResource(cost); if (isSuffCost == true) { sampleTower.thisObj.SetActive(true); _ShowPlatform(true); GameControl.SelectTower(sampleTower); UnitTower towerInstance = sampleTower; towerInstance.StartCoroutine(towerInstance.DragNDropRoutine()); return(true); } return(false); //"Insufficient Resource"; }
//called when a tower building is initated in DragNDrop, use the sample tower as the model and set it in DragNDrop mode public string StartDragNDrop(int ID, int pointerID = -1) { UnitTower sampleTower = GetSampleTower(ID); if (sampleTower.type == _TowerType.Resource && !GameControl.IsGameStarted()) { return("Cant Build Tower before spawn start"); } IndicatorControl.SetDragNDropPhase(true); List <int> cost = sampleTower.GetCost(); int suffCost = ResourceManager.HasSufficientResource(cost); if (suffCost == -1) { sampleTower.thisT.position = new Vector3(9999, 9999, 9999); sampleTower.thisObj.SetActive(true); UnitTower towerInstance = sampleTower; towerInstance.StartCoroutine(towerInstance.DragNDropRoutine(pointerID)); return(""); } return("Insufficient Resource " + suffCost); }
//called by any external component to build tower, uses buildInfo public static string BuildTower(UnitTower tower) { if (buildInfo == null) { return("Select a Build Point First"); } UnitTower sampleTower = GetSampleTower(tower); //check if there are sufficient resource List <int> cost = sampleTower.GetCost(); int suffCost = ResourceManager.HasSufficientResource(cost); if (suffCost == -1) { ResourceManager.SpendResource(cost); GameObject towerObj = (GameObject)Instantiate(tower.gameObject, buildInfo.position, buildInfo.platform.thisT.rotation); UnitTower towerInstance = towerObj.GetComponent <UnitTower>(); towerInstance.InitTower(instance.towerCount += 1); towerInstance.Build(); //clear the build info and indicator for build manager ClearBuildPoint(); return(""); } return("Insufficient Resource"); }
public static string _BuildTower(UnitTower tower, BuildInfo bInfo) //called from UnitTower.DragNDropRoutine { if (bInfo == null) { if (!UseDragNDrop()) { return("Select a Build Point First"); } else { return("Invalid build position"); } } if (bInfo.status != _TileStatus.Available) { return("Invalid build position"); } //dont allow building of resource tower before game started if (tower.type == _TowerType.Resource && !GameControl.IsGameStarted()) { return("Cant Build Tower before spawn start"); } UnitTower sampleTower = GetSampleTower(tower); //check if there are sufficient resource List <int> cost = sampleTower.GetCost(); int suffCost = ResourceManager.HasSufficientResource(cost); if (suffCost == -1) { ResourceManager.SpendResource(cost); GameObject towerObj = (GameObject)Instantiate(tower.gameObject, bInfo.position, bInfo.platform.thisT.rotation); UnitTower towerInstance = towerObj.GetComponent <UnitTower>(); towerInstance.InitTower(instance.towerCount += 1); towerInstance.Build(); //if(bInfo.platform!=null) towerObj.transform.parent=bInfo.platform.transform; //register the tower to the platform if (bInfo.platform != null) { bInfo.platform.BuildTower(bInfo.position, towerInstance); } //clear the build info and indicator for build manager //ClearBuildIndicator(); IndicatorControl.ClearBuildTileIndicator(); return(""); } return("Insufficient Resource"); }
public static void BuildTower(UnitTower prefab, BuildPlatform platform, int nodeID, bool useRsc = true) { Debug.Log("BuildTower " + prefab); if (useRsc) { if (!RscManager.HasSufficientRsc(prefab.GetCost())) { Debug.Log("Insufficient resources"); return; } Debug.Log("Get cost " + prefab.GetCost()[0]); RscManager.SpendRsc(prefab.GetCost()); } NodeTD node = platform.GetNode(nodeID); GameObject obj = (GameObject)Instantiate(prefab.gameObject, node.pos, platform.GetRot() * Quaternion.Euler(-90, 0, 0)); UnitTower tower = obj.GetComponent <UnitTower>(); AddTower(tower, platform, nodeID); }
public void _Show(UnitTower tower, bool showControl = false) { isOn = true; thisObj.SetActive(showControl); floatingButtons.SetActive(showControl); controlObj.SetActive(showControl); rscObj.SetActive(!showControl); currentTower = tower; if (showControl) { if (currentTower.IsInConstruction()) { StartCoroutine(WaitForConstruction()); floatingButtons.SetActive(false); } upgradeOption = currentTower.ReadyToBeUpgrade(); if (upgradeOption > 0) { butUpgrade.SetActive(true); } else { butUpgrade.SetActive(false); } // deactivate the priority settings for support and electricity towers if (tower.type != _TowerType.Turret) { priorityObj.SetActive(false); } } else { List <int> cost = currentTower.GetCost(); for (int i = 0; i < rscObjList.Count; i++) { rscObjList[i].label.text = cost[i].ToString(); } } Update(); txtName.text = tower.unitName; txtLvl.text = "lvl " + tower.GetLevel(); txtDesp1.text = tower.GetDespStats(); txtDesp2.text = tower.GetDespGeneral(); thisObj.SetActive(isOn); }
void ShowTooltip(UnitTower tower) { lbTooltipName.text = tower.unitName; lbTooltipDesp.text = tower.GetDespGeneral(); List <int> cost = tower.GetCost(); for (int i = 0; i < tooltipRscItemList.Count; i++) { tooltipRscItemList[i].label.text = cost[i].ToString(); } tooltipCanvasG.alpha = 1; tooltipObj.SetActive(true); //UIMainControl.FadeIn(tooltipCanvasG, 0.0f, tooltipObj); }
public void OnHoverUpgradeButton(int index) { if (currentTower == null) { return; } if (index == 0 && butUpgrade1Canvas.alpha < 1) { return; } if (index == 1 && butUpgrade2Canvas.alpha < 1) { return; } UpdateResourcePanel(currentTower.GetCost(index)); rscPanelObj.SetActive(true); }
void UpdateDisplay() { lbTowerName.text = sTower.unitName; lbTowerDesp.text = sTower.desp; int upgradeType = sTower.GetUpgradeType(); //0-to next level, 1-to next tower int upgradeCount = sTower.GetUpgradeOptionCount(); for (int i = 0; i < upgradeButtons.Count; i++) { if (i < upgradeCount) { if (upgradeType == 0) { upgradeButtons[i].lbMain.text = sTower.GetUpgradeCost()[0].ToString("f0"); //"next level"; upgradeButtons[i].imgMain.enabled = false; upgradeButtons[i].imgAlt.enabled = true; } else if (upgradeType == 1) { UnitTower nextTower = sTower.GetUpgradeTower(i); upgradeButtons[i].lbMain.text = nextTower.GetCost()[0].ToString("f0"); upgradeButtons[i].imgMain.sprite = nextTower.icon; upgradeButtons[i].imgMain.enabled = true; upgradeButtons[i].imgAlt.enabled = false; } upgradeButtons[i].SetActive(true); } else { upgradeButtons[i].SetActive(false); } } buttonSell.lbMain.text = sTower.GetSellValue()[0].ToString("f0"); buttonSell.SetActive(!sTower.disableSelling); targetModeObj.SetActive(sTower.IsTurret() && allowTargetModeSwitch); UpdateTargetModeDisplay(); targetDirObj.SetActive(sTower.IsTurret() && sTower.UseDirectionalTargeting() && allowTargetDirSwitch); sliderTargetDir.value = sTower.targetingDir; }
public string _BuildTowerDragNDrop(UnitTower tower) { UnitTower sampleTower = GetSampleTower(tower); List <int> cost = sampleTower.GetCost(); int suffCost = ResourceManager.HasSufficientResource(cost); if (suffCost == -1) { sampleTower.thisObj.SetActive(true); GameControl.SelectTower(sampleTower); UnitTower towerInstance = sampleTower; towerInstance.StartCoroutine(towerInstance.DragNDropRoutine()); return(""); } return("Insufficient Resource " + suffCost); }
//called by any external component to build tower, uses buildInfo public static string BuildTower(UnitTower tower) { if (buildInfo == null) { return("Select a Build Point First"); } //dont allow building of resource tower before game started if (tower.type == _TowerType.Resource && !GameControl.IsGameStarted()) { return("Cant Build Tower before spawn start"); } UnitTower sampleTower = GetSampleTower(tower); //check if there are sufficient resource List <int> cost = sampleTower.GetCost(); int suffCost = ResourceManager.HasSufficientResource(cost); if (suffCost == -1) { ResourceManager.SpendResource(cost); GameObject towerObj = (GameObject)Instantiate(tower.gameObject, buildInfo.position, buildInfo.platform.thisT.rotation); UnitTower towerInstance = towerObj.GetComponent <UnitTower>(); towerInstance.InitTower(instance.towerCount += 1); towerInstance.Build(); //register the tower to the platform if (buildInfo.platform != null) { buildInfo.platform.BuildTower(buildInfo.position, towerInstance); } //clear the build info and indicator for build manager ClearBuildPoint(); return(""); } return("Insufficient Resource"); }
public void _Show(UnitTower tower, Vector3 pos, int pivotCorner = 2, Vector3 offset = default(Vector3)) { SetPivot(pivotCorner); labelName.text = tower.unitName; labelDesp.text = tower.desp; labelDesp.enabled = true; List <float> cost = tower.GetCost(); for (int i = 0; i < RscManager.GetResourceCount(); i++) { rscItemList[i].imgMain.sprite = RscManager.GetRscIcon(i); rscItemList[i].lbMain.text = cost[i].ToString("f0"); } minHeight = 120; rectT.position = pos + offset; canvasGroup.alpha = 1; thisObj.SetActive(true); }
public void _Show(UnitTower tower, bool showControl=false){ isOn=true; thisObj.SetActive(showControl); floatingButtons.SetActive(showControl); controlObj.SetActive(showControl); rscObj.SetActive(!showControl); currentTower=tower; if(showControl){ if(currentTower.IsInConstruction()){ StartCoroutine(WaitForConstruction()); floatingButtons.SetActive(false); } upgradeOption=currentTower.ReadyToBeUpgrade(); if(upgradeOption>0){ butUpgrade.SetActive(true); if(upgradeOption>1) butUpgradeAlt1.SetActive(true); else butUpgradeAlt1.SetActive(false); } else{ butUpgrade.SetActive(false); butUpgradeAlt1.SetActive(false); } txtTargetPriority.text=tower.targetPriority.ToString(); if(tower.directionalTargeting){ directionObj.SetActive(true); sliderDirection.value=tower.dirScanAngle; } else directionObj.SetActive(false); if(FPSControl.ActiveInScene()){ if(FPSControl.UseTowerWeapon() && currentTower.FPSWeaponID==-1) fpsButtonObj.SetActive(false); else fpsButtonObj.SetActive(true); } else fpsButtonObj.SetActive(false); } else{ List<int> cost=currentTower.GetCost(); for(int i=0; i<rscObjList.Count; i++){ rscObjList[i].label.text=cost[i].ToString(); } } Update(); txtName.text=tower.unitName; txtLvl.text="lvl"+tower.GetLevel(); txtDesp1.text=tower.GetDespStats(); txtDesp2.text=tower.GetDespGeneral(); thisObj.SetActive(isOn); }
public static void NewBuildable(UnitTower tower) { instance.AddBuildButton(instance.buildButtons.Count, tower.icon, tower.GetCost()[0].ToString("f0")); instance.buildableList = TowerManager.GetBuildableList(); }
public void _Show(UnitTower tower, bool showControl = false) { isOn = true; thisObj.SetActive(showControl); floatingButtons.SetActive(showControl); controlObj.SetActive(showControl); rscObj.SetActive(!showControl); currentTower = tower; if (showControl) { if (currentTower.IsInConstruction()) { StartCoroutine(WaitForConstruction()); floatingButtons.SetActive(false); } upgradeOption = currentTower.ReadyToBeUpgrade(); if (upgradeOption > 0) { butUpgrade.SetActive(true); if (upgradeOption > 1) { butUpgradeAlt1.SetActive(true); } else { butUpgradeAlt1.SetActive(false); } } else { butUpgrade.SetActive(false); butUpgradeAlt1.SetActive(false); } txtTargetPriority.text = tower.targetPriority.ToString(); if (tower.directionalTargeting) { directionObj.SetActive(true); sliderDirection.value = tower.dirScanAngle; } else { directionObj.SetActive(false); } if (FPSControl.ActiveInScene()) { if (FPSControl.UseTowerWeapon() && currentTower.FPSWeaponID == -1) { fpsButtonObj.SetActive(false); } else { fpsButtonObj.SetActive(true); } } else { fpsButtonObj.SetActive(false); } } else { List <int> cost = currentTower.GetCost(); for (int i = 0; i < rscObjList.Count; i++) { rscObjList[i].label.text = cost[i].ToString(); } } Update(); txtName.text = tower.unitName; txtLvl.text = "lvl" + tower.GetLevel(); txtDesp1.text = tower.GetDespStats(); txtDesp2.text = tower.GetDespGeneral(); thisObj.SetActive(isOn); }
public void OnHoverUpgradeButton() { OnHoverUpgradeSellButton(currentTower.GetCost()); }
//called by any external component to build tower, uses buildInfo public static string BuildTower(UnitTower tower) { if (buildInfo == null) { return("Select a Build Point First"); } UnitTower sampleTower = GetSampleTower(tower); /***/ // check if there's energy reciving tower if (tower.electricityNeeded && !tower.electricityReciever && !tower.electricityFacility) { LayerMask maskTarget = 1 << LayerManager.LayerTower(); Collider[] cols = Physics.OverlapSphere(buildInfo.position, 1000 /*GetRange()*/, maskTarget); if (cols.Length > 0) { tower.electicitySources.Clear(); // find all electric facility for (int i = 0; i < cols.Length; i++) { // if it's not electric reciever skip if (!cols[i].gameObject.GetComponent <UnitTower>().electricityReciever) { continue; } //float test = cols[i].gameObject.GetComponent<UnitTower>().GetRange(); //float test2 = Vector3.Distance(cols[i].gameObject.GetComponent<UnitTower>().transform.position, buildInfo.position); // if this tower is in range of electricityReciever if (Vector3.Distance(cols[i].gameObject.GetComponent <UnitTower>().transform.position, buildInfo.position) <= cols[i].gameObject.GetComponent <UnitTower>().GetRange()) { tower.electicitySources.Add(cols[i].gameObject.GetComponent <UnitTower>()); } } if (tower.electicitySources.Count == 0) { // set electricity source for tower weapon return("There is not enough electricity"); } } else { return("There is not enough electricity"); } } /***/ //check if there are sufficient resource List <int> cost = sampleTower.GetCost(); int suffCost = ResourceManager.HasSufficientResource(cost); if (suffCost == -1) { ResourceManager.SpendResource(cost); GameObject towerObj = (GameObject)Instantiate(tower.gameObject, buildInfo.position, buildInfo.platform.thisT.rotation); UnitTower towerInstance = towerObj.GetComponent <UnitTower>(); towerInstance.InitTower(instance.towerCount += 1, buildInfo.platform); towerInstance.Build(); // if new electricity reciver is placed search for all towers in it's range and add itself as electricity source if (tower.electricityReciever) { LayerMask maskTarget = 1 << LayerManager.LayerTower(); Collider[] cols = Physics.OverlapSphere(buildInfo.position, tower.GetRange(), maskTarget); if (cols.Length > 0) { UnitTower tmp_tow; for (int i = 0; i < cols.Length; i++) { tmp_tow = cols[i].gameObject.GetComponent <UnitTower>(); if (tmp_tow.electricityReciever || tmp_tow.electricityFacility) { continue; } tmp_tow.electicitySources.Add(towerInstance); } } } //clear the build info and indicator for build manager ClearBuildPoint(); return(""); } return("Insufficient Resource"); }
public void _Show(UnitTower tower, bool showControl=false) { isOn=true; thisObj.SetActive(showControl); floatingButtons.SetActive(showControl); controlObj.SetActive(showControl); rscObj.SetActive(!showControl); currentTower=tower; if(showControl){ if(currentTower.IsInConstruction()){ StartCoroutine(WaitForConstruction()); floatingButtons.SetActive(false); } upgradeOption=currentTower.ReadyToBeUpgrade(); if(upgradeOption>0){ butUpgrade.SetActive(true); } else{ butUpgrade.SetActive(false); } // deactivate the priority settings for support and electricity towers if (tower.type != _TowerType.Turret) { priorityObj.SetActive(false); } } else{ List<int> cost=currentTower.GetCost(); for(int i=0; i<rscObjList.Count; i++){ rscObjList[i].label.text=cost[i].ToString(); } } Update(); txtName.text=tower.unitName; txtLvl.text="lvl "+tower.GetLevel(); txtDesp1.text=tower.GetDespStats(); txtDesp2.text=tower.GetDespGeneral(); thisObj.SetActive(isOn); }