Exemplo n.º 1
0
        void SetupConfigs()
        {
            IUnitConfigDataProvider database;

            //todo guard
            if (LSDatabaseManager.TryGetDatabase(out database))
            {
                ConfigElementData = database.UnitConfigElementData;
                ConfigElementMap  = new Dictionary <string, UnitConfigElementDataItem>();
                for (int i = 0; i < ConfigElementData.Length; i++)
                {
                    var item = ConfigElementData[i];
                    ConfigElementMap.Add(item.Name, item);
                }
                ConfigData = database.UnitConfigData;
                for (int i = 0; i < ConfigData.Length; i++)
                {
                    IUnitConfigDataItem item  = ConfigData[i];
                    LSAgent             agent = AgentController.GetAgentTemplate(item.Target);
                    for (int j = 0; j < item.Stats.Length; j++)
                    {
                        Stat stat = item.Stats[j];
                        //todo guard
                        var       element   = ConfigElementMap[stat.ConfigElement];
                        Component component = agent.GetComponent(element.ComponentType);
                        SetField(component, element.Field, stat.Value);
                    }
                }
            }
        }
 private static void GetMousedAgent()
 {
     if (MousedAgent != null)
     {
         MousedAgent.IsHighlighted = false;
         MousedAgent = null;
     }
     for (i = 0; i < PlayerManager.agentControllers.Count; i++)
     {
         AgentController agentController = PlayerManager.agentControllers [i];
         for (j = 0; j < AgentController.MaxAgents; j++)
         {
             if (agentController.AgentActive[j])
             {
                 curAgent = agentController.Agents[j];
                 if (curAgent.GetComponent <Renderer>().isVisible)
                 {
                     dif = new Vector2(
                         curAgent.transform.position.x - MouseWorldPosition.x,
                         curAgent.transform.position.z - MouseWorldPosition.y);
                     if ((dif.x * dif.x + dif.y * dif.y) <= (curAgent.SelectionRadius * curAgent.SelectionRadius))
                     {
                         MouseOver(curAgent);
                         break;
                     }
                 }
             }
         }
     }
 }
 private static void GetMousedAgent()
 {
     if (MousedAgent != null) {
         MousedAgent.IsHighlighted = false;
         MousedAgent = null;
     }
     for (i = 0; i < PlayerManager.agentControllers.Count; i++) {
         AgentController agentController = PlayerManager.agentControllers [i];
         for (j = 0; j < AgentController.MaxAgents; j++)
         {
             if (agentController.AgentActive[j])
             {
                 curAgent = agentController.Agents[j];
                 if (curAgent.GetComponent<Renderer>().isVisible) {
                     dif = new Vector2 (
                         curAgent.transform.position.x - MouseWorldPosition.x,
                         curAgent.transform.position.z - MouseWorldPosition.y);
                     if ((dif.x * dif.x + dif.y * dif.y) <= (curAgent.SelectionRadius * curAgent.SelectionRadius)) {
                         MouseOver (curAgent);
                         break;
                     }
                 }
             }
         }
     }
 }
        public static void Update()
        {
            MousePosition = Input.mousePosition;
            MouseWorldPosition = GetWorldPos (MousePosition);
            CanClearSelection = !Input.GetKey (KeyCode.LeftShift);

            if (Boxing) {
                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 = GetWorldPos (RaycastTopLeft);
                    Box_TopRight = GetWorldPos (RaycastTopRight);
                    Box_BottomLeft = GetWorldPos (RaycastBotLeft);
                    Box_BottomRight = GetWorldPos (RaycastBotRight);
                }

                MousedAgent = null;
                ClearBox ();

                for (i = 0; i < PlayerManager.agentControllers.Count; i++) {
                    AgentController agentController = PlayerManager.agentControllers [i];
                    for (j = 0; j < AgentController.MaxAgents; j++) {
                        if (agentController.AgentActive [j]) {
                            curAgent = agentController.Agents [j];
                            if (curAgent.GetComponent<Renderer>().isVisible) {
                                if (MousedAgent == null) {
                                    dif = new Vector2 (
                                    curAgent.transform.position.x - MouseWorldPosition.x,
                                    curAgent.transform.position.z - MouseWorldPosition.y);
                                    if ((dif.x * dif.x + dif.y * dif.y) <= (curAgent.SelectionRadius * curAgent.SelectionRadius)) {
                                        MouseOver (curAgent);
                                        BoxAgent (curAgent);
                                        continue;
                                    }
                                }

                                Vector2 agentPos = new Vector2 (curAgent.transform.position.x, curAgent.transform.position.z);
                                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) {
                                                BoxAgent (curAgent);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (Input.GetMouseButtonUp (0)) {

                    if (CanClearSelection)
                        ClearSelection ();
                    SelectBoxedAgents ();
                    Boxing = false;
                    ClearBox ();

                }

            } else if (InitializeBoxing) {
                GetMousedAgent ();
                InitializeTime += Time.deltaTime;
                if (InitializeTime >= MinimumClickTimeToBox) {
                    if (Input.GetMouseButton (0)) {
                        BoxEnd = MousePosition;
                        float Area = BoxEnd.x > BoxStart.x ? BoxEnd.x - BoxStart.x : BoxStart.x - BoxEnd.x;
                        float AreaMul = BoxEnd.y > BoxStart.y ? BoxEnd.y - BoxStart.y : BoxStart.y - BoxEnd.y;
                        Area *= AreaMul;
                        if (Area >= MinimumBoxArea) {
                            Boxing = true;
                            InitializeBoxing = false;
                            InitializeTime = 0f;
                        } else {
                            return;
                        }
                    } else {
                        QuickSelect ();
                    }
                    InitializeBoxing = false;
                    InitializeTime = 0f;
                } else {
                    GetMousedAgent ();
                    if (Input.GetMouseButtonUp (0)) {
                        QuickSelect ();
                    }
                }
            } else {
                GetMousedAgent ();
                if (Input.GetMouseButtonDown (0)) {
                    InitializeBoxing = true;
                    BoxStart = MousePosition;
                }
            }
        }