private int currentButtonID = -1; //last touched button, for touch mode only public void OnTowerButton(GameObject butObj, int pointerID = -1) { int ID = GetButtonID(butObj); if (UIMainControl.InTouchMode() && !BuildManager.UseDragNDrop()) { if (currentButtonID >= 0) { buttonList[currentButtonID].imgHighlight.enabled = false; } if (currentButtonID != ID) { currentButtonID = ID; buttonList[ID].imgHighlight.enabled = true; OnHoverButton(butObj); return; } ClearTouchModeButton(); } string exception = BuildManager.BuildTower(ID, buildInfo, pointerID); if (exception != "") { UIMessage.DisplayMessage(exception); return; } buildInfo = null; if (!BuildManager.UseDragNDrop()) { Hide(); } }
public void OnTowerButton(GameObject butObj) { //in drag and drop mode, player could be hitting the button while having an active tower selected //if that's the case, clear the selectedTower first. and we can show the tooltip properly if (UI.UseDragNDrop() && GameControl.GetSelectedTower() != null) { UI.ClearSelectedTower(); return; } int ID = GetButtonID(butObj); List <UnitTower> towerList = BuildManager.GetTowerList(); bool exception = true; if (!UI.UseDragNDrop()) { exception = BuildManager.BuildTower(towerList[ID]); } else { exception = BuildManager.BuildTowerDragNDrop(towerList[ID]); } if (exception == false) { UIGameMessage.DisplayMessage("Can't build tower"); } if (!UI.UseDragNDrop()) { OnExitHoverButton(butObj); } Hide(); }
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 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); }