Пример #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";

            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";
        }
Пример #2
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)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";
        }
Пример #3
0
 public static void AddNewTower(UnitTower newTower)
 {
     if (instance.towerList.Contains(newTower)) return;
       instance.towerList.Add(newTower);
       instance.AddNewSampleTower(newTower);
       if (onAddNewTowerE != null) onAddNewTowerE(newTower);
 }
Пример #4
0
		public void _AddNewTower(UnitTower newTower){
			int count=buttonList.Count;
			buttonList.Add(buttonList[count-1].Clone("button"+(count), new Vector3(55, 0, 0)));
			buttonList[count].imageIcon.sprite=newTower.iconSprite;
			
			EventTrigger trigger = buttonList[count].rootObj.GetComponent<EventTrigger>();
			EventTrigger.Entry entry=SetupTriggerEntry();
			trigger.triggers.Add(entry);
		}
Пример #5
0
    // Use this for initialization
    void Start()
    {
        myRenderers = GetComponentsInChildren<MeshRenderer>();
        myRenderersColors = new List<Color>(myRenderers.Length);
        for (int i = 0; i < myRenderers.Length; i++)
        {
            myRenderersColors.Add(myRenderers[i].material.color);
        }

        unitTowerT = GetComponent<TDTK.UnitTower>();
    }
Пример #6
0
        public void BuildTower(Vector3 pos, UnitTower tower)
        {
            //pathfinding related code, only call if this platform is walkable;
            if(!walkable) return;

            NodeTD node=PathFinder.GetNearestNode(pos, nodeGraph);
            node.walkable=false;
            tower.SetPlatform(this, node);

            //if the node has been check before during CheckForBlock(), just use the altPath
            if(node==nextBuildNode){
                for(int i=0; i<subPathList.Count; i++){
                    if(subPathList[i].IsNodeInPath(node)) subPathList[i].SwitchToSubPath();
                }
                return;
            }

            for(int i=0; i<subPathList.Count; i++){
                if(subPathList[i].IsNodeInPath(node)) subPathList[i].SearchNewPath(nodeGraph);
            }
        }
Пример #7
0
 public static void OnTowerUpgraded(UnitTower tower)
 {
     if (onTowerUpgradedE != null) onTowerUpgradedE(tower);
 }
Пример #8
0
 public static void OnTowerSold(UnitTower tower)
 {
     if (onTowerSoldE != null) onTowerSoldE(tower);
 }
		public UnitTower CreateSampleTower(UnitTower towerPrefab){
			GameObject towerObj=(GameObject)Instantiate(towerPrefab.gameObject);
			
			towerObj.transform.parent=transform;
			if(towerObj.GetComponent<Collider>()!=null) Destroy(towerObj.GetComponent<Collider>());
			Utility.DestroyColliderRecursively(towerObj.transform);
			towerObj.SetActive(false);
			
			UnitTower towerInstance=towerObj.GetComponent<UnitTower>();
			towerInstance.SetAsSampleTower(towerPrefab);
			
			return towerInstance;
		}
		public static void PreBuildTower(UnitTower tower){
			PlatformTD platform=null;
			LayerMask mask=1<<LayerManager.LayerPlatform();
			Collider[] cols=Physics.OverlapSphere(tower.thisT.position, _gridSize, mask);
			if(cols.Length>0) platform=cols[0].gameObject.GetComponent<PlatformTD>();
			
			if(platform!=null){
				Vector3 buildPos=GetTilePos(platform.thisT, tower.thisT.position);
				tower.thisT.position=buildPos;
				tower.thisT.rotation=platform.thisT.rotation;
			}
			else Debug.Log("no platform found for pre-placed tower");
			
			tower.InitTower(instance.towerCount+=1);
		}
		//called when a tower building is initated in DragNDrop, use the sample tower as the model and set it in DragNDrop mode
		public static string BuildTowerDragNDrop(UnitTower tower){ return instance._BuildTowerDragNDrop(tower); }
Пример #12
0
        public void _SelectTower(UnitTower tower)
        {
            _ClearSelectedTower();

            selectedTower=tower;

            float range=tower.GetRange();

            Transform indicatorT=rangeIndicator;

            if(indicatorT!=null){
                indicatorT.parent=tower.thisT;
                indicatorT.position=tower.thisT.position;
                indicatorT.localScale=new Vector3(2*range, 1, 2*range);

                indicatorT.gameObject.SetActive(true);
            }
        }
Пример #13
0
 public static void SelectTower(UnitTower tower)
 {
     instance._SelectTower(tower);
 }
Пример #14
0
		public static void Building(UnitTower tower){ instance.StartCoroutine(instance._Building(tower)); }
