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; } //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)) { //Debug.Log("all path is blocked "+Time.time); status = _TileStatus.Blocked; } } //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); } //reverse block status for mine if (status == _TileStatus.Blocked) { //for drag n drop mode if (ID >= 0 && GetTower(ID).type == _TowerType.Mine) { status = _TileStatus.Available; } if (ID < 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) { status = _TileStatus.Available; } } } 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 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); }