Esempio n. 1
0
        // do double click things
        public static void HandleDoubleLeftClickDown()
        {
            Boxing = false;
            if (MousedAgent)
            {
                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)
                            {
                                if (curAgent.IsVisible &&
                                    curAgent.objectName == MousedAgent.objectName &&
                                    curAgent.IsOwnedBy(PlayerManager.MainController))
                                {
                                    bufferSelectedAgents.Add(curAgent);
                                }
                            }
                        }
                    }
                }

                if (bufferSelectedAgents.Count > 0)
                {
                    int peakBoxPriority = bufferSelectedAgents.PeekMax().BoxPriority;
                    while (bufferSelectedAgents.Count > 0)
                    {
                        RTSAgent agent = bufferSelectedAgents.PopMax();
                        if (agent.BoxPriority < peakBoxPriority)
                        {
                            break;
                        }
                        BoxAgent(agent);
                    }

                    SelectSelectedAgents();
                }
            }
        }
Esempio n. 2
0
        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;
                }
            }
        }