void OnTowerHover(TowerButtonBehavior btn) { if (second != btn) { second = btn; SecondTarget.SetToTowerButton(btn); } }
void OnTowerSelected(TowerButtonBehavior btn) { if (first == null) { FirstTarget.SetToTowerButton(btn); first = btn; } }
void OnTowerDeselected(TowerButtonBehavior btn) { if (btn == first) { FirstTarget.Hide(); first = null; } }
public void OnBeginDrag(PointerEventData eventData) { var btn = Controller.GetTowerButton(eventData.position); //Debug.Log("Button: " + btn.Tower.Index + " | Faction: " + btn.Tower.Faction); if (btn != null && btn.Tower.Faction == FactionController.PlayerFaction) { firstSelect = btn; //Debug.Log("Drag Begin: " + btn.Tower.Index); } }
public void SetToTowerButton(TowerButtonBehavior btn) { gameObject.SetActive(true); if (currentRoutine != null) { StopCoroutine(currentRoutine); Reset(); } this.btn = btn; rect.position = btn.transform.position; currentRoutine = StartCoroutine(Open(btn.Size * 1.5f, Quaternion.Euler(new Vector3(0, 0, rotation)))); }
/// <summary> /// Tell the UIController that this tower will be moving and to update the position of the button accordingly. /// </summary> /// <param name="tower">Tower to mark.</param> public static void MarkTowerAsDynamic(TowerBehavior tower) { TowerButtonBehavior tbtn = null; foreach (var b in current.buttons) { if (b.Tower == tower) { current.dynamicBtns.Add(b); tbtn = b; } } if (tbtn == null) { Debug.LogError("No TowerButton for Tower found: " + tower); } }
public void OnPointerDown(PointerEventData eventData) { var btn = Controller.GetTowerButton(eventData.position); if (btn != null && btn.Tower.Faction == FactionController.PlayerFaction) { // Soft select tower and prepare units for movement firstSelect = btn; //firstSelect.Tower.ShowAtmosphere(); curUnitGroup = UnitController.CreateUnitGroupForFaction(btn.Tower.Faction, (int)(btn.Tower.StationedUnits * Controller.UnitPercent)); curUnitGroup.PrepareUnits(btn.Tower); if (PlayerSelectedTower != null) { PlayerSelectedTower(btn); } } }
// Checks for a tower button at position on screen. Uses TowerButtonRadius to determine range of the buttons. public TowerButtonBehavior GetTowerButton(Vector2 position) { // Scale down radius to account for multiple screen sizes //Debug.Log("Ratio: " + ratio); float minDist = 300f; float closestDist = float.MaxValue; TowerButtonBehavior closest = null; foreach (var btn in buttons) { float dist = Vector2.Distance(position, new Vector2(btn.transform.position.x, btn.transform.position.y)); if (dist < minDist && dist < closestDist) { closestDist = dist; closest = btn; } } //Debug.Log("No button found"); return(closest); }
public void OnPointerUp(PointerEventData eventData) { if (firstSelect != null) { if (secondSelect != null) { // If two towers are selected and they are not the same tower, move units to second tower if (firstSelect != secondSelect) { //Debug.Log("Sending Units: " + curUnitGroup.UnitCount); TowerBehavior.MoveGroupFromTo(curUnitGroup, firstSelect.Tower, secondSelect.Tower); curUnitGroup = null; } if (PlayerUnhoveredTower != null) { PlayerUnhoveredTower(secondSelect); } } if (PlayerDeselectedTower != null) { PlayerDeselectedTower(firstSelect); } } // Reset unused units if (curUnitGroup != null) { curUnitGroup.UnprepareUnits(); curUnitGroup = null; } firstSelect = null; secondSelect = null; }
public void OnPointerClick(PointerEventData eventData) { var btn = Controller.GetTowerButton(eventData.position); if (btn == null || btn.Tower.Faction != FactionController.PlayerFaction) { return; } if (firstSelect == null) { firstSelect = btn; } else { // If double click if (firstSelect == btn && eventData.clickCount % 2 == 0) { // If already selected, deselect if (selected == firstSelect) { firstSelect.Deselect(); selected = null; } else { // If nothing is selected, select if (selected != null) { selected.Deselect(); } firstSelect.Select(); selected = firstSelect; } } } }
void OnTowerUnhover(TowerButtonBehavior btn) { SecondTarget.Hide(); second = null; }
public void OnDrag(PointerEventData eventData) { if (firstSelect == null) { return; } var s = Controller.GetTowerButton(eventData.position); if (s != null) { //Debug.Log("Dragging: " + s.Tower.Index); // If pointer is over tower and it is not the same as the first selected tower if (s != firstSelect)// && secondSelect == null) { // If second is not selected yet if (secondSelect == null) { secondSelect = s; if (PlayerHoveredTower != null) { PlayerHoveredTower(secondSelect); } } // Else if s is not already selected else if (s != secondSelect) { if (PlayerUnhoveredTower != null) { PlayerUnhoveredTower(secondSelect); } secondSelect = s; if (PlayerHoveredTower != null) { PlayerHoveredTower(secondSelect); } } } else { // Unhover second selected tower if (secondSelect != null && PlayerUnhoveredTower != null) { PlayerUnhoveredTower(secondSelect); secondSelect = null; } } } else { // If pointer isn't over anything hide second tower's atmosphere if exists if (secondSelect != null) { if (PlayerUnhoveredTower != null) { PlayerUnhoveredTower(secondSelect); } } secondSelect = null; } }
void OnPlayerUnhoveredTower(TowerButtonBehavior tower) { //planetSelectedTexture.setValue(0); AudioManager.PlayTowerUnhovered(); }
void OnPlayerDeselectedTower(TowerButtonBehavior tower) { //planetSelectedEngine.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); AudioManager.PlayTowerDeselected(); }
void OnPlayerSelectedTower(TowerButtonBehavior tower) { //planetSelectedEngine.start(); //planetSelectedTexture.setValue(0); AudioManager.PlayTowerSelected(); }