示例#1
0
        private void Start()
        {
            AddCommand("help", "Lists all commands.", (args) => {
                Println("Commands:");
                foreach (string Action in Actions.Keys)
                {
                    Println("- " + Action);
                }
            });

            AddCommand("help (command)", "Describes the given command.", (args) => {
                // Check complete versions of the names (so you can do eg. help "help (command)")
                foreach (string Action in Actions.Keys)
                {
                    if (Action.Equals(args[0]))
                    {
                        Println(Actions[Action].Description);
                        return;
                    }
                }
                // Check just names
                foreach (string Action in Actions.Keys)
                {
                    string[] Parts = Action.Split(' ');
                    if (Parts[0].Equals(args[0]))
                    {
                        Println(Actions[Action].Description);
                        return;
                    }
                }
                Println("That command doesn't exist.");
            });

            AddCommand("print (text)", "Prints the given text.", (args) => {
                Println(args[0]);
            });

            AddCommand("shutdown", "Shuts the game down.", (args) => {
                if (Client.IsRunning())
                {
                    Client.Shutdown();
                }
                if (Server.IsRunning())
                {
                    Server.Shutdown();
                }
                Application.Quit();
            });

            Println("Use the \"help\" command for a list of commands.");

            // Set an accurate row length (if the panel is set)
            if (Panel != null && Panel.GetComponent <RectTransform>() != null)
            {
                float CharacterWidth = FontUtil.GetCharacterWidth(TextField.font,
                                                                  TextField.fontSize, TextField.fontStyle);
                float PanelWidth = Panel.GetComponent <RectTransform>().rect.width;
                RowLength = (int)(PanelWidth / CharacterWidth);
            }
        }