Exemplo n.º 1
0
        //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)ObjectPoolManager.Spawn(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");
        }
Exemplo n.º 2
0
        public string _BuildTowerDragNDrop(UnitTower tower)
        {
            if (tower.type == _TowerType.Resource && !GameControl.IsGameStarted())
            {
                return("Cant Build Tower before spawn start");
            }

            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);
        }
Exemplo n.º 3
0
        public void _Show(UnitTower tower, bool showControl = false)
        {
            if (!tower.IsTower())
            {
                return;
            }

            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);
        }
Exemplo n.º 4
0
 public void OnHoverUpgradeButton()
 {
     OnHoverUpgradeSellButton(currentTower.GetCost());
 }