Developer Console class
Inheritance: MonoBehaviour
Exemple #1
0
        private void Awake()
        {
#if UNITY_EDITOR
            _console = DeveloperConsole.Instance;
            GenerateCommands();
#endif
        }
 /// <summary>
 /// 绘制控制台
 /// </summary>
 public static void DrawConsole()
 {
     if (_showConsole)
     {
         DeveloperConsole.DrawGUI();
     }
 }
        /// <summary>
        /// 初始化框架
        /// </summary>
        public static void Initialize(MonoBehaviour behaviour, bool showConsole, System.Action <ELogLevel, string> logCallback)
        {
            if (behaviour == null)
            {
                throw new Exception("MotionFramework behaviour is null.");
            }
            if (_behaviour != null)
            {
                throw new Exception($"{nameof(MotionEngine)} is already initialized.");
            }

            UnityEngine.Object.DontDestroyOnLoad(behaviour.gameObject);
            _behaviour = behaviour;

            // 初始化控制台
            _showConsole = showConsole;
            if (showConsole)
            {
                DeveloperConsole.Initialize();
            }

            // 注册日志回调
            if (logCallback != null)
            {
                MotionLog.RegisterCallback(logCallback);
            }
        }
Exemple #4
0
        private void OnInputSubmitted(string input)
        {
            // First check that some input was submitted
            // If input is only whitespace, just clear the input and do nothing
            if (string.IsNullOrWhiteSpace(input))
            {
                InputField.text = string.Empty;
                InputField.ActivateInputField();
                return;
            }

            DeveloperConsole.Log($"{InputFieldPrefix.Text} {InputField.text}");

            mInputHistoryCache = string.Empty;
            mInputHistory.Insert(0, input);
            if (mInputHistory.Count > ConsoleSettings.MaxInputHistory)
            {
                mInputHistory.RemoveAt(mInputHistory.Count - 1);
            }

            // Copy input into the draft array
            mInputHistoryDraft.Clear();
            mInputHistoryDraft.AddRange(mInputHistory);

            mInputHistoryEdittingIndex = -1;
            InputField.text            = null;
            InputField.ActivateInputField();

            // Send the user's input to the console
            DeveloperConsole.Console.OnInputReceived(input);
        }
 void OnGUI()
 {
     // 绘制控制台
     if (Application.isEditor || Debug.isDebugBuild)
     {
         DeveloperConsole.Draw();
     }
 }
Exemple #6
0
        public void ProcessCommand_CommandDoesNotExist_CommandIsNotProcessed()
        {
            var mock    = new Mock <IConsoleCommand>();
            var console = new DeveloperConsole(prefix, Array.Empty <IConsoleCommand>());

            console.ProcessCommand($"{prefix}hi");

            mock.Verify(x => x.Process(Array.Empty <string>()), Times.Never());
        }
Exemple #7
0
    void Update()
    {
        GameObject selObj = UICamera.selectedObject;

        if ((selObj == null || (selObj != null && (!selObj.GetComponent <UIInput>() || selObj.transform.root.GetComponent <DeveloperConsole>()))) && (Input.GetKeyDown(KeyCode.BackQuote) || Input.GetKeyDown(KeyCode.F12)))
        {
            DeveloperConsole.ToggleConsole();
        }
    }
