Beispiel #1
0
    // ReSharper disable once UnusedMember.Local
    void OnEnable()
    {
        Instance = this;

        Application.logMessageReceivedThreaded += OnLogging;

        if (!_inited)
        {
            Log = EditorGUIUtility.Load("log.png") as Texture2D;
            Warn = EditorGUIUtility.Load("warn.png") as Texture2D;
            Error = EditorGUIUtility.Load("error.png") as Texture2D;
            
            _searchField = new SearchField();
            InitLogTree();
        }

        viewRect = position;
        float startY = pading * 2 + searchBarHeight;
        topTreeHeight = viewRect.height * verticalSplitterPercent - startY;
        _splitterRect = new Rect(0, viewRect.height * verticalSplitterPercent, viewRect.width, 5);
        bottomTreeHeight = viewRect.height - topTreeHeight - _splitterRect.height;

        RefreshShowingEntry();
        _inited = true;
    }
        private static void Main()
        {
            AdvancedConsole.Title = "Simple Commands System";

            // If you aren't using System.Console in your program
            // edit the SCS.System.AdvancedConsole class
            // and edit or don't use the SCS.Commands.ConsoleCommands class

            // Setting standard values
            Command.StandardPrefix      = "!";
            Command.StandardDescription = "No desc.";

            // The default of SCS.System.Command.StandardPrefix is "/"
            // It using for the help command from the SCS.MainCommands class

            // Preparing commands for use
            Command.RegisterCommands <MainCommands>();                            // 1 variant
            Command.RegisterCommands <ConsoleCommands>();
            Command.RegisterCommands(typeof(MathCommands), typeof(FileCommands)); // 2 variant

            // Writing "Enter !help to get a list of commands" with colored "!help"
            AdvancedConsole.ColoredWriteLine(new ColoredString("Enter "),
                                             new ColoredString(ConsoleColor.DarkCyan, "!"), new ColoredString(ConsoleColor.Cyan, "help "),
                                             new ColoredString("to get a list of commands. Don't use commas between arguments and use string arguments in quotes.\n"));

            while (true)
            {
                AdvancedConsole.Write("Enter a command: ");
                string message = AdvancedConsole.ReadLine();

                AdvancedConsole.WriteLine();
                Command.Execute(message); // Parses the message to a command and executes it
                AdvancedConsole.WriteLine();
            }
        }
 public static void WriteCommand(string path, string contents)
 {
     try
     {
         File.WriteAllText(path, contents);
     }
     catch (Exception e)
     {
         if (e is DirectoryNotFoundException)
         {
             AdvancedConsole.Warn("Directory Not Found!");
         }
         else if (e is PathTooLongException)
         {
             AdvancedConsole.Warn("Path Too Long!");
         }
         else if (e is UnauthorizedAccessException)
         {
             AdvancedConsole.Warn("Unauthorized Access!");
         }
         else
         {
             AdvancedConsole.Warn(AdvancedConsole.WarningType.WrongArguments);
         }
         return;
     }
     AdvancedConsole.WriteLine("Text successfully written!");
 }
 public static void ReadCommand(string path)
 {
     try
     {
         AdvancedConsole.WriteLine(File.ReadAllText(path));
     }
     catch (Exception e)
     {
         if (e is DirectoryNotFoundException)
         {
             AdvancedConsole.Warn("Directory Not Found!");
         }
         else if (e is FileNotFoundException)
         {
             AdvancedConsole.Warn("File Not Found!");
         }
         else if (e is PathTooLongException)
         {
             AdvancedConsole.Warn("Path Too Long!");
         }
         else if (e is UnauthorizedAccessException)
         {
             AdvancedConsole.Warn("Unauthorized Access!");
         }
         else
         {
             AdvancedConsole.Warn(AdvancedConsole.WarningType.WrongArguments);
         }
     }
 }
 public static void ComputeCommand(string expression)
 {
     try
     {
         using DataTable table = new DataTable();
         object result = table.Compute(expression, string.Empty);
         AdvancedConsole.WriteLine($"Result: {result}");
     }
     catch
     {
         AdvancedConsole.Warn("Wrong expression!");
     }
 }
 public static void RandomCommand(int minValue, int maxValue)
 {
     try
     {
         Random random = new Random();
         AdvancedConsole.WriteLine($"Result: {random.Next(minValue, maxValue)}");
     }
     catch (Exception e)
     {
         if (e is ArgumentOutOfRangeException)
         {
             AdvancedConsole.Warn("Wrong arguments! minValue cannot be greater than maxValue!");
         }
         else
         {
             AdvancedConsole.Warn(AdvancedConsole.WarningType.WrongArguments);
         }
     }
 }
 public static void RoundCommand(decimal a, int b) => AdvancedConsole.WriteLine($"Result: {Math.Round(a, b)}");
 public static void TanCommand(double a) => AdvancedConsole.WriteLine($"Result: {Math.Tan(a)}");
 public static void SqrtCommand(double a) => AdvancedConsole.WriteLine($"Result: {Math.Sqrt(a)}");
 public static void PowCommand(double a, double b) => AdvancedConsole.WriteLine($"Result: {Math.Pow(a, b)}");
        public static void RandomCommand(int maxValue)
        {
            Random random = new Random();

            AdvancedConsole.WriteLine($"Result: {random.Next(maxValue)}");
        }
        public static void HelpCommand(string prefix = null)
        {
            List <Command> commands;
            ListScanner    ignoreInHelpFilter = new ListScanner("Help Ignore", ListScanner.TargetOfScanner.Tags, ListScanner.ScannerCondition.NotContains);

            if (prefix != null && !Command.Prefixes.Contains(prefix))
            {
                if (Command.Prefixes.Count <= 1)
                {
                    AdvancedConsole.Warn(AdvancedConsole.WarningType.WrongArguments);
                }
                else
                {
                    AdvancedConsole.Warn("Invalid prefix!");
                }
                return;
            }

            if (prefix == null)
            {
                #region Colored text
                AdvancedConsole.ColoredWriteLine(new CStr("Command to enter:\n"), new CStr(ConsoleColor.DarkCyan, "prefix "),
                                                 new CStr(ConsoleColor.Cyan, "name "), new CStr(ConsoleColor.Magenta, "argument1 argument2 argumentN\n"));

                AdvancedConsole.ColoredWriteLine(new CStr("Command in help:\n"),
                                                 new CStr(ConsoleColor.DarkCyan, "prefix "), new CStr(ConsoleColor.Cyan, "name "),
                                                 new CStr(ConsoleColor.DarkYellow, "parameter-type1 "), new CStr(ConsoleColor.Yellow, "parameter-name1"), new CStr(", "),
                                                 new CStr(ConsoleColor.DarkYellow, "parameter-type2 "), new CStr(ConsoleColor.Yellow, "parameter-name2 "),
                                                 new ColoredString("= "), new CStr(ConsoleColor.Magenta, "default-value "), new CStr(ConsoleColor.DarkGray, "| Description.\n"));
                #endregion
            }

            if (Command.Prefixes.Count == 1)
            {
                prefix = Command.Prefixes[0];
            }

            if (prefix == null)
            {
                commands = Command.Find(ignoreInHelpFilter, new ListScanner("Help"));
            }
            else
            {
                ListScanner          ignoreHelpCommandsFilter = new ListScanner("Help", ListScanner.TargetOfScanner.Tags, ListScanner.ScannerCondition.NotContains);
                SimpleCommandScanner prefixFilter             = new SimpleCommandScanner(prefix, SimpleCommandScanner.TargetOfScanner.Prefix);

                commands = Command.Find(ignoreInHelpFilter, ignoreHelpCommandsFilter, prefixFilter);
            }

            AdvancedConsole.WriteLine(commands.Count > 0 ? "Commands:" : "Sorry, commands not found :(");
            foreach (Command command in commands)
            {
                AdvancedConsole.ColoredWrite(ConsoleColor.DarkCyan, command.Prefix);
                AdvancedConsole.ColoredWrite(ConsoleColor.Cyan, command.Name);

                foreach (ParameterInfo parameter in command.Parameters)
                {
                    AdvancedConsole.ColoredWrite(ConsoleColor.DarkYellow, " " + parameter.ParameterType.Name + " ");
                    AdvancedConsole.ColoredWrite(ConsoleColor.Yellow, parameter.Name);

                    if (parameter.HasDefaultValue)
                    {
                        AdvancedConsole.Write(" = ");
                        AdvancedConsole.ColoredWrite(ConsoleColor.Magenta, $"{parameter.DefaultValue ?? "null"}");
                    }
                    if (parameter != command.Parameters.Last())
                    {
                        AdvancedConsole.Write(",");
                    }
                }

                AdvancedConsole.ColoredWriteLine(ConsoleColor.DarkGray, $" | {command.Description}");
            }
        }