private static bool SelectedResearchFacilityTile(PlotSelectable selectable) { // Selected the selected object, so open research facility if (selectable == selected) { Deselect(selectable); EventManager.Instance.RaiseEvent(new OpenResearchFacilityEvent()); return(true); } return(false); }
/// <summary> /// Performs a raycast from the camera to the mouse /// </summary> /// <param name="selectable">The PlotSelectable that is hit by the raycast</param> /// <returns>True or False depending on whether we hit a PlotSelectable</returns> private bool RayCast(out PlotSelectable selectable) { Ray mouseRay = playerCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(mouseRay, out RaycastHit hitinfo)) { GameObject hitObject = hitinfo.collider.gameObject; selectable = hitObject.GetComponent <PlotSelectable>(); if (selectable != null) { return(true); } } selectable = null; return(false); }
private static bool SelectedBuilding(PlotSelectable selectable, AbstractBuildingTile abstractBuildingTile) { // Selected the selected object, so open market if (selectable == selected) { Deselect(selectable); if (abstractBuildingTile.HasDebris) { EventManager.Instance.RaiseEvent(new SelectedBuildingTileEvent(abstractBuildingTile, true)); return(true); } EventManager.Instance.RaiseEvent(new OpenMarketEvent(abstractBuildingTile)); return(true); } // Send the tile if it has a building, else send null so that the listeners know you selected something that has no building EventManager.Instance.RaiseEvent(new SelectedBuildingTileEvent(abstractBuildingTile.HasBuilding ? abstractBuildingTile : null, true)); return(false); }
private void Select(PlotSelectable selectable) { AbstractTile abstractTile = selectable.GetTile(); if (!(abstractTile is AbstractBuildingTile)) { // we did not select a building, so tell our listeners EventManager.Instance.RaiseEvent(new SelectedBuildingTileEvent(null, false)); } switch (abstractTile) // Handle special actions if we selected an already selected tile { case AbstractBuildingTile buildingTile when SelectedBuilding(selectable, buildingTile): case ResearchFacilityTile researchFacilityTile when SelectedResearchFacilityTile(selectable): return; } Deselect(selected); // Deselect the last selected object // select the new object selected = selectable; selectable.Select(selectedMaterial); }
private static void Deselect(ISelectable selectable) { selectable?.Deselect(); selected = null; }