Exemple #8
0
        public override void Load()
        {
            Keyboard.SetKeyRepeat(true);

            Font TextFont  = new Font("Assets/Fonts/consola.ttf", 15);
            Font TitleFont = new Font("Assets/Fonts/consolab.ttf", 16);

            DevConsole = new DeveloperConsole();

            if (!Program.Preferences.Success)
            {
                Log(string.Format("ERROR: failed to load '{0}'", Preferences.Path));
            }
            else
            {
                Log(string.Format("Preferences: load '{0}'", Preferences.Path));
            }

            //  > Coolors: https://coolors.co/090c08-fff7f8-696d7d-ffe74c-ff5964-6369d1-6cae75-8b9474
            Language.Load("Assets/Languages");

            //  > Elements
            var te_2 = new TextEditor();

            te_2.SetFont(TextFont.Copy(), TitleFont);
            //te_2.SetFile( @"K:\Projets\C#\code-editor\Program.cs" );
            te_2.SetFile(@"K:\Projets\Lua/Löve2D/Sokoblob/main.lua");
            te_2.SetFractionPos(0, 0);
            te_2.SetFractionSize(.65f, 1);
            te_2.ComputeBounds();

            var te_1 = new TextEditor();

            te_1.SetFont(TextFont.Copy(), TitleFont);
            te_1.SetFile(@"K:\Projets\Python\test.py");
            te_1.SetFractionPos(te_2.FractionBounds.Width, 0);
            te_1.SetFractionSize(1 - te_2.FractionBounds.Width, .65f);
            te_1.ComputeBounds();

            DevConsole.SetFont(TextFont.Copy(), TitleFont);
            DevConsole.SetFractionPos(te_1.FractionBounds.X, te_1.FractionBounds.Y + te_1.FractionBounds.Height);
            DevConsole.SetFractionSize(te_1.FractionBounds.Width, 1 - te_1.FractionBounds.Height);
            DevConsole.ComputeBounds();

            //var te_3 = new TextEditor();
            //te_3.SetFont( TextFont, TitleFont );
            //te_3.SetFile( @"K:\Projets\Python\py-icewalker\main_1.py" );
            //te_3.SetPos( te_1.Bounds.X, te_1.Bounds.Y + te_1.Bounds.Height );
            //te_3.SetSize( te_1.Bounds.Width, Graphics.GetHeight() - te_1.Bounds.Height );
            //te_3.HighlighterTheme = highlighter;

            Elements.Focus(DevConsole);

            //  > Themes
            Theme.Load("Assets/Themes");
            SetTheme(Theme.Get(Program.Preferences.Theme));
        }
Exemple #9
0
        public override void Invoke(string data)
        {
            if (!MethodParser.TryParse(data, out var arguments))
            {
                // Failed to parse input. Show usage
                DeveloperConsole.Log(Help);
                return;
            }

            Method.Invoke(Target, arguments);
        }
Exemple #10
0
 public void ClickOnDeveloperConsole()
 {
     if (DeveloperConsole.Displayed)
     {
         DeveloperConsole.Click();
     }
     else
     {
         throw new Exception("Element is not found or not clickable");
     }
 }
Exemple #11
0
        public void ProcessCommand_CommandExists_CommandIsProcessed()
        {
            var mock = new Mock <IConsoleCommand>();

            mock.Setup(x => x.CommandWord).Returns("hi");
            var console = new DeveloperConsole(prefix, new IConsoleCommand[] { mock.Object });

            console.ProcessCommand($"{prefix}hi");

            mock.Verify(x => x.Process(Array.Empty <string>()), Times.Once());
        }
    private void OnConsoleAttached(DeveloperConsole.DeveloperConsole dc)
    {
        //Initialize console stuff here
        _developerConsole = dc;

        //Register commands
        dc.CommandDispatcher.RegisterCommand(
            new CommandDispatcher.Command("ping", "Prints 'pong!' in the console", ExampleCommandEventHandler), true);

        //Register Tick/KeyUp/KeyDown events after we have access to the console
        Tick += OnTick;
    }
        public virtual void Invoke(string data)
        {
            if (!MethodParser.TryParse(data, out var arguments))
            {
                // Failed to parse input. Show usage
                DeveloperConsole.LogWarning($"{MethodParser.CalculateUsage(Name)}\n" +
                                            $"Try '{typeof(HelpCommand).GetCustomAttribute<CommandAttribute>().Name} {Name}' for more information.");
                return;
            }

            Method.Invoke(Target, arguments);
        }
