示例#1
0
        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;
                platform.BuildTower(buildPos, tower);
            }
            else
            {
                Debug.Log("no platform found for pre-placed tower");
            }

            tower.InitTower(instance.towerCount += 1);
        }
		void Awake(){
			instance = (PlatformTD)target;
			
			GetTower();
			
			//EditorUtility.SetDirty(instance);
		}
示例#3
0
        void Awake()
        {
            instance = (PlatformTD)target;

            GetTower();

            //EditorUtility.SetDirty(instance);
        }
示例#4
0
 public void RemoveIDFromList(int ID)
 {
     for (int i = 0; i < serializedObject.targetObjects.Length; i++)
     {
         PlatformTD platformInstance = (PlatformTD)serializedObject.targetObjects[i];
         platformInstance.unavailableTowerIDList.Remove(ID);
     }
 }
示例#5
0
 public void EnableAllTowerOnAll()
 {
     for (int i = 0; i < serializedObject.targetObjects.Length; i++)
     {
         PlatformTD platformInstance = (PlatformTD)serializedObject.targetObjects[i];
         platformInstance.unavailableTowerIDList = new List <int>();
     }
 }
示例#6
0
		public List<Vector3> altPath=new List<Vector3>(); //for checking if there's any block
		
		public void Init(PlatformTD platform){
			parentPlatform=platform;
			
			startN=PathFinder.GetNearestNode(connectStart.position, platform.GetNodeGraph());
			endN=PathFinder.GetNearestNode(connectEnd.position, platform.GetNodeGraph());
			
			path.Add((connectStart.position+connectEnd.position)/2);
			
			SearchNewPath(platform.GetNodeGraph());
		}
示例#7
0
 public void AddIDToList(int ID)
 {
     for (int i = 0; i < serializedObject.targetObjects.Length; i++)
     {
         PlatformTD platformInstance = (PlatformTD)serializedObject.targetObjects[i];
         if (!platformInstance.unavailableTowerIDList.Contains(ID))
         {
             platformInstance.unavailableTowerIDList.Add(ID);
         }
     }
 }
示例#8
0
        public List <Vector3> altPath = new List <Vector3>();     //for checking if there's any block

        public void Init(PlatformTD platform)
        {
            parentPlatform = platform;

            startN = PathFinder.GetNearestNode(connectStart.position, platform.GetNodeGraph());
            endN   = PathFinder.GetNearestNode(connectEnd.position, platform.GetNodeGraph());

            path.Add((connectStart.position + connectEnd.position) / 2);

            SearchNewPath(platform.GetNodeGraph());
        }
示例#9
0
        public void DisableAllTowerOnAll()
        {
            List <int> allIDList = new List <int>();

            for (int i = 0; i < towerDB.towerList.Count; i++)
            {
                allIDList.Add(towerDB.towerList[i].prefabID);
            }

            for (int i = 0; i < serializedObject.targetObjects.Length; i++)
            {
                PlatformTD platformInstance = (PlatformTD)serializedObject.targetObjects[i];
                platformInstance.unavailableTowerIDList = new List <int>(allIDList);
            }
        }
示例#10
0
        public void InitTower(int ID, PlatformTD currentPlatform)
        {
            Init();

            instanceID = ID;
            platform   = currentPlatform;

            value = stats[currentActiveStat].cost;

            int rscCount = ResourceManager.GetResourceCount();

            for (int i = 0; i < stats.Count; i++)
            {
                UnitStat stat = stats[i];
                stat.slow.effectID = instanceID;
                stat.dot.effectID  = instanceID;
                stat.buff.effectID = instanceID;
                if (stat.rscGain.Count != rscCount)
                {
                    while (stat.rscGain.Count < rscCount)
                    {
                        stat.rscGain.Add(0);
                    }
                    while (stat.rscGain.Count > rscCount)
                    {
                        stat.rscGain.RemoveAt(stat.rscGain.Count - 1);
                    }
                }
            }

            if (type == _TowerType.Turret)
            {
                StartCoroutine(ScanForTargetRoutine());
                StartCoroutine(TurretRoutine());
            }
            if (type == _TowerType.AOE)
            {
                StartCoroutine(AOETowerRoutine());
            }
            if (type == _TowerType.Support)
            {
                StartCoroutine(SupportRoutine());
            }
            if (type == _TowerType.Electric)
            {
                // TODO: Coroutine for electric towers here
            }
        }
