bool ScreenElementsContains(Vector2 point) { if (gameSpeedButton.Contains(point)) { return(true); } else if (miniMap.Contains(point)) { return(true); } else if (SetupPhase && ShipSelectionRect.Contains(point)) { return(true); } else if (PlayerShipManager.HasSomethingSelected() && shipInfoPanel.ContainsMouse(point)) { return(true); } else if (fleetCombatInfoPanel.Contains(point)) { return(true); } return(false); }
bool ScreenElementsContains(Vector2 point) { if (miniMap.Contains(point) || gameSpeedButton.Contains(point)) { return(true); } else if (screenState == ScreenState.setup && SetupPanel.Contains(point)) { return(true); } else if (screenState == ScreenState.play && shipInfoPanel.ContainsMouse(point) && PlayerShipManager.HasSomethingSelected()) { return(true); } return(false); }
// Update is called once per frame public override void Update() { base.Update(); SetMousePosition(); if (SetupPhase) { if (Input.GetKeyDown(KeyCode.Escape)) { CloseScreen(); } if (Input.GetMouseButtonDown(1)) { DeselectDesignData(); if (PickedUpObject != null) { PickedUpObject.transform.position = PickedUpOrigin; PickedUpObject = null; } } if (Input.GetMouseButton(1)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); //If we hit... if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.collider.transform.root.tag == "Ship") { Ship ship = hit.collider.transform.root.GetComponent <Ship> (); ship.GetShipData().RemoveFromFleet(); ship.DestroyAllFighters(); ship.DestroyWeaponEffects(); ship.DeleteSelf(); } else if (hit.collider.transform.root.tag == "Fighter") { Fighter fighter = hit.collider.transform.root.GetComponent <Fighter> (); fighter.GetParentWing().DestroySelf(); } else if (hit.collider.transform.root.tag == "FighterWing") { hit.collider.transform.root.GetComponent <FighterWing>().DestroySelf(); } } } else if (DummyUnit != null && !ScreenElementsContains(mousePosition)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); //If we hit... if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (!PivotSet) { DummyUnit.transform.position = new Vector3(hit.point.x, 1f, hit.point.z); } if (Input.GetMouseButtonDown(0)) { PivotPoint = DummyUnit.transform.position; PivotSet = true; } else if (Input.GetMouseButton(0)) { Vector3 Direction = (new Vector3(hit.point.x, 1f, hit.point.z) - PivotPoint); if (Direction.magnitude > DummyUnitRadius) { Quaternion Rotation = Quaternion.LookRotation(Direction); DummyUnit.transform.rotation = Rotation; } } else if (Input.GetMouseButtonUp(0)) { ShipData shipData = new ShipData(selectedDesign); Ship newShip = ResourceManager.CreateCombatShip(shipData, DummyUnit.transform.position, DummyUnit.transform.rotation); if (newShip != null) { if (PlayerSelected) { PlayerShipManager.AddSpaceUnit(newShip); PlayerFleet.AddShip(newShip.GetShipData()); } else if (EnemySelected) { EnemyShipManager.AddSpaceUnit(newShip); EnemyFleet.AddShip(newShip.GetShipData()); } else if (AllySelected) { AlliedShipManager.AddSpaceUnit(newShip); AlliedFleet.AddShip(newShip.GetShipData()); } else if (NeutralSelected) { NeutralShipManager.AddSpaceUnit(newShip); NeutralFleet.AddShip(newShip.GetShipData()); } } PivotSet = false; } } } else if (PickedUpObject != null && !ScreenElementsContains(mousePosition)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); //If we hit... if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (!PivotSet) { PickedUpObject.transform.position = new Vector3(hit.point.x, 1f, hit.point.z); } if (Input.GetMouseButtonDown(0)) { PivotPoint = PickedUpObject.transform.position; PivotSet = true; } else if (Input.GetMouseButton(0)) { Vector3 Direction = (new Vector3(hit.point.x, 1f, hit.point.z) - PivotPoint); if (Direction.magnitude > DummyUnitRadius) { Quaternion Rotation = Quaternion.LookRotation(Direction); PickedUpObject.transform.rotation = Rotation; } } else if (Input.GetMouseButtonUp(0)) { PickedUpObject = null; PivotSet = false; } } } else if (miniMap.Contains(mousePosition)) { if (Input.GetMouseButton(0)) { miniMap.GetWorldPosition(mousePosition); } } else if (DummyUnit == null) { if (Input.GetMouseButtonUp(0)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); //If we hit... if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.collider.transform.root.tag == "Ship") { PickedUpObject = hit.collider.transform.root.gameObject; PickedUpOrigin = hit.collider.transform.root.transform.position; } } } } } else { //Update the ships managers UpdateShipManagers(); Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); if (Input.GetKeyDown(KeyCode.Escape)) { SetPauseShipManagers(true); SetupPhase = true; } if (!ScreenElementsContains(mousePosition)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { //Highlight hovered units if (hit.collider.transform.root.tag == "Ship") { hit.collider.transform.root.GetComponent <SpaceUnit> ().Hovered(); } else if (hit.collider.transform.root.tag == "Fighter") { hit.collider.transform.root.GetComponent <Fighter> ().GetParentWing().Hovered(); } else if (hit.collider.transform.root.tag == "FighterWing") { hit.collider.transform.root.GetComponent <FighterWing> ().Hovered(); } //Process abilities if (PlayerShipManager.AbilityActivite()) { if (hit.collider.transform.root.tag == "Ship") { Ship hoveredShip = hit.collider.transform.root.GetComponent <Ship>(); if (hoveredShip.ValidTransporterTarget(PlayerShipManager)) { if (PlayerShipManager.TransporterTargetingTroop) { Cursor.SetCursor(ResourceManager.GetIconTexture("Icon_TransportTroop"), Vector2.zero, CursorMode.Auto); if (Input.GetMouseButtonDown(0)) { PlayerShipManager.CastActiveAbility(hoveredShip); } } else if (PlayerShipManager.TransporterTargetingCrew) { Cursor.SetCursor(ResourceManager.GetIconTexture("Icon_TransportCrew"), Vector2.zero, CursorMode.Auto); if (Input.GetMouseButtonDown(0)) { PlayerShipManager.CastActiveAbility(hoveredShip); } } } } if (Input.GetMouseButtonDown(1)) { PlayerShipManager.ResetAbilities(); } } else //Normal movement and commands { if (Input.GetMouseButtonDown(0)) { //Cancel movement order if (PivotSet) { PivotSet = false; Object.Destroy(PivotObject); foreach (GameObject marker in DirectionMarkers) { Object.Destroy(marker); } DirectionMarkers.Clear(); } //Check if clicked a ship if (hit.collider.transform.root.tag == "Ship") { Ship ship = hit.collider.transform.root.GetComponent <Ship>(); if (ship.GetShipManager() == PlayerShipManager) { if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } PlayerShipManager.AddToSelection(ship); } else { PlayerShipManager.SelectUnownedShip(ship); } } else if (hit.collider.transform.root.tag == "FighterWing") { FighterWing fighterWing = hit.collider.transform.root.GetComponent <FighterWing>(); if (fighterWing.GetShipManager() == PlayerShipManager) { if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } PlayerShipManager.AddToSelection(fighterWing); } else { PlayerShipManager.SelectUnownedFighter(fighterWing); } } else if (hit.collider.transform.root.tag == "Fighter") { Fighter fighter = hit.collider.transform.root.GetComponent <Fighter>(); if (fighter.GetShipManager() == PlayerShipManager) { if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } PlayerShipManager.AddToSelection(fighter); } else { PlayerShipManager.SelectUnownedFighter(fighter); } } else if (hit.collider.gameObject.tag == "PlayArea") { if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } shipDragSelectionBox.SetStart(Input.mousePosition); } } else if (Input.GetMouseButtonDown(1) && PlayerShipManager.HasSomethingSelected()) { if (hit.collider.gameObject.tag == "PlayArea") { PivotSet = true; PivotObject = new GameObject(); PivotObject.transform.position = hit.point; Vector3 shipGroupCenter; Vector3 sum = Vector3.zero; foreach (Ship ship in PlayerShipManager.GetSelectedShips()) { sum += ship.transform.position; } foreach (FighterWing fighterWing in PlayerShipManager.GetSelectedFighters()) { sum += fighterWing.transform.position; } shipGroupCenter = sum / PlayerShipManager.GetSelectedMobileUnitsCount(); Vector3 Direction = PivotObject.transform.position - shipGroupCenter; Quaternion rotation = Quaternion.LookRotation(Direction, Vector3.up); PivotObject.transform.rotation = rotation; foreach (Ship ship in PlayerShipManager.GetSelectedShips()) { GameObject marker = ResourceManager.CreateDirectionMarker(ship.transform.position + Direction); marker.transform.rotation = rotation; DirectionMarkers.Add(marker); marker.transform.parent = PivotObject.transform; } foreach (FighterWing fighterWing in PlayerShipManager.GetSelectedFighters()) { GameObject marker = ResourceManager.CreateDirectionMarker(fighterWing.transform.position + Direction); marker.transform.rotation = rotation; DirectionMarkers.Add(marker); marker.transform.parent = PivotObject.transform; } } else if (hit.collider.transform.root.tag == "Ship") { Ship ship = hit.collider.transform.root.GetComponent <Ship>(); PlayerShipManager.SetTargetForSelectedShips(ship); } else if (hit.collider.transform.root.tag == "FighterWing") { FighterWing fighterWing = hit.collider.transform.root.GetComponent <FighterWing>(); PlayerShipManager.SetTargetForSelectedShips(fighterWing.GetFirstFighter()); } else if (hit.collider.transform.root.tag == "Fighter") { Fighter fighter = hit.collider.transform.root.GetComponent <Fighter>(); PlayerShipManager.SetTargetForSelectedShips(fighter); } } else if (Input.GetMouseButton(1) && PivotSet) { if (hit.collider.gameObject.tag == "PlayArea") { Vector3 Direction = hit.point - PivotObject.transform.position; if (Direction.sqrMagnitude > 0) { Quaternion rotation = Quaternion.LookRotation(Direction, Vector3.up); PivotObject.transform.rotation = rotation; foreach (GameObject marker in DirectionMarkers) { marker.transform.rotation = rotation; } } } } else if (PivotSet) { if (hit.collider.gameObject.tag == "PlayArea") { List <Vector3> points = new List <Vector3>(); foreach (GameObject marker in DirectionMarkers) { points.Add(marker.transform.position); } PlayerShipManager.SetGoalPositionsForShips(points, PivotObject.transform.rotation); PivotSet = false; Object.Destroy(PivotObject); foreach (GameObject marker in DirectionMarkers) { Object.Destroy(marker); } DirectionMarkers.Clear(); } } } } //Drag left click if (Input.GetMouseButton(0)) { shipDragSelectionBox.SetEnd(Input.mousePosition); } else if (shipDragSelectionBox.isActive()) { //Deselect ships from before if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } shipDragSelectionBox.SetActive(false); shipDragSelectionBox.SelectShips(PlayerShipManager); } } else if (miniMap.Contains(mousePosition)) { if (Input.GetMouseButton(0)) { miniMap.GetWorldPosition(mousePosition); } } } }
// Update is called once per frame public override void Update() { combatCameraMover.Update(); SetMousePosition(); if (Input.GetKeyDown(KeyCode.Escape)) { if (SummaryScrollList.isOpen()) { SummaryScrollList.SetOpen(false); } else if (designDisplayWindow.isOpen()) { designDisplayWindow.SetOpen(false); } else { if (SetupPhase) { if (quitResumeSubScreen.isOpen()) { quitResumeSubScreen.SetOpen(false); } else { quitResumeSubScreen.SetOpen(true); } } else { SetPauseShipManagers(true); SetupPhase = true; } } } if (SetupPhase) { if (Input.GetMouseButtonDown(1)) { DeselectDesignData(); if (PickedUpObject != null) { PickedUpObject.transform.position = PickedUpOrigin; PickedUpObject = null; } } if (Input.GetMouseButton(1)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); //If we hit... if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.collider.transform.root.tag == "Ship") { Ship ship = hit.collider.transform.root.GetComponent <Ship>(); ship.GetShipData().RemoveFromFleet(); ship.DestroyAllFighters(); ship.DestroyWeaponEffects(); ship.DeleteSelf(); } if (hit.collider.transform.root.tag == "Station") { Station station = hit.collider.transform.root.GetComponent <Station>(); station.stationData.RemoveFromFleet(); station.DestroyAllFighters(); station.DeleteSelf(); } else if (hit.collider.transform.root.tag == "Fighter") { Fighter fighter = hit.collider.transform.root.GetComponent <Fighter>(); fighter.GetParentWing().DestroySelf(); } else if (hit.collider.transform.root.tag == "FighterWing") { hit.collider.transform.root.GetComponent <FighterWing>().DestroySelf(); } } } else if (DummyUnit != null && !ScreenElementsContains(mousePosition)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); //If we hit... if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (isPositionInPlayArea(hit.point)) { if (!PivotSet) { DummyUnit.transform.position = new Vector3(hit.point.x, 1f, hit.point.z); } if (Input.GetMouseButtonDown(0)) { PivotPoint = DummyUnit.transform.position; PivotSet = true; } else if (Input.GetMouseButton(0)) { Vector3 Direction = (new Vector3(hit.point.x, 1f, hit.point.z) - PivotPoint); if (Direction.magnitude > DummyUnitRadius) { Quaternion Rotation = Quaternion.LookRotation(Direction); DummyUnit.transform.rotation = Rotation; } } else if (Input.GetMouseButtonUp(0)) { if (SelectedUnityCategory == UnitCategory.Ships && selectedDesign != null) { ShipData shipData = new ShipData(selectedDesign); Ship newShip = ResourceManager.instance.CreateCombatShip(shipData, DummyUnit.transform.position, DummyUnit.transform.rotation); if (newShip != null) { if (PlayerSelected) { PlayerShipManager.AddSpaceUnit(newShip); PlayerFleet.AddShip(newShip.GetShipData()); } else if (EnemySelected) { EnemyShipManager.AddSpaceUnit(newShip); EnemyFleet.AddShip(newShip.GetShipData()); } else if (AllySelected) { AlliedShipManager.AddSpaceUnit(newShip); AlliedFleet.AddShip(newShip.GetShipData()); } else if (NeutralSelected) { NeutralShipManager.AddSpaceUnit(newShip); NeutralFleet.AddShip(newShip.GetShipData()); } } } else if (SelectedUnityCategory == UnitCategory.Stations && selectedStationDesign != null) { StationData stationData = new StationData(selectedStationDesign); Station newStation = ResourceManager.instance.CreateCombatStation(stationData, DummyUnit.transform.position, DummyUnit.transform.rotation); if (PlayerSelected) { PlayerShipManager.AddSpaceUnit(newStation); PlayerFleet.AddStation(newStation.stationData); } else if (EnemySelected) { EnemyShipManager.AddSpaceUnit(newStation); EnemyFleet.AddStation(newStation.stationData); } else if (AllySelected) { AlliedShipManager.AddSpaceUnit(newStation); AlliedFleet.AddStation(newStation.stationData); } else if (NeutralSelected) { NeutralShipManager.AddSpaceUnit(newStation); NeutralFleet.AddStation(newStation.stationData); } } else if (SelectedUnityCategory == UnitCategory.Fighters && selectedFighter != null) { FighterWing wing = ResourceManager.CreateFighterWing(); Fighter newFighter = ResourceManager.instance.CreateCombatFighter(selectedFighter, DummyUnit.transform.position, DummyUnit.transform.rotation); wing.addFighter(newFighter); List <Fighter> createdFighters = new List <Fighter>(); createdFighters.Add(newFighter); for (int i = 1; i < selectedFighter.MaxSquadronSize; i++) { Vector3 randomOffect = new Vector3(DummyUnit.transform.position.x + Random.Range(-0.5f, 0.5f), DummyUnit.transform.position.y + Random.Range(0.1f, 0.6f), DummyUnit.transform.position.z + Random.Range(-0.5f, 0.5f)); newFighter = ResourceManager.instance.CreateCombatFighter(selectedFighter, randomOffect, DummyUnit.transform.rotation); wing.addFighter(newFighter); createdFighters.Add(newFighter); } if (PlayerSelected) { PlayerShipManager.AddFighterWing(wing); foreach (Fighter fighter in createdFighters) { PlayerShipManager.AddSpaceUnit(fighter); } } else if (EnemySelected) { EnemyShipManager.AddFighterWing(wing); foreach (Fighter fighter in createdFighters) { EnemyShipManager.AddSpaceUnit(fighter); } } else if (AllySelected) { AlliedShipManager.AddFighterWing(wing); foreach (Fighter fighter in createdFighters) { AlliedShipManager.AddSpaceUnit(fighter); } } else if (NeutralSelected) { NeutralShipManager.AddFighterWing(wing); foreach (Fighter fighter in createdFighters) { NeutralShipManager.AddSpaceUnit(fighter); } } wing.SetNewGoalPosition(DummyUnit.transform.position); } PivotSet = false; } } } } else if (PickedUpObject != null && !ScreenElementsContains(mousePosition)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); //If we hit... if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (isPositionInPlayArea(hit.point)) { if (!PivotSet) { PickedUpObject.transform.position = new Vector3(hit.point.x, 1f, hit.point.z); } if (Input.GetMouseButtonDown(0)) { PivotPoint = PickedUpObject.transform.position; PivotSet = true; } else if (Input.GetMouseButton(0)) { Vector3 Direction = (new Vector3(hit.point.x, 1f, hit.point.z) - PivotPoint); if (Direction.magnitude > DummyUnitRadius) { Quaternion Rotation = Quaternion.LookRotation(Direction); PickedUpObject.transform.rotation = Rotation; } } else if (Input.GetMouseButtonUp(0)) { PickedUpObject = null; PivotSet = false; } } } } else if (miniMap.Contains(mousePosition)) { if (Input.GetMouseButton(0)) { combatCameraMover.GoTo(miniMap.GetWorldPosition(mousePosition)); } } else if (DummyUnit == null) { if (Input.GetMouseButtonUp(0)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); //If we hit... if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.collider.transform.root.tag == "Ship" || hit.collider.transform.root.tag == "Station") { PickedUpObject = hit.collider.transform.root.gameObject; PickedUpOrigin = hit.collider.transform.root.transform.position; } } } } } else if (!designDisplayWindow.isOpen()) { //Update the ships managers UpdateShipManagers(); combatTimer.CountUp(); doubleClickDetector.Update(); Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); storedUnitPanel.Update(); if (!ScreenElementsContains(mousePosition)) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { //Highlight hovered units if (hit.collider.transform.root.tag == "Ship" || hit.collider.transform.root.tag == "Station") { hit.collider.transform.root.GetComponent <SpaceUnit>().Hovered(); } else if (hit.collider.transform.root.tag == "Fighter") { hit.collider.transform.root.GetComponent <Fighter>().GetParentWing().Hovered(); } else if (hit.collider.transform.root.tag == "FighterWing") { hit.collider.transform.root.GetComponent <FighterWing>().Hovered(); } //Process abilities if (PlayerShipManager.AbilityActivite()) { if (hit.collider.transform.root.tag == "Ship") { Ship hoveredShip = hit.collider.transform.root.GetComponent <Ship>(); if (hoveredShip.ValidTransporterTarget(PlayerShipManager)) { if (PlayerShipManager.TransporterTargetingTroop) { //Cursor.SetCursor(ResourceManager.instance.GetIconTexture("Icon_TransportTroop"), Vector2.zero, CursorMode.Auto); if (Input.GetMouseButtonDown(0)) { PlayerShipManager.CastActiveAbility(hoveredShip); } } else if (PlayerShipManager.TransporterTargetingCrew) { //Cursor.SetCursor(ResourceManager.instance.GetIconTexture("Icon_TransportCrew"), Vector2.zero, CursorMode.Auto); if (Input.GetMouseButtonDown(0)) { PlayerShipManager.CastActiveAbility(hoveredShip); } } } } if (Input.GetMouseButtonDown(1)) { PlayerShipManager.ResetAbilities(); } } else //Normal movement and commands { if (Input.GetMouseButtonDown(0)) { //Cancel movement order if (PivotSet) { PivotSet = false; Object.Destroy(PivotObject); foreach (GameObject marker in DirectionMarkers) { Object.Destroy(marker); } DirectionMarkers.Clear(); } //Check if clicked a ship if (hit.collider.transform.root.tag == "Ship") { Ship ship = hit.collider.transform.root.GetComponent <Ship>(); if (ship.GetShipManager() == PlayerShipManager) { if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } if (doubleClickDetector.GetClicks() > 1) { PlayerShipManager.AddToSelection(ship.GetHull()); } else { PlayerShipManager.AddToSelection(ship); } combatCameraMover.SetFollowTarget(ship.gameObject); } else { PlayerShipManager.SelectUnownedShip(ship); } } else if (hit.collider.transform.root.tag == "Station") { Station station = hit.collider.transform.root.GetComponent <Station>(); if (station.GetShipManager() == PlayerShipManager) { if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } PlayerShipManager.AddToSelection(station); } else { PlayerShipManager.SelectUnownedStation(station); } } else if (hit.collider.transform.root.tag == "FighterWing") { FighterWing fighterWing = hit.collider.transform.root.GetComponent <FighterWing>(); if (fighterWing.GetShipManager() == PlayerShipManager) { if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } PlayerShipManager.AddToSelection(fighterWing); } else { PlayerShipManager.SelectUnownedFighter(fighterWing); } } else if (hit.collider.transform.root.tag == "Fighter") { Fighter fighter = hit.collider.transform.root.GetComponent <Fighter>(); if (fighter.GetShipManager() == PlayerShipManager) { if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } PlayerShipManager.AddToSelection(fighter); } else { PlayerShipManager.SelectUnownedFighter(fighter); } } else if (hit.collider.gameObject.tag == "PlayArea") { if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } shipDragSelectionBox.SetStart(Input.mousePosition); shipDragSelectionBox.SetActive(true); } } else if (Input.GetMouseButtonDown(1) && PlayerShipManager.HasSomethingSelected()) { if (hit.collider.gameObject.tag == "PlayArea") { if (isPositionInPlayArea(hit.point)) { PivotSet = true; PivotObject = new GameObject(); PivotObject.transform.position = hit.point; Vector3 shipGroupCenter; Vector3 sumVector = Vector3.zero; foreach (Ship ship in PlayerShipManager.GetSelectedShips()) { sumVector += ship.transform.position; } foreach (FighterWing fighterWing in PlayerShipManager.GetSelectedFighters()) { sumVector += fighterWing.transform.position; } shipGroupCenter = sumVector / PlayerShipManager.GetSelectedMobileUnitsCount(); Vector3 Direction = PivotObject.transform.position - shipGroupCenter; if (Direction != Vector3.zero) { Quaternion rotation = Quaternion.LookRotation(Direction, Vector3.up); PivotObject.transform.rotation = rotation; foreach (Ship ship in PlayerShipManager.GetSelectedShips()) { Vector3 markerPosition = ship.transform.position + Direction; //Try to keep ships 2 units apart foreach (GameObject markers in DirectionMarkers) { Vector3 otherMarkerDirection = markerPosition - markers.transform.position; if (otherMarkerDirection.sqrMagnitude < 4f) { markerPosition = markers.transform.position + otherMarkerDirection.normalized * 2f; } } GameObject marker = ResourceManager.CreateDirectionMarker(markerPosition); marker.transform.rotation = rotation; DirectionMarkers.Add(marker); //marker.transform.parent = PivotObject.transform; } foreach (FighterWing fighterWing in PlayerShipManager.GetSelectedFighters()) { GameObject marker = ResourceManager.CreateDirectionMarker(fighterWing.transform.position + Direction); marker.transform.rotation = rotation; DirectionMarkers.Add(marker); //marker.transform.parent = PivotObject.transform; } } } } else if (hit.collider.transform.root.tag == "Ship") { Ship ship = hit.collider.transform.root.GetComponent <Ship>(); PlayerShipManager.SetTargetForSelectedShips(ship); } else if (hit.collider.transform.root.tag == "Station") { Station station = hit.collider.transform.root.GetComponent <Station>(); PlayerShipManager.SetTargetForSelectedShips(station); } else if (hit.collider.transform.root.tag == "FighterWing") { FighterWing fighterWing = hit.collider.transform.root.GetComponent <FighterWing>(); PlayerShipManager.SetTargetForSelectedShips(fighterWing.GetFirstFighter()); } else if (hit.collider.transform.root.tag == "Fighter") { Fighter fighter = hit.collider.transform.root.GetComponent <Fighter>(); PlayerShipManager.SetTargetForSelectedShips(fighter); } } else if (Input.GetMouseButton(1) && PivotSet) { if (hit.collider.gameObject.tag == "PlayArea") { Vector3 Direction = hit.point - PivotObject.transform.position; if (Direction.sqrMagnitude > 1f) { Quaternion rotation = Quaternion.LookRotation(Direction, Vector3.up); PivotObject.transform.rotation = rotation; foreach (GameObject marker in DirectionMarkers) { marker.transform.rotation = rotation; } } } } else if (PivotSet) { if (hit.collider.gameObject.tag == "PlayArea") { List <Vector3> points = new List <Vector3>(); foreach (GameObject marker in DirectionMarkers) { points.Add(marker.transform.position); } PlayerShipManager.SetGoalPositionsForShips(points, PivotObject.transform.rotation); PivotSet = false; Object.Destroy(PivotObject); foreach (GameObject marker in DirectionMarkers) { Object.Destroy(marker); } DirectionMarkers.Clear(); } } } } //Drag left click if (Input.GetMouseButton(0)) { shipDragSelectionBox.SetEnd(Input.mousePosition); } else if (shipDragSelectionBox.isActive()) { //Deselect ships from before if (!Input.GetKey(KeyCode.LeftShift)) { PlayerShipManager.DeselectShips(); } shipDragSelectionBox.SetActive(false); shipDragSelectionBox.SelectShips(PlayerShipManager); } } else if (miniMap.Contains(mousePosition)) { if (Input.GetMouseButton(0)) { combatCameraMover.GoTo(miniMap.GetWorldPosition(mousePosition)); } } } }