Exemple #14
0
            public void Invoke(string data)
            {
                var args = DeveloperConsole.SplitArgs(data);

                if (args.Length != 0)
                {
                    LogWarning(Help);
                }
                else
                {
                    DeveloperConsole.Log(DeveloperConsole.WorkingDirectory);
                }
            }
Exemple #15
0
    void Awake()
    {
        // 初始化应用
        InitAppliaction();

        // 初始化控制台
        if (Application.isEditor || Debug.isDebugBuild)
        {
            DeveloperConsole.Initialize();
        }

        // 初始化框架
        MotionEngine.Initialize(this, HandleMotionFrameworkLog);
    }
Exemple #16
0
 void Awake()
 {
     // Make sure there is only one instance of this singleton
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
         inputField.onEndEdit.AddListener(ParseTextInput);
         console = new GameConsole();
     }
 }
Exemple #17
0
    void Start()
    {
        enemyScript = FindObjectOfType <Enemies>();
        // Stats
        gameManagerScript = FindObjectOfType <GameManager>();
        playerScript      = FindObjectOfType <PlayerManager>();

        // Easter egg
        egg_buttonToCatch.gameObject.SetActive(false);
        egg_linkText.SetActive(false);

        // Console
        DeveloperConsole.SetActive(false);
        consoleActive = false;
    }
Exemple #18
0
 void CallConsole()
 {
     if (InputManager.Instance.OpenConsole)
     {
         if (consoleInstance != null)
         {
             consoleInstance.consoleCanvas.gameObject.SetActive(!consoleInstance.consoleCanvas.gameObject.activeInHierarchy);
         }
         else
         {
             consoleInstance = Instantiate(consolePrefab, consolePrefab.transform.position, Quaternion.identity);
             consoleInstance.consoleCanvas.gameObject.SetActive(true);
         }
     }
 }
Exemple #19
0
            public void Invoke(string data)
            {
                var args = DeveloperConsole.SplitArgs(data);

                if (args.Length > 1)
                {
                    LogWarning(kUsage);
                    return;
                }

                string dirPath;

                if (args.Length == 1)
                {
                    if (!TryNavigateDirectory(args[0], out dirPath))
                    {
                        // Inputted directory does not exist
                        LogWarning("not a directory");
                        return;
                    }
                }
                else
                {
                    dirPath = DeveloperConsole.WorkingDirectory;
                }

                // Get all directories and files in the current path and alphabetize
                var entries = Directory.GetFileSystemEntries(dirPath, "*", SearchOption.TopDirectoryOnly)
                              .OrderBy(e => e);

                // Write directories to console
                StringBuilder sb = new StringBuilder();

                foreach (var entry in entries)
                {
                    ConsoleUtilities.TryGetRelative(dirPath, entry, out var formatted);
                    if (Directory.Exists(entry))
                    {
                        formatted = $"<color=#{kDirectoryColorHtml}>{formatted}</color>";
                    }
                    sb.AppendLine(formatted);
                }

                DeveloperConsole.Log(sb.ToString());
            }
    void Awake()
    {
#if !UNITY_EDITOR
        SimulationOnEditor = false;
#endif

        // 初始化应用
        InitAppliaction();

        // 初始化控制台
        if (Application.isEditor || Debug.isDebugBuild)
        {
            DeveloperConsole.Initialize();
        }

        // 初始化框架
        MotionEngine.Initialize(this, HandleMotionFrameworkLog);
    }
Exemple #21
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;

            // setup text box etc
            clear(new string[0]);
            closeConsole(new string[0]);
            RegisterCommand("close", "Closes the developer console.", closeConsole);
            RegisterCommand("clear", "clears the developer console window.", clear);
            RegisterCommand("help", " (command) Displays help for a particular command or lists all commands available.", help);
        }
        else
        {
            Debug.LogError("Error: Two developer console instances have started!");
        }
    }