Пример #15
0
        public bool UpdatePathMaps(UnitTower tow, bool destroy = false)
        {
            int index_z = (int)Mathf.Round(tow.Platform.transform.position.z - platform_min_z) / 2;
              int index_x = (int)Mathf.Round(tow.Platform.transform.position.x - platform_min_x) / 2;

              if (index_z < 0)
            return true;

              beerMap[index_x, index_z + 1] = destroy;  // false -> new tower build there

              // Check if the last paths are still walkable
              // exit if true
              if (lastPathOne.Count >= 0 && lastPathTwo.Count >= 0)
              {
            bool lastPathOK = true;

            for (int i = 0; i < lastPathOne.Count; i++)
            {
              if (beerMap[lastPathOne[i].X, lastPathOne[i].Y] == false)
            lastPathOK = false;
            }

            for (int i = 0; i < lastPathTwo.Count; i++)
            {
              if (beerMap[lastPathTwo[i].X, lastPathTwo[i].Y] == false)
            lastPathOK = false;
            }

            if (lastPathOK)
              return true;
              }

              if (!GenerateGlobalPaths())
              {
            beerMap[index_x, index_z + 1] = !destroy;
            GenerateGlobalPaths();
            return false;
              }

              // TODO position of this SpawnManager functions ?
              // Here becazse GenerateGlobalPaths is called at startup
              // Waves not generated at that time
              for (int i = 0; i < SpawnManager.instance.waveList.Count; i++)
              {
            SpawnManager.instance.waveGenerator.UpdateWavePath(SpawnManager.instance.waveList[i]);
              }

              UnitCreep[] creeps = ObjectPoolManager.FindObjectsOfType<UnitCreep>();
              foreach (UnitCreep creep in creeps)
              {
            // Problem with creeps not in the maze -> between start and normal platforms
            // or between normal platforms and goal
            // No new Path, if creep is already past the last tower row
            if (creep.transform.position.z > platform_min_z)
            {
              int c_z;
              if (creep.transform.position.z > platform_max_z)
            c_z = 34;
              else
            c_z = Mathf.CeilToInt(creep.transform.position.z - platform_min_z) / 2; // Changed to CeilToInt and not round

              int c_x = (int)Mathf.Round(creep.transform.position.x - platform_min_x) / 2;
              parameters = new PathFindingParameters(new Point(c_x, c_z), pt_goal, beerMap, nodeMap);
              pf = new PathFinder(parameters);

              PathTD pt = pf.FindPathTD(creep.transform, "CreepCustomPath");

              creep.SetNewPath(pt);
            }
              }

              //Object[] towers = GameObject.FindObjectsOfType(typeof(UnitTower));

              //Object[] platforms = GameObject.FindObjectsOfType(typeof(PlatformTD));

              //Object[] paths = GameObject.FindObjectsOfType(typeof(PathTD));

              //SpawnManager.ChangeDefaultPath(paths[0] as PathTD);
              return true;
        }
Пример #16
0
		public static bool TowerUseShootObjectT(UnitTower tower){
			_TowerType type=tower.type;
			if(type==_TowerType.AOE || type==_TowerType.Mine) return true;
			return false;
		}
Пример #17
0
		public static bool TowerUseShootObject(UnitTower tower){
			_TowerType type=tower.type;
			if(type==_TowerType.Turret) return true;
			return false;
		}
Пример #18
0
		public static bool TowerTargetHostile(UnitTower tower){
			_TowerType type=tower.type;
			if(type==_TowerType.Turret || type==_TowerType.AOE || type==_TowerType.Mine) return true;
			return false;
		}
Пример #19
0
		IEnumerator _Building(UnitTower tower){
			Slider bar=GetUnusedBuildingBar();
			Transform barT=bar.transform;
			while(tower!=null && tower.IsInConstruction()){
				bar.value=tower.GetBuildProgress();
				
				if(mainCam==null){
					mainCam=Camera.main;
					continue;
				}
				
				Vector3 screenPos = mainCam.WorldToScreenPoint(tower.thisT.position+new Vector3(0, 0, 0));
				barT.localPosition=(screenPos+new Vector3(0, -20, 0))/UI.GetScaleFactor();
				bar.gameObject.SetActive(true);
				
				yield return null;
			}
			bar.gameObject.SetActive(false);
		}
Пример #20
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";

              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";
        }
Пример #21
0
        public void _ClearSelectedTower()
        {
            selectedTower=null;

            rangeIndicatorObj.SetActive(false);
            rangeIndicator.parent=thisT;
        }
Пример #22
0
 //Call by inherited class UnitTower, caching inherited UnitTower instance to this instance
 public void SetSubClass(UnitTower unit)
 {
     unitT=unit;
     subClass=_UnitSubClass.Tower;
     gameObject.layer=LayerManager.LayerTower();
 }
		public static void ShowIndicator(UnitTower tower){
			instance.indicatorCursor.SetActive(true);
			instance.indicatorCursor.transform.position=tower.thisT.position;
			instance.indicatorCursor.transform.rotation=tower.thisT.rotation;
		}
Пример #24
0
 public void SetAsSampleTower(UnitTower tower)
 {
     isSampleTower=true;
     srcTower=tower;
     thisT.position=new Vector3(0, 9999, 0);
 }
		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;
		}
Пример #26
0
 public static void OnNewTower(UnitTower tower)
 {
     if (onNewTowerE != null) onNewTowerE(tower);
 }
		public void AddNewSampleTower(UnitTower newTower){
			UnitTower towerInstance=CreateSampleTower(newTower);
			sampleTowerList.Add(towerInstance);
		}
Пример #28
0
 public static void OnTowerConstructed(UnitTower tower)
 {
     if (onTowerConstructedE != null) onTowerConstructedE(tower);
 }
		public static UnitTower GetSampleTower(UnitTower tower){
			for(int i=0; i<instance.sampleTowerList.Count; i++){
				if(instance.sampleTowerList[i].prefabID==tower.prefabID) return instance.sampleTowerList[i];
			}
			return null;
		}
Пример #30
0
 public static void OnTowerConstructing(UnitTower tower)
 {
     if (onTowerConstructingE != null) onTowerConstructingE(tower);
 }