public void Init(){ instance=this; gridSize=Mathf.Max(0.25f, gridSize); _gridSize=gridSize; buildInfo=null; InitTower(); InitPlatform(); }
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 void _Show() { buildInfo=BuildManager.GetBuildInfo(); UpdateActiveBuildButtonList(); Update(); isOn=true; thisObj.SetActive(isOn); }
static public void ClearBuildPoint(){ //Debug.Log("ClearBuildPoint"); buildInfo=null; ClearIndicator(); }
public static void ClearBuildPoint() { buildInfo=null; ClearIndicator(); }
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); }
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); }
static public void ClearBuildPoint() { //Debug.Log("ClearBuildPoint"); buildInfo = null; ClearIndicator(); }
static public void ClearBuildPoint() { buildInfo = null; ClearIndicator(); }