Exemplo n.º 1
0
        private static void GetMousedAgent()
        {
            if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            MouseOver(RTSInterfacing.GetScreenAgent(Input.mousePosition, (agent) =>
            {
                return(agent.CanSelect && PlayerManager.ContainsController(agent.Controller));
            }));
        }
        protected override void OnInitialize()
        {
            if (!Setted)
            {
                Setup();
            }
            SelectionManager.Initialize();

            RTSInterfacing.Initialize();
            IsGathering       = false;
            CurrentInterfacer = null;
        }
        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 <Scan>() != null)
                        {
                            //If the selected agent has Scan (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 Scan, send a Move command - right clicking on terrain
                            ProcessInterfacer((QuickPos));
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected override void OnVisualize()
        {
            SelectionManager.Update();

            if (CommandManager.sendType == SendState.None)
            {
                return;
            }
            RTSInterfacing.Visualize();

            if (IsGathering)
            {
                if (Input.GetMouseButtonDown(1))
                {
                    IsGathering = false;
                    return;
                }

                if (Input.GetMouseButtonDown(0) || CurrentInterfacer.InformationGather == InformationGatherType.None)
                {
                    ProcessInterfacer(CurrentInterfacer);
                }
            }
            else
            {
                if (Selector.MainSelectedAgent != null)
                {
                    if (Input.GetMouseButtonDown(1))
                    {
                        LSAgent target;
                        if (RTSInterfacing.MousedAgent.IsNotNull() &&
                            PlayerManager.GetAllegiance(RTSInterfacing.MousedAgent) == AllegianceType.Enemy &&
                            Selector.MainSelectedAgent.Scanner != null)
                        {
                            ProcessInterfacer((QuickTarget));
                        }
                        else
                        {
                            ProcessInterfacer((QuickPos));
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        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));
                }
                else
                {
                    curCom.Add <Vector2d>(RTSInterfacing.GetWorldPosD(Input.mousePosition));
                }
                break;

            case InformationGatherType.None:
                curCom = new Command(facer.ListenInputID);
                break;
            }

            return(curCom);
        }
        protected override void OnVisualize()
        {
            SelectionManager.Update();


            RTSInterfacing.Visualize();

            if (IsGathering)
            {
                if (Input.GetMouseButtonDown(1))
                {
                    IsGathering = false;
                    return;
                }

                if (Input.GetMouseButtonDown(0) || CurrentInterfacer.InformationGather == InformationGatherType.None)
                {
                    ProcessInterfacer(CurrentInterfacer);
                }
            }
            else
            {
                if (Selector.MainSelectedAgent != null)
                {
                    if (Input.GetMouseButtonDown(1))
                    {
                        //LSAgent target;
                        if (RTSInterfacing.MousedAgent.IsNotNull() &&
                            Selector.MainSelectedAgent.GetAbility <Scan>() != null)
                        {
                            ProcessInterfacer((QuickTarget));
                        }
                        else
                        {
                            ProcessInterfacer((QuickPos));
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        private static void ProcessInterfacer(AbilityDataItem facer)
        {
            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));
                }
                else
                {
                    curCom.Add <Vector2d>(RTSInterfacing.GetWorldPosD(Input.mousePosition));
                }
                break;

            case InformationGatherType.None:
                curCom = new Command(facer.ListenInputID);
                break;
            }

            Send(curCom);
        }
        public static void ProcessInterfacer(AbilityDataItem facer)
        {
            Command com = RTSInterfacing.GetProcessInterfacer(facer);

            Send(com);
        }
Exemplo n.º 9
0
        public static void Update()
        {
            MousePosition      = Input.mousePosition;
            MouseWorldPosition = RTSInterfacing.GetWorldPos(MousePosition);
            CanClearSelection  = !Input.GetKey(KeyCode.LeftShift);
            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)
                    {
                        bufferBoxedAgents.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)
                                    {
                                        if (curAgent.RefEquals(MousedAgent))
                                        {
                                            bufferBoxedAgents.Add(curAgent);
                                        }
                                        else
                                        {
                                            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)
                                                        {
                                                            bufferBoxedAgents.Add(curAgent);
                                                            continue;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        bufferBoxable.FastClear();
                        //bool noneBoxable = true;
                        if (bufferBoxedAgents.Count > 0)
                        {
                            int peakBoxPriority = bufferBoxedAgents.PeekMax().BoxPriority;
                            while (bufferBoxedAgents.Count > 0)
                            {
                                LSAgent agent = bufferBoxedAgents.PopMax();
                                if (agent.BoxPriority < peakBoxPriority)
                                {
                                    break;
                                }
                                BoxAgent(agent);
                            }
                        }
                    }
                    else
                    {
                        BoxAgent(MousedAgent);
                    }
                }
                if (Input.GetMouseButtonUp(0))
                {
                    if (CanClearSelection)
                    {
                        ClearSelection();
                    }
                    if (IsGathering == false)
                    {
                        SelectBoxedAgents();
                    }

                    Boxing = false;
                }
            }
            else
            {
                if (IsGathering == false && Input.GetMouseButtonDown(0))
                {
                    _checkBoxDistance = true;
                    StartBoxing(MousePosition);
                }
            }
        }
Exemplo n.º 10
0
 private static void GetMousedAgent()
 {
     MouseOver(RTSInterfacing.GetScreenAgent(Input.mousePosition, (agent) => {
         return(agent.CanSelect && PlayerManager.ContainsController(agent.Controller));
     }));
 }