示例#11
0
        public Vector3 _GetTilePos(PlatformTD platform, Vector3 hitPos)
        {
            Vector3 v = hitPos - platform.thisT.position;               //get the vector from platform origin to hit point

            //transform the vector to the platform local space, so we know the (x, y)
            v = Quaternion.Euler(0, -platform.thisT.rotation.eulerAngles.y, 0) * v;

            //check the size of the platform for odd/even columen and then set the offset in corresponding axis
            float osX = platform.size.x % 2 == 0 ? gridSize / 2 : 0;
            float osZ = platform.size.y % 2 == 0 ? gridSize / 2 : 0;

            //calculate the x and z position (this is the relative position in platform local space to the platform origin)
            float x = Mathf.Round((osX + v.x) / gridSize) * gridSize - osX;
            float z = Mathf.Round((osZ + v.z) / gridSize) * gridSize - osZ;

            //transform the calculated position to world space
            return(platform.thisT.position + platform.thisT.TransformDirection(new Vector3(x, 0, z)));
        }
示例#12
0
        private bool UnavailableListSharesValue(int ID)
        {
            if (!serializedObject.isEditingMultipleObjects)
            {
                return(true);
            }

            PlatformTD platformInstance = (PlatformTD)serializedObject.targetObjects[0];
            bool       flag             = platformInstance.unavailableTowerIDList.Contains(ID);

            for (int i = 1; i < serializedObject.targetObjects.Length; i++)
            {
                platformInstance = (PlatformTD)serializedObject.targetObjects[i];
                if (flag != platformInstance.unavailableTowerIDList.Contains(ID))
                {
                    return(false);
                }
            }

            return(true);
        }
		void Awake(){
			instance = (PlatformTD)target;
			
			GetTower();
		}
