protected override void OnInitialize() { if (!Setted) { Setup(); } SelectionManager.Initialize(); RTSInterfacing.Initialize(); IsGathering = false; CurrentInterfacer = null; }
private static void GetMousedAgent() { if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject()) { return; } //reimplement commander manager check, all controllers should have commander MouseOver(RTSInterfacing.GetScreenAgent(Input.mousePosition, (agent) => { return(agent.CanSelect); // && PlayerManager.ContainsController(agent.Controller); })); }
protected override void OnVisualize() { //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 (Selector.MainSelectedAgent != null) { if (Input.GetMouseButtonDown(1)) { if (RTSInterfacing.MousedAgent.IsNotNull() && Selector.MainSelectedAgent.GetAbility <Attack>() != null) { //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 ProcessInterfacer((QuickPos)); } } } } }
public static Command GetProcessInterfacer(AbilityDataItem facer) { if (facer == null) { Debug.LogError("Interfacer does not exist. Can't generate command."); return(null); } Command curCom = null; switch (facer.InformationGather) { case InformationGatherType.Position: curCom = new Command(facer.ListenInputID); curCom.Add <Vector2d>(RTSInterfacing.GetWorldPosD(Input.mousePosition)); break; case InformationGatherType.Target: curCom = new Command(facer.ListenInputID); if (RTSInterfacing.MousedAgent.IsNotNull()) { curCom.SetData <DefaultData>(new DefaultData(DataType.UShort, RTSInterfacing.MousedAgent.LocalID)); } break; case InformationGatherType.PositionOrTarget: curCom = new Command(facer.ListenInputID); if (RTSInterfacing.MousedAgent.IsNotNull()) { curCom.Add <DefaultData>(new DefaultData(DataType.UShort, RTSInterfacing.MousedAgent.GlobalID)); } break; case InformationGatherType.PositionOrAction: curCom = new Command(facer.ListenInputID); curCom.Add <Vector2d>(RTSInterfacing.GetWorldPosD(Input.mousePosition)); break; case InformationGatherType.None: curCom = new Command(facer.ListenInputID); break; } return(curCom); }
public static void Update() { MousePosition = Input.mousePosition; MouseWorldPosition = RTSInterfacing.GetWorldPos(MousePosition); GetMousedAgent(); if (Boxing) { if (CanBox) { BoxingTime += Time.deltaTime; if (MousePosition != BoxEnd) { Vector2 RaycastTopLeft; Vector2 RaycastTopRight; Vector2 RaycastBotLeft; Vector2 RaycastBotRight; BoxEnd = MousePosition; if (BoxStart.x < BoxEnd.x) { RaycastTopLeft.x = BoxStart.x; RaycastBotLeft.x = BoxStart.x; RaycastTopRight.x = BoxEnd.x; RaycastBotRight.x = BoxEnd.x; } else { RaycastTopLeft.x = BoxEnd.x; RaycastBotLeft.x = BoxEnd.x; RaycastTopRight.x = BoxStart.x; RaycastBotRight.x = BoxStart.x; } if (BoxStart.y < BoxEnd.y) { RaycastBotLeft.y = BoxStart.y; RaycastBotRight.y = BoxStart.y; RaycastTopLeft.y = BoxEnd.y; RaycastTopRight.y = BoxEnd.y; } else { RaycastBotLeft.y = BoxEnd.y; RaycastBotRight.y = BoxEnd.y; RaycastTopLeft.y = BoxStart.y; RaycastTopRight.y = BoxStart.y; } Box_TopLeft = RTSInterfacing.GetWorldPos(RaycastTopLeft); Box_TopRight = RTSInterfacing.GetWorldPos(RaycastTopRight); Box_BottomLeft = RTSInterfacing.GetWorldPos(RaycastBotLeft); Box_BottomRight = RTSInterfacing.GetWorldPos(RaycastBotRight); } ClearBox(); //int lecount = 0; if ((BoxEnd - BoxStart).sqrMagnitude >= MinBoxSqrDist) { bufferSelectedAgents.Clear(); for (int i = 0; i < PlayerManager.AgentControllerCount; i++) { var agentController = PlayerManager.GetAgentController(i); for (int j = 0; j < AgentController.MaxAgents; j++) { if (agentController.LocalAgentActive[j]) { curAgent = agentController.LocalAgents[j]; if (curAgent.CanSelect) { //always add mousedagent if (curAgent.RefEquals(MousedAgent)) { bufferSelectedAgents.Add(curAgent); } else if (curAgent.IsOwnedBy(PlayerManager.MainController)) { agentPos = curAgent.Position2; Edge = Box_TopRight - Box_TopLeft; Point = agentPos - Box_TopLeft; if (DotEdge() < 0) { Edge = Box_BottomRight - Box_TopRight; Point = agentPos - Box_TopRight; if (DotEdge() < 0) { Edge = Box_BottomLeft - Box_BottomRight; Point = agentPos - Box_BottomRight; if (DotEdge() < 0) { Edge = Box_TopLeft - Box_BottomLeft; Point = agentPos - Box_BottomLeft; if (DotEdge() < 0) { bufferSelectedAgents.Add(curAgent); continue; } } } } } } } } } if (bufferSelectedAgents.Count > 0) { int peakBoxPriority = bufferSelectedAgents.PeekMax().BoxPriority; while (bufferSelectedAgents.Count > 0) { RTSAgent agent = bufferSelectedAgents.PopMax(); if (agent.BoxPriority < peakBoxPriority) { break; } BoxAgent(agent); } } } else { BoxAgent(MousedAgent); } } if (Input.GetMouseButtonUp(0)) { if (!_selectionLocked && !Input.GetKey(KeyCode.LeftShift)) { ClearSelection(); } if (IsGathering == false) { SelectSelectedAgents(); } Boxing = false; } } }
public static void ProcessInterfacer(AbilityDataItem facer) { Command com = RTSInterfacing.GetProcessInterfacer(facer); Send(com); }