コード例 #1
0
    void LateUpdate()
    {
        // exit ui and building mode
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (BuildManager.placing)
            {
                BuildManager.EndPlacing();
            }
            else if (ChatManager.IsChatActive())
            {
                ChatManager.ToggleChat();
            }
            else
            {
                if (uiManager.InMenu())
                {
                    uiManager.ExitMenu();
                }
                else if (uiManager.HideObjectInfo())
                {
                }
                else if (uiManager.HidePersonInfo())
                {
                }
                else
                {
                    uiManager.ShowMenu(6);
                }
            }
        }

        if (!ChatManager.IsChatActive())
        {
            // open build menu if exactly one person is selected
            if (Input.GetKeyDown(KeyCode.B))
            {
                if (PersonScript.selectedPeople.Count == 1)
                {
                    uiManager.ShowMenu(7);
                }
            }

            // open job overview if no person selected
            if (Input.GetKeyDown(KeyCode.J))
            {
                if (PersonScript.selectedPeople.Count == 0)
                {
                    uiManager.ShowMenu(1);
                    uiManager.OnPopulationTab(1);
                }
            }

            // open minimap overview
            if (Input.GetKeyDown(KeyCode.M))
            {
                uiManager.ToggleMiniMap();
            }

            BuildingScript selb = uiManager.GetSelectedBuilding();
            // destroy building if selected
            if (Input.GetKeyDown(KeyCode.Period))
            {
                if (selb && !BuildManager.placing)
                {
                    /* TODO: show warning when destroying buildings */
                    //selb.DestroyBuilding();
                }
            }
            // move building if selected
            if (Input.GetKeyDown(KeyCode.Comma))
            {
                if (selb && !BuildManager.placing)
                {
                    BuildManager.StartMoving(selb);
                }
            }

            // Toggle Cheats
            if (Input.GetKeyDown(KeyCode.O))
            {
                GameManager.ToggleDebugging();
                ChatManager.Msg("Cheats " + (GameManager.IsDebugging() ? "aktiviert" : "deaktiviert"), MessageType.Debug);
            }

            // Toggle Deubg window
            if (Input.GetKeyDown(KeyCode.P))
            {
                UIManager.Instance.ShowMenu(10);
            }

            // Person Groups
            int numberInput = -1;
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                numberInput = 0;
            }
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                numberInput = 1;
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                numberInput = 2;
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                numberInput = 3;
            }
            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                numberInput = 4;
            }
            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                numberInput = 5;
            }
            if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                numberInput = 6;
            }
            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                numberInput = 7;
            }
            if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                numberInput = 8;
            }
            if (Input.GetKeyDown(KeyCode.Alpha9))
            {
                numberInput = 9;
            }

            if (numberInput >= 0)
            {
                List <int> group = GameManager.GetPeopleGroup(numberInput);
                if (Input.GetKey(KeyCode.LeftControl))
                {
                    group = new List <int>();
                    foreach (PersonScript ps in PersonScript.selectedPeople)
                    {
                        group.Add(ps.Nr);
                    }
                    GameManager.SetPeopleGroup(numberInput, group);
                    ChatManager.Msg("Personengruppe " + numberInput + " erstellt!");
                }
                else
                {
                    PersonScript.DeselectAll();
                    if (group != null)
                    {
                        foreach (PersonScript ps in PersonScript.allPeople)
                        {
                            if (group.Contains(ps.Nr))
                            {
                                ps.OnSelect();
                            }
                        }
                    }
                }
            }
        }
        // enter chat
        if (!IsInputFieldFocused() && Input.GetKeyDown(KeyCode.Return))
        {
            ChatManager.CommitMsg();
            ChatManager.ToggleChat();
        }

        // if click is not already handled, select units
        SelectUnits();

        LeftClickHandled  = false;
        RightClickHandled = false;
    }