Exemple #22
0
    // A coroutine that will take and show the screenshot
    private IEnumerator ShowScreenshot()
    {
        yield return(new WaitForEndOfFrame());

        // Take a screenshot (in the form of a Texture2D)
        Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

        texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        texture.Apply();

        // Get a caption for the image containing the date
        var    now     = DateTime.Now;
        string caption = $"Taken on {now.ToString("dddd, dd MMMM yyyy")} at {now.ToString("HH:mm:ss")}";

        // Create ScreenShot entry
        var entry = DeveloperConsole.AppendEntry <ScreenshotEntry>(Resources.Load <GameObject>("Developer Console/Tests/ScreenshotEntry"));

        entry.SetData(texture, caption);
    }
Exemple #23
0
        public void Invoke(string data)
        {
            var args = DeveloperConsole.SplitArgs(data);

            if (args.Length == 0)
            {
                Invoke();
            }
            else
            {
                // Find a verb whose name is the first argument
                var verb = args[0].Trim().ToLower();

                foreach (var pair in mVerbs)
                {
                    if (pair.Key.Equals(verb))
                    {
                        pair.Value.Command.Invoke(data.Substring(DeveloperConsole.SplitPositions[0]));
                        return;
                    }
                }

                // No verb with that name
                DeveloperConsole.LogWarning($"'{Name}': no such verb with name '{args[0]}' could be found.");
                if (mVerbs.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Possible subcommands are: ");
                    var verbsAlphabetized = (from pair in mVerbs
                                             let v = pair.Value
                                                     orderby v.Name
                                                     select v);

                    foreach (var v in verbsAlphabetized)
                    {
                        sb.AppendLine($"    * {Name} {v.Name}");
                    }
                    DeveloperConsole.LogWarning(sb.ToString());
                }
            }
        }
Exemple #24
0
            public void Invoke(string data)
            {
                var args = DeveloperConsole.SplitArgs(data);

                if (args.Length == 0)
                {
                    DeveloperConsole.ChangeDirectory(DeveloperConsole.HomeDirectory);
                }
                else if (args.Length == 1)
                {
                    if (TryNavigateDirectory(args[0], out var newDir))
                    {
                        DeveloperConsole.ChangeDirectory(newDir);
                    }
                    else
                    {
                        LogWarning("not a directory");
                    }
                }
                else
                {
                    LogWarning(kUsage);
                }
            }
Exemple #25
0
 private void LogWarning(object message) => DeveloperConsole.LogWarning($"{kCommandName}: {message}");
Exemple #26
0
 private static void LogWarning(string commandName, object message) => DeveloperConsole.LogWarning($"{commandName}: {message}");
Exemple #27
0
 static void ClearConsoleOutput()
 {
     DeveloperConsole.Clear();
 }
Exemple #28
0
 // *This function is where all the code for the command is stored. In this example, the command prints a message to the console.
 public override void RunCommand()
 {
     DeveloperConsole.AddMessageToConsole("This is a test command. It is has been succesfully created!");
 }
 static void Test()
 {
     DeveloperConsole.ConsoleMessage("Hi");
 }
 /// <summary>
 ///     Register this script with the console
 /// </summary>
 /// <param name="s">The script to register</param>
 /// <param name="c">The console attached callback</param>
 public static void RegisterConsoleScript(this Script s, DeveloperConsole.DeveloperConsole.OnConsoleAttached c)
 {
     DeveloperConsole.DeveloperConsole.RegisterConsoleScript(s, c);
 }
Exemple #31
0
 void Start()
 {
     DeveloperConsole.ManualInit(cachedDC);
 }
Exemple #32
0
 /// <summary>
 /// Crée une nouvelle instance de MapEditorControler associé à la map donnée.
 /// </summary>
 public MapEditorControler(HumanControler baseControler)
 {
     m_baseControler = baseControler;
     m_minimap       = new Minimap(baseControler.MapRdr);
     m_console       = new DeveloperConsole(baseControler.EnhancedGuiManager);
 }