//similar to CheckBuildPoint but called by UnitTower in DragNDrop mode, check tower type before return public static bool CheckBuildPoint(Vector3 pointer, int footprint, int ID) { //~ Debug.Log(footprint); _TileStatus status = CheckBuildPoint(pointer, footprint); if (status == _TileStatus.NoPlatform || status == _TileStatus.Unavailable) { return(false); } UnitTower tower = GetTower(ID); if (status == _TileStatus.Blocked && tower.type != _TowerType.Mine) { return(false); } if (ID >= 0) { foreach (TowerAvailability avai in currentBuildInfo.towerAvaiList) { if (avai.ID == ID) { if (avai.enabledInLvl) { return(true); } else { return(false); } //break; } } } currentBuildInfo.buildable = false; return(false); }
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); }
public IEnumerator DragNDropRoutine() { GameControl.SelectTower(this); yield return(null); #if (UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY) && !UNITY_EDITOR _TileStatus status = _TileStatus.NoPlatform; while (Input.touchCount >= 1) { Vector3 pos = Input.touches[0].position; status = BuildManager.CheckBuildPoint(pos, -1, prefabID); if (status == _TileStatus.Available) { BuildInfo buildInfo = BuildManager.GetBuildInfo(); thisT.position = buildInfo.position; thisT.rotation = buildInfo.platform.thisT.rotation; } else { Ray ray = Camera.main.ScreenPointToRay(pos); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { thisT.position = hit.point; } //this there is no collier, randomly place it 30unit from camera else { thisT.position = ray.GetPoint(30); } } if (Input.touches[0].phase == TouchPhase.Ended) { //if current mouse point position is valid, build the tower if (status == _TileStatus.Available) { bool exception = BuildManager.BuildTower(srcTower); if (exception == false) { GameControl.DisplayMessage("Can't build tower"); } } else { BuildManager.ClearBuildPoint(); } break; } yield return(null); } GameControl.ClearSelectedTower(); #else while (true) { Vector3 pos = Input.mousePosition; _TileStatus status = BuildManager.CheckBuildPoint(pos, -1, prefabID); if (status == _TileStatus.Available) { BuildInfo buildInfo = BuildManager.GetBuildInfo(); thisT.position = buildInfo.position; thisT.rotation = buildInfo.platform.thisT.rotation; } else { Ray ray = Camera.main.ScreenPointToRay(pos); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { thisT.position = hit.point; } //this there is no collier, randomly place it 30unit from camera else { thisT.position = ray.GetPoint(30); } } //left-click, build if (Input.GetMouseButtonDown(0) && !UIUtilities.IsCursorOnUI()) { //if current mouse point position is valid, build the tower if (status == _TileStatus.Available) { bool exception = BuildManager.BuildTower(srcTower); if (exception == false) { GameControl.DisplayMessage("Can't build tower"); } } else { BuildManager.ClearBuildPoint(); } GameControl.ClearSelectedTower(); thisObj.SetActive(false); break; } //right-click, cancel if (Input.GetMouseButtonDown(1) || GameControl.GetGameState() == _GameState.Over) { GameControl.ClearSelectedTower(); BuildManager.ClearBuildPoint(); thisObj.SetActive(false); break; } yield return(null); } #endif thisObj.SetActive(false); thisT.position = new Vector3(0, 9999, 0); BuildManager.ShowPlatform(false); }
public static _TileStatus CheckBuildPoint(Vector3 pointer, int footprint) { footprint = -1; //if(currentBuildInfo!=null) return false; _TileStatus status = _TileStatus.Available; BuildableInfo buildableInfo = new BuildableInfo(); //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; } Ray ray = Camera.main.ScreenPointToRay(pointer); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, maskPlatform)) { for (int i = 0; i < buildManager.buildPlatforms.Length; i++) { Transform basePlane = buildManager.platforms[i]; if (hit.transform == basePlane) { //calculating the build center point base on the input position Vector3 pos = GetTilePos(basePlane, 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 buildableInfo.buildable = true; buildableInfo.position = pos; buildableInfo.platform = buildManager.buildPlatforms[i]; //Debug.Log(buildableInfo.platform+" !!! "+buildManager.buildPlatforms[i]); } //check if the platform is walkable, if so, check if building on the point wont block all possible path if (buildManager.buildPlatforms[i].IsWalkable()) { //return true is the platform is not block if (buildManager.buildPlatforms[i].CheckForBlock(pos, footprint)) { //Debug.Log("all path is blocked "+Time.time); status = _TileStatus.Blocked; } } //~ buildableInfo.buildableType=buildManager.buildPlatforms[i].buildableType; //~ buildableInfo.specialBuildableID=buildManager.buildPlatforms[i].specialBuildableID; if (status == _TileStatus.Blocked) { List <TowerAvailability> tempList = new List <TowerAvailability>(); for (int n = 0; n < buildManager.buildPlatforms[i].towerAvaiList.Count; n++) { UnitTower tower = GetTower(buildManager.buildPlatforms[i].towerAvaiList[n].ID); if (tower.type == _TowerType.Mine) { tempList.Add(buildManager.buildPlatforms[i].towerAvaiList[n]); } } buildableInfo.towerAvaiList = tempList; } else { buildableInfo.towerAvaiList = buildManager.buildPlatforms[i].towerAvaiList; } break; } } } else { return(_TileStatus.NoPlatform); } currentBuildInfo = buildableInfo; if (buildManager.tileIndicatorMode != _TileIndicatorMode.None) { Utility.SetActive(indicator, true); indicator.transform.position = currentBuildInfo.position; if (currentBuildInfo.platform != null) { indicator.transform.rotation = currentBuildInfo.platform.thisT.rotation; } } return(status); }
public IEnumerator DragNDropRoutine() { GameControl.SelectTower(this); yield return(null); while (true) { Vector3 pos = Input.mousePosition; _TileStatus status = BuildManager.CheckBuildPoint(pos, -1, prefabID); if (status == _TileStatus.Available) { BuildInfo buildInfo = BuildManager.GetBuildInfo(); thisT.position = buildInfo.position; thisT.rotation = buildInfo.platform.thisT.rotation; } else { Ray ray = Camera.main.ScreenPointToRay(pos); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { thisT.position = hit.point; } //this there is no collier, randomly place it 30unit from camera else { thisT.position = ray.GetPoint(30); } } //left-click, build if (Input.GetMouseButtonDown(0) && !UIUtilities.IsCursorOnUI()) { //if current mouse point position is valid, build the tower if (status == _TileStatus.Available) { string exception = BuildManager.BuildTower(srcTower); if (exception != "") { GameControl.DisplayMessage(exception); } } else { BuildManager.ClearBuildPoint(); } GameControl.ClearSelectedTower(); thisObj.SetActive(false); break; } //right-click, cancel if (Input.GetMouseButtonDown(1) || GameControl.GetGameState() == _GameState.Over) { GameControl.ClearSelectedTower(); BuildManager.ClearBuildPoint(); thisObj.SetActive(false); break; } yield return(null); } thisT.position = new Vector3(0, 9999, 0); }