public void FindBuildingLocation() { Vector3 newLocation = RTSInterfacing.GetWorldPos3(Input.mousePosition); if (RTSInterfacing.HitPointIsGround(Input.mousePosition)) { tempBuilding.transform.position = newLocation; } }
// fires a ray into the world to find the first object we would hit, which should be the ground. // If the selection manager is over an existing Agent, then space is already occupied and so it cannot be built in. public bool CanPlaceBuilding() { bool canPlace = true; if (SelectionManager.MousedAgent || !RTSInterfacing.HitPointIsGround(tempBuilding.transform.position)) { canPlace = false; } return(canPlace); }
protected override void OnInitialize() { if (!Setted) { Setup(); } SelectionManager.Initialize(); RTSInterfacing.Initialize(); IsGathering = false; CurrentInterfacer = null; }
protected override void OnVisualize() { if (cachedCommander.CachedBuilderManager.IsFindingBuildingLocation()) { SelectionManager.CanBox = false; } else { SelectionManager.CanBox = true; } //Update the SelectionManager which handles box-selection. SelectionManager.Update(); //Update RTSInterfacing, a useful tool that automatically generates useful data for user-interfacing RTSInterfacing.Visualize(); if (IsGathering) { //We are currently gathering mouse information. The next click will trigger the command with the mouse position. //I.e. Press "T" to use the 'Psionic Storm' ability. Then left click on a position to activate it there. //Right click to cancel casting the abiility by setting IsGathering to false if (Input.GetMouseButtonDown(1)) { IsGathering = false; return; } //If we left click to release the ability //Or if the ability we're activating requires no mouse-based information (i.e. CurrentInterfacer.InformationGather) //Trigger the ability if (Input.GetMouseButtonDown(0) || CurrentInterfacer.InformationGather == InformationGatherType.None) { ProcessInterfacer(CurrentInterfacer); } } else { //We are not gathering information. Instead, allow quickcasted abilities with the mouse. I.e. Right click to move or attack. if (Input.GetKeyDown(KeyCode.Escape)) { OpenPauseMenu(); } MoveCamera(); RotateCamera(); MouseActivity(); } // } }
public static void FindStructureLocation() { Vector3 newLocation = RTSInterfacing.GetWorldPos3(Input.mousePosition); if (RTSInterfacing.HitPointIsGround(Input.mousePosition) && lastLocation != newLocation) { lastLocation = newLocation; tempStructure.transform.position = Positioning.GetSnappedPosition(newLocation); if (_constructingWall) { WallPositioningHelper.Visualize(); } } }
//LSF public static void ProcessInterfacer(AbilityDataItem facer) { Command com = RTSInterfacing.GetProcessInterfacer(facer); Send(com); }
protected override void OnVisualize() { if (Input.GetKeyDown(KeyCode.Space)) { var com = GetSpawnCommand(PlayerManager.MainController, _agentSpawnCode, RTSInterfacing.GetWorldPosD(Input.mousePosition)); CommandManager.SendCommand(com); } }
private void HandleSingleRightClick() { if (PlayerManager.MainController.GetCommanderHUD().MouseInBounds() && Selector.MainSelectedAgent && !ConstructionHandler.IsFindingBuildingLocation()) { if (Selector.MainSelectedAgent && Selector.MainSelectedAgent.IsOwnedBy(PlayerManager.MainController)) { if (Selector.MainSelectedAgent.GetAbility <Rally>() && !Selector.MainSelectedAgent.GetAbility <Structure>().NeedsConstruction) { if (Selector.MainSelectedAgent.GetAbility <Rally>().GetFlagState() == FlagState.SettingFlag) { Selector.MainSelectedAgent.GetAbility <Rally>().SetFlagState(FlagState.SetFlag); PlayerManager.MainController.GetCommanderHUD().SetCursorLock(false); PlayerManager.MainController.GetCommanderHUD().SetCursorState(CursorState.Select); } else { Vector2d rallyPoint = RTSInterfacing.GetWorldPosD(Input.mousePosition); Selector.MainSelectedAgent.GetAbility <Rally>().SetRallyPoint(rallyPoint.ToVector3()); } } if (RTSInterfacing.MousedAgent.IsNotNull()) { // if moused agent is a resource, send selected agent to harvest if (Selector.MainSelectedAgent.GetAbility <Harvest>() && RTSInterfacing.MousedAgent.MyAgentType == AgentType.Resource) { //call harvest command ProcessInterfacer((QuickHarvest)); } // moused agent is a building and owned by current player else if (RTSInterfacing.MousedAgent.MyAgentType == AgentType.Building && RTSInterfacing.MousedAgent.IsOwnedBy(PlayerManager.MainController)) { // moused agent isn't under construction if (!RTSInterfacing.MousedAgent.GetAbility <Structure>().NeedsConstruction) { // if moused agent is a harvester resource deposit, call harvest command to initiate deposit if (Selector.MainSelectedAgent.GetAbility <Harvest>() && Selector.MainSelectedAgent.GetAbility <Harvest>().GetCurrentLoad() > 0) { //call harvest command ProcessInterfacer((QuickHarvest)); } } // moused agent is still under construction else if (Selector.MainSelectedAgent.GetAbility <Construct>()) { //call build command ProcessInterfacer((QuickBuild)); } } else if (Selector.MainSelectedAgent.GetAbility <Attack>() && !RTSInterfacing.MousedAgent.IsOwnedBy(PlayerManager.MainController) && RTSInterfacing.MousedAgent.MyAgentType != AgentType.Resource) { //If the selected agent has Attack (the ability behind attacking) and the mouse is over an agent, send a target command - right clicking on a unit ProcessInterfacer((QuickTarget)); } } else { // If there is no agent under the mouse or the selected agent doesn't have Attack, send a Move command - right clicking on terrain // stop casting all abilities // Selector.MainSelectedAgent.StopCast(); ProcessInterfacer((QuickMove)); } } } }
protected override void OnVisualize() { if (ConstructionHandler.IsFindingBuildingLocation()) { SelectionManager.CanBox = false; } else { SelectionManager.CanBox = true; } //Update the SelectionManager which handles mouse-selection. SelectionManager.Update(); //Update RTSInterfacing, a useful tool that automatically generates useful data for user-interfacing RTSInterfacing.Visualize(); //Update Construction handler which handles placing buildings on a grid ConstructionHandler.Visualize(); if (IsGathering) { //We are currently gathering mouse information. The next click will trigger the command with the mouse position. //I.e. Press "T" to use the 'Psionic Storm' ability. Then left click on a position to activate it there. //Right click to cancel casting the abiility by setting IsGathering to false if (Input.GetMouseButtonDown(1)) { IsGathering = false; return; } //If we left click to release the ability //Or if the ability we're activating requires no mouse-based information (i.e. CurrentInterfacer.InformationGather) //Trigger the ability if (Input.GetMouseButtonDown(0) || CurrentInterfacer.InformationGather == InformationGatherType.None) { ProcessInterfacer(CurrentInterfacer); } } else { //We are not gathering information. Instead, allow quickcasted abilities with the mouse. I.e. Right click to move or attack. if (Input.GetKeyDown(KeyCode.Escape)) { OpenPauseMenu(); } MoveCamera(); // prevent user input if mouse is over hud bool mouseOverHud = PlayerManager.MainController.GetCommanderHUD()._mouseOverHud; if (!mouseOverHud) { // detect rotation amount if no agents selected & Right mouse button is down if (PlayerManager.MainController.SelectedAgents.Count <= 0 && Input.GetMouseButton(1) || Input.GetMouseButton(1) && Input.GetKeyDown(KeyCode.LeftAlt)) { // lock the cursor to prevent movement during rotation Cursor.lockState = CursorLockMode.Locked; RotateCamera(); } else { Cursor.lockState = CursorLockMode.None; } MouseHover(); if (Input.GetMouseButtonDown(0)) { if (Time.time < tapTimer + tapThreshold) { // left double click action OnDoubleLeftTapDown?.Invoke(); tap = false; return; } tap = true; tapTimer = Time.time; } // right click action else if (Input.GetMouseButtonDown(1)) { HandleSingleRightClick(); OnSingleRightTapDown?.Invoke(); } else if (Input.GetMouseButtonUp(0)) { _isDragging = false; OnLeftTapUp?.Invoke(); } if (tap == true && Time.time > tapTimer + tapThreshold) { tap = false; // left click hold action if (Input.GetMouseButton(0)) { if (OnLeftTapHoldDown != null) { _isDragging = true; OnLeftTapHoldDown(); } } else { // left click action HandleSingleLeftClick(); OnSingleLeftTapDown?.Invoke(); } } // other defined keys foreach (KeyValuePair <UserInputKeyMappings, KeyCode> inputKey in userInputKeys) { if (Input.GetKeyDown(inputKey.Value)) { switch (inputKey.Key) { // these should probably be switched to events... case UserInputKeyMappings.RotateLeftShortCut: ConstructionHandler.HandleRotationTap(UserInputKeyMappings.RotateLeftShortCut); break; case UserInputKeyMappings.RotateRightShortCut: ConstructionHandler.HandleRotationTap(UserInputKeyMappings.RotateRightShortCut); break; default: break; } } } } } }