示例#14
0
        public static NodeTD[] GenerateNode(PlatformTD platform, float heightOffset)
        {
            if (instance == null)
            {
                Init();
            }

            Transform platformT = platform.thisT;

            float gridSize = BuildManager.GetGridSize();

            float scaleX = platform.thisT.localScale.x;
            float scaleZ = platform.thisT.localScale.z;

            int countX = (int)(scaleX / gridSize);
            int countZ = (int)(scaleZ / gridSize);


            float x = -scaleX / 2 / scaleX;
            float z = -scaleZ / 2 / scaleZ;


            Vector3 point = platformT.TransformPoint(new Vector3(x, 0, z));

            thisT.position = point;
            thisT.rotation = platformT.rotation;

            thisT.position = thisT.TransformPoint(new Vector3(gridSize / 2, heightOffset, gridSize / 2));

            NodeTD[] nodeGraph = new NodeTD[countZ * countX];

            int counter = 0;

            for (int i = 0; i < countZ; i++)
            {
                for (int j = 0; j < countX; j++)
                {
                    Vector3 pos = thisT.position;
                    pos.y = pos.y + 5000;

                    LayerMask  mask = 1 << TDTK.GetLayerTower();
                    RaycastHit hit1;
                    if (Physics.Raycast(pos, Vector3.down, out hit1, Mathf.Infinity, ~mask))
                    {
                        nodeGraph[counter] = new NodeTD(new Vector3(pos.x, hit1.point.y + heightOffset, pos.z), counter);
                    }
                    else
                    {
                        nodeGraph[counter]          = new NodeTD(pos, counter);
                        nodeGraph[counter].walkable = false;
                    }

                    counter += 1;

                    thisT.position = thisT.TransformPoint(new Vector3(gridSize, 0, 0));
                }
                thisT.position = thisT.TransformPoint(new Vector3(-(countX) * gridSize, 0, gridSize));
            }

            thisT.position = Vector3.zero;
            thisT.rotation = Quaternion.identity;


            counter = 0;
            foreach (NodeTD cNode in nodeGraph)
            {
                if (cNode.walkable)
                {
                    //check if there's anything within the point
                    LayerMask mask = 1 << TDTK.GetLayerPlatform();
                    mask |= 1 << TDTK.GetLayerTower();
                    if (TDTK.GetLayerTerrain() >= 0)
                    {
                        mask |= 1 << TDTK.GetLayerTerrain();
                    }
                    Collider[] cols = Physics.OverlapSphere(cNode.pos, gridSize * 0.45f, ~mask);
                    if (cols.Length > 0)
                    {
                        cNode.walkable = false;
                        counter       += 1;
                    }
                }
            }


            float neighbourDistance = 0;
            float neighbourRange;

            if (instance.connectDiagonalNeighbour)
            {
                neighbourRange = gridSize * 1.5f;
            }
            else
            {
                neighbourRange = gridSize * 1.1f;
            }

            counter = 0;
            //assign the neighouring  node for each node in the grid
            foreach (NodeTD currentNode in nodeGraph)
            {
                //only if that node is walkable
                if (currentNode.walkable)
                {
                    //create an empty array
                    List <NodeTD> neighbourNodeList = new List <NodeTD>();
                    List <float>  neighbourCostList = new List <float>();

                    NodeTD[] neighbour = new NodeTD[8];
                    int      id        = currentNode.ID;

                    if (id > countX - 1 && id < countX * countZ - countX)
                    {
                        //print("middle rows");
                        if (id != countX)
                        {
                            neighbour[0] = nodeGraph[id - countX - 1];
                        }
                        neighbour[1] = nodeGraph[id - countX];
                        neighbour[2] = nodeGraph[id - countX + 1];
                        neighbour[3] = nodeGraph[id - 1];
                        neighbour[4] = nodeGraph[id + 1];
                        neighbour[5] = nodeGraph[id + countX - 1];
                        neighbour[6] = nodeGraph[id + countX];
                        if (id != countX * countZ - countX - 1)
                        {
                            neighbour[7] = nodeGraph[id + countX + 1];
                        }
                    }
                    else if (id <= countX - 1)
                    {
                        //print("first row");
                        if (id != 0)
                        {
                            neighbour[0] = nodeGraph[id - 1];
                        }
                        if (nodeGraph.Length > id + 1)
                        {
                            neighbour[1] = nodeGraph[id + 1];
                        }
                        if (countZ > 0)
                        {
                            if (nodeGraph.Length > id + countX - 1)
                            {
                                neighbour[2] = nodeGraph[id + countX - 1];
                            }
                            if (nodeGraph.Length > id + countX)
                            {
                                neighbour[3] = nodeGraph[id + countX];
                            }
                            if (nodeGraph.Length > id + countX + 1)
                            {
                                neighbour[4] = nodeGraph[id + countX + 1];
                            }
                        }
                    }
                    else if (id >= countX * countZ - countX)
                    {
                        //print("last row");
                        neighbour[0] = nodeGraph[id - 1];
                        if (id != countX * countZ - 1)
                        {
                            neighbour[1] = nodeGraph[id + 1];
                        }
                        if (id != countX * (countZ - 1))
                        {
                            neighbour[2] = nodeGraph[id - countX - 1];
                        }
                        neighbour[3] = nodeGraph[id - countX];
                        neighbour[4] = nodeGraph[id - countX + 1];
                    }



                    //scan through all the node in the grid
                    foreach (NodeTD node in neighbour)
                    {
                        //if this the node is not currentNode
                        if (node != null && node.walkable)
                        {
                            //if this node is within neighbour node range
                            neighbourDistance = GetHorizontalDistance(currentNode.pos, node.pos);
                            if (neighbourDistance < neighbourRange)
                            {
                                //if nothing's in the way between these two
                                LayerMask mask = 1 << TDTK.GetLayerPlatform();
                                mask |= 1 << TDTK.GetLayerTower();
                                if (!Physics.Linecast(currentNode.pos, node.pos, ~mask))
                                {
                                    //if the slop is not too steep
                                    //if(Mathf.Abs(GetSlope(currentNode.pos, node.pos))<=maxSlope){
                                    //add to list
                                    //if(!node.walkable) Debug.Log("error");
                                    neighbourNodeList.Add(node);
                                    neighbourCostList.Add(neighbourDistance);
                                    //}//else print("too steep");
                                }                //else print("something's in the way");
                            }                    //else print("out of range "+neighbourDistance);
                        }                        //else print("unwalkable");
                    }

                    //set the list as the node neighbours array
                    currentNode.SetNeighbour(neighbourNodeList, neighbourCostList);

                    //if(neighbourNodeList.Count==0)
                    //Debug.Log("no heighbour. node number "+counter+"  "+neighbourNodeList.Count);
                }

                counter += 1;
            }

            return(nodeGraph);
        }
示例#15
0
 public void SetPlatform(PlatformTD platform, NodeTD node)
 {
     occupiedPlatform = platform;
     occupiedNode     = node;
 }
示例#16
0
 public static Vector3 GetTilePos(PlatformTD platform, Vector3 hitPos)
 {
     return(instance._GetTilePos(platform, hitPos));
 }
示例#17
0
        void Awake()
        {
            instance = (PlatformTD)target;

            GetTower();
        }
示例#18
0
 public void SetPlatform(PlatformTD platform, NodeTD node)
 {
     occupiedPlatform=platform;
     occupiedNode=node;
 }
示例#19
0
 void Awake()
 {
     instance = (PlatformTD)target;
     LoadDB();
 }
示例#20
0
		public static NodeTD[] GenerateNode(PlatformTD platform, float heightOffset){
			if(instance==null) Init();
			
			Transform platformT=platform.thisT;
			
			float gridSize=BuildManager.GetGridSize();
			
			float scaleX=platform.thisT.localScale.x;
			float scaleZ=platform.thisT.localScale.z;
			
			int countX=(int)(scaleX/gridSize);
			int countZ=(int)(scaleZ/gridSize);
			
			
			float x=-scaleX/2/scaleX;
			float z=-scaleZ/2/scaleZ;
			
			
			Vector3 point=platformT.TransformPoint(new Vector3(x, 0, z));
			
			thisT.position=point;
			thisT.rotation=platformT.rotation;
			
			thisT.position=thisT.TransformPoint(new Vector3(gridSize/2, heightOffset, gridSize/2));
			
			NodeTD[] nodeGraph=new NodeTD[countZ*countX];
			
			int counter=0;
			for(int i=0; i<countZ; i++){
				for(int j=0; j<countX; j++){
					Vector3 pos=thisT.position;
					pos.y=pos.y+5000;
					
					LayerMask mask=1<<LayerManager.LayerTower();
					RaycastHit hit1;
					if(Physics.Raycast(pos, Vector3.down, out hit1, Mathf.Infinity, ~mask)) {
						nodeGraph[counter]=new NodeTD(new Vector3(pos.x, hit1.point.y+heightOffset, pos.z), counter);
					}
					else{
						nodeGraph[counter]=new NodeTD(pos, counter);
						nodeGraph[counter].walkable=false;
					}
					
					counter+=1;
					
					thisT.position=thisT.TransformPoint(new Vector3(gridSize, 0, 0));
				}
				thisT.position=thisT.TransformPoint(new Vector3(-(countX)*gridSize, 0, gridSize));
			}
			
			thisT.position=Vector3.zero;
			thisT.rotation=Quaternion.identity;
			
			
			counter=0;
			foreach(NodeTD cNode in nodeGraph){
				if(cNode.walkable){
					//check if there's anything within the point
					LayerMask mask=1<<LayerManager.LayerPlatform();
					mask|=1<<LayerManager.LayerTower();
					if(LayerManager.LayerTerrain()>=0) mask|=1<<LayerManager.LayerTerrain();
					Collider[] cols=Physics.OverlapSphere(cNode.pos, gridSize*0.45f, ~mask);
					if(cols.Length>0){
						cNode.walkable=false;
						counter+=1;
					}
				}
			}
			
			
			float neighbourDistance=0;
			float neighbourRange;
			if(instance.connectDiagonalNeighbour) neighbourRange=gridSize*1.5f;
			else neighbourRange=gridSize*1.1f;
			
			counter=0;
			//assign the neighouring  node for each node in the grid
			foreach(NodeTD currentNode in nodeGraph){
				//only if that node is walkable
				if(currentNode.walkable){
				
					//create an empty array
					List<NodeTD> neighbourNodeList=new List<NodeTD>();
					List<float> neighbourCostList=new List<float>();
					
					NodeTD[] neighbour=new NodeTD[8];
					int id=currentNode.ID;
					
					if(id>countX-1 && id<countX*countZ-countX){
						//print("middle rows");
						if(id!=countX) neighbour[0]=nodeGraph[id-countX-1];
						neighbour[1]=nodeGraph[id-countX];
						neighbour[2]=nodeGraph[id-countX+1];
						neighbour[3]=nodeGraph[id-1];
						neighbour[4]=nodeGraph[id+1];
						neighbour[5]=nodeGraph[id+countX-1];
						neighbour[6]=nodeGraph[id+countX];
						if(id!=countX*countZ-countX-1)neighbour[7]=nodeGraph[id+countX+1];
					}
					else if(id<=countX-1){
						//print("first row");
						if(id!=0) neighbour[0]=nodeGraph[id-1];
						if(nodeGraph.Length>id+1) neighbour[1]=nodeGraph[id+1];
						if(countZ>0){
							if(nodeGraph.Length>id+countX-1)	neighbour[2]=nodeGraph[id+countX-1];
							if(nodeGraph.Length>id+countX)	neighbour[3]=nodeGraph[id+countX];
							if(nodeGraph.Length>id+countX+1)	neighbour[4]=nodeGraph[id+countX+1];
						}
					}
					else if(id>=countX*countZ-countX){
						//print("last row");
						neighbour[0]=nodeGraph[id-1];
						if(id!=countX*countZ-1) neighbour[1]=nodeGraph[id+1];
						if(id!=countX*(countZ-1))neighbour[2]=nodeGraph[id-countX-1];
						neighbour[3]=nodeGraph[id-countX];
						neighbour[4]=nodeGraph[id-countX+1];
					}
					


					//scan through all the node in the grid
					foreach(NodeTD node in neighbour){
						//if this the node is not currentNode
						if(node!=null && node.walkable){
							//if this node is within neighbour node range
							neighbourDistance=GetHorizontalDistance(currentNode.pos, node.pos);
							if(neighbourDistance<neighbourRange){
								//if nothing's in the way between these two
								LayerMask mask=1<<LayerManager.LayerPlatform();
								mask|=1<<LayerManager.LayerTower();
								if(!Physics.Linecast(currentNode.pos, node.pos, ~mask)){
									//if the slop is not too steep
									//if(Mathf.Abs(GetSlope(currentNode.pos, node.pos))<=maxSlope){
										//add to list
										//if(!node.walkable) Debug.Log("error");
										neighbourNodeList.Add(node);
										neighbourCostList.Add(neighbourDistance);
									//}//else print("too steep");
								}//else print("something's in the way");
							}//else print("out of range "+neighbourDistance);
						}//else print("unwalkable");
					}

					//set the list as the node neighbours array
					currentNode.SetNeighbour(neighbourNodeList, neighbourCostList);
					
					//if(neighbourNodeList.Count==0)
						//Debug.Log("no heighbour. node number "+counter+"  "+neighbourNodeList.Count);
				}
				
				counter+=1;
			}
			
			return nodeGraph;
		}
示例#21
0
        public BuildInfo _CheckBuildPoint(Vector3 pointer, int towerID)
        {
            BuildInfo buildInfo = new BuildInfo();

            if (disableBuildWhenInPlay && SpawnManager.GetActiveUnitCount() > 0)
            {
                buildInfo.status = _TileStatus.NotInBuildPhase;
                return(buildInfo);
            }

            Camera mainCam = Camera.main;

            if (mainCam != null)
            {
                Ray        ray = mainCam.ScreenPointToRay(pointer);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, maskPlatform))
                {
                    for (int i = 0; i < buildPlatforms.Count; i++)
                    {
                        if (hit.transform == buildPlatforms[i].thisT)
                        {
                            PlatformTD platform = buildPlatforms[i];

                            //calculating the build center point base on the input position
                            Vector3 pos = GetTilePos(platform, hit.point);

                            buildInfo.position = pos;
                            buildInfo.platform = platform;

                            //checking if tower can be built on the platform, for dragNdrop mode
                            if (towerID >= 0 && !platform.availableTowerIDList.Contains(towerID))
                            {
                                buildInfo.status = _TileStatus.Unavailable;
                            }

                            if (buildInfo.status == _TileStatus.Available)
                            {
                                //check if the position is blocked, by any other obstabcle other than the baseplane itself
                                Collider[] cols = Physics.OverlapSphere(pos, gridSize / 2 * 0.9f, ~maskAll);
                                if (cols.Length > 0)
                                {
                                    buildInfo.status = _TileStatus.NoPlatform;
                                }
                                else
                                {
                                    buildInfo.status = _TileStatus.Available;
                                }

                                if (buildInfo.status == _TileStatus.Available)
                                {
                                    //check if the platform is walkable, if so, check if building on the point wont block all possible path
                                    if (platform.IsWalkable())
                                    {
                                        if (platform.CheckForBlock(pos))
                                        {
                                            buildInfo.status = _TileStatus.Blocked;
                                        }
                                    }

                                    //map platform availableTowerIDList (which is the towers' prefabID) to the list elements' ID in towerList
                                    buildInfo.availableTowerIDList = new List <int>();
                                    for (int m = 0; m < platform.availableTowerIDList.Count; m++)
                                    {
                                        for (int n = 0; n < towerList.Count; n++)
                                        {
                                            if (platform.availableTowerIDList[m] == towerList[n].prefabID)
                                            {
                                                buildInfo.availableTowerIDList.Add(n);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            break;
                        }
                    }
                }
                else
                {
                    buildInfo.status = _TileStatus.NoPlatform;
                }
            }
            else
            {
                buildInfo.status = _TileStatus.NoPlatform;
            }

            //reverse block status for mine
            if (buildInfo.status == _TileStatus.Blocked)
            {
                //for drag n drop mode
                if (towerID >= 0 && GetTowerPrefab(towerID).type == _TowerType.Mine)
                {
                    buildInfo.status = _TileStatus.Available;
                }
                if (towerID < 0)
                {
                    bool gotMineInList = false;
                    for (int i = 0; i < buildInfo.availableTowerIDList.Count; i++)
                    {
                        if (towerList[buildInfo.availableTowerIDList[i]].type == _TowerType.Mine)
                        {
                            gotMineInList = true;
                        }
                        else
                        {
                            buildInfo.availableTowerIDList.RemoveAt(i);
                            i -= 1;
                        }
                    }
                    if (gotMineInList)
                    {
                        buildInfo.status = _TileStatus.Available;
                    }
                }
            }


            if (!UseDragNDrop())             //for PointNClick
            {
                if (buildInfo.status != _TileStatus.Available)
                {
                    IndicatorControl.ClearBuildTileIndicator();
                }
                else
                {
                    IndicatorControl.SetBuildTileIndicator(buildInfo);
                }
            }

            return(buildInfo);
        }
示例#22
0
        public _TileStatus _CheckBuildPoint(Vector3 pointer, int footprint = -1, int ID = -1)
        {
            _TileStatus status       = _TileStatus.Available;
            BuildInfo   newBuildInfo = new BuildInfo();

            //disable indicator first (for dragNdrop mode), it will be re-enable if the build-point is valid
            indicatorBuildPoint.SetActive(false);

            //layerMask for platform only
            LayerMask maskPlatform = 1 << LayerManager.LayerPlatform();
            //layerMask for detect all collider within buildPoint
            LayerMask maskAll      = 1 << LayerManager.LayerPlatform();
            int       terrainLayer = LayerManager.LayerTerrain();

            if (terrainLayer >= 0)
            {
                maskAll |= 1 << terrainLayer;
            }

            //int creepLayer=LayerManager.layerCreep();
            //if(creepLayer>=0) maskAll|=1<<creepLayer;

            Camera mainCam = Camera.main;

            if (mainCam != null)
            {
                Ray        ray = mainCam.ScreenPointToRay(pointer);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, maskPlatform))
                {
                    for (int i = 0; i < buildPlatforms.Count; i++)
                    {
                        if (hit.transform == buildPlatforms[i].thisT)
                        {
                            PlatformTD platform = buildPlatforms[i];

                            //checking if tower can be built on the platform, for dragNdrop mode
                            if (ID >= 0 && !platform.availableTowerIDList.Contains(ID))
                            {
                                return(_TileStatus.Unavailable);
                            }

                            //calculating the build center point base on the input position
                            Vector3 pos = GetTilePos(platform.thisT, hit.point);

                            //check if the position is blocked, by any other obstabcle other than the baseplane itself
                            Collider[] cols = Physics.OverlapSphere(pos, _gridSize / 2 * 0.9f + footprint * _gridSize, ~maskAll);
                            if (cols.Length > 0)
                            {
                                //Debug.Log("something's in the way "+cols[0]);
                                return(_TileStatus.Unavailable);
                            }
                            else
                            {
                                //confirm that we can build here
                                newBuildInfo.position = pos;
                                newBuildInfo.platform = platform;
                            }

                            //newBuildInfo.availableTowerIDList=platform.availableTowerIDList;
                            //map platform availableTowerIDList (which is the towers' prefabID) to the list elements' ID in towerList
                            newBuildInfo.availableTowerIDList = new List <int>();
                            for (int m = 0; m < platform.availableTowerIDList.Count; m++)
                            {
                                for (int n = 0; n < towerList.Count; n++)
                                {
                                    if (platform.availableTowerIDList[m] == towerList[n].prefabID)
                                    {
                                        newBuildInfo.availableTowerIDList.Add(n);
                                        break;
                                    }
                                }
                            }

                            //List<int> tempList=new List<int>();
                            //for(int n=0; n<towerList.Count; n++) tempList.Add(towerList[n].prefabID);
                            //newBuildInfo.availableTowerIDList=tempList;

                            buildInfo = newBuildInfo;

                            break;
                        }
                    }
                }
                else
                {
                    return(_TileStatus.NoPlatform);
                }
            }
            else
            {
                return(_TileStatus.NoPlatform);
            }



            if (buildInfo != null && cursorIndicatorMode != _CursorIndicatorMode.None)
            {
                if (status == _TileStatus.Available)
                {
                    indicatorBuildPointRen.material.SetColor("_TintColor", new Color(0, 1, 0, 1));
                }
                else
                {
                    indicatorBuildPointRen.material.SetColor("_TintColor", new Color(1, 0, 0, 1));
                }

                indicatorBuildPoint.SetActive(true);
                indicatorBuildPoint.transform.position = buildInfo.position;
                if (buildInfo.platform != null)
                {
                    indicatorBuildPoint.transform.rotation = buildInfo.platform.thisT.rotation;
                }

                HideCursorIndicator();
            }

            return(status);
        }
示例#23
0
        public void InitTower(int ID, PlatformTD currentPlatform)
        {
            Init();

              instanceID = ID;
              platform = currentPlatform;

              value = stats[currentActiveStat].cost;

              int rscCount = ResourceManager.GetResourceCount();
              for (int i = 0; i < stats.Count; i++)
              {
            UnitStat stat = stats[i];
            stat.slow.effectID = instanceID;
            stat.dot.effectID = instanceID;
            stat.buff.effectID = instanceID;
            if (stat.rscGain.Count != rscCount)
            {
              while (stat.rscGain.Count < rscCount) stat.rscGain.Add(0);
              while (stat.rscGain.Count > rscCount) stat.rscGain.RemoveAt(stat.rscGain.Count - 1);
            }
              }

              if (type == _TowerType.Turret)
              {
            StartCoroutine(ScanForTargetRoutine());
            StartCoroutine(TurretRoutine());
              }
              if (type == _TowerType.AOE)
              {
            StartCoroutine(AOETowerRoutine());
              }
              if (type == _TowerType.Support)
              {
            StartCoroutine(SupportRoutine());
              }
              if (type == _TowerType.Electric)
              {
            // TODO: Coroutine for electric towers here
              }
        }