コード例 #1
0
 /// <summary>
 /// Awake function getting all the references in need and also adding a few basic commands
 /// </summary>
 protected override void Awake()
 {
     _graphData = new Queue <float>();
     MemoryTracer.SetDebugComponent(this);
     _consoleOutBuffer = new Queue <string>();
     _consoleOutBuffer.Enqueue("Console Initialized..");
     _title         = Owner.GetChildWithName("Title").GetComponent <UITextRendererComponent>();
     _consoleInput  = Owner.GetChildWithName("ConsoleInput").GetComponent <UITextRendererComponent>();
     _consoleOutput = Owner.GetChildWithName("ConsoleOutput").GetComponent <UITextRendererComponent>();
     _bgImage       = Owner.GetChildWithName("BackgroundImage").GetComponent <UIImageRendererComponent>();
     _hintText      = Owner.GetChildWithName("HintText").GetComponent <UITextRendererComponent>();
     _graph         = Owner.GetChildWithName("Graph").GetComponent <GraphDrawingComponent>();
     (_graph.Context as GraphDrawingContext).Enabled = false;
     _consoleOutputImage =
         Owner.GetChildWithName("BackgroundOutputImage").GetComponent <UIImageRendererComponent>();
     _sb    = new StringBuilder();
     _outSB = new StringBuilder();
     AddCommand("help", cmd_ListCmds);
     AddCommand("h", cmd_ListCmds);
     AddCommand("q", cmd_Exit);
     AddCommand("exit", cmd_Exit);
     AddCommand("quit", cmd_Exit);
     AddCommand("cls", cmd_Clear);
     AddCommand("clear", cmd_Clear);
     AddCommand("lmem", MemoryTracer.cmdListMemoryInfo);
     AddCommand("llmem", MemoryTracer.cmdListLastMemoryInfo);
     AddCommand("cmd", cmdExOnConsole);
     AddCommand("tg", cmd_ToggleGraph);
     AddCommand("togglegraph", cmd_ToggleGraph);
 }
コード例 #2
0
        /// <summary>
        /// Static function that will assemble the Console
        /// </summary>
        /// <returns>A gameobject ready to be added to the game</returns>
        public static GameObject CreateConsole()
        {
            ShaderProgram.TryCreate(new Dictionary <ShaderType, string>
            {
                { ShaderType.FragmentShader, "shader/UITextRender.fs" },
                { ShaderType.VertexShader, "shader/UITextRender.vs" }
            }, out ShaderProgram textShader);

            ShaderProgram.TryCreate(new Dictionary <ShaderType, string>
            {
                { ShaderType.FragmentShader, "shader/UIRender.fs" },
                { ShaderType.VertexShader, "shader/UIRender.vs" }
            }, out ShaderProgram uiShader);

            ShaderProgram.TryCreate(new Dictionary <ShaderType, string>
            {
                { ShaderType.FragmentShader, "shader/graph.fs" },
                { ShaderType.VertexShader, "shader/graph.vs" }
            }, out ShaderProgram graphShader);

            GameObject obj       = new GameObject("Console");
            GameObject _in       = new GameObject("ConsoleInput");
            GameObject _out      = new GameObject("ConsoleOutput");
            GameObject _titleObj = new GameObject("Title");
            GameObject _bgObj    = new GameObject("BackgroundImage");
            GameObject _bgOutObj = new GameObject("BackgroundOutputImage");
            GameObject _hint     = new GameObject("HintText");
            GameObject _graph    = new GameObject("Graph");

            obj.Add(_in);
            obj.Add(_out);
            obj.Add(_titleObj);
            obj.Add(_bgObj);
            obj.Add(_hint);
            obj.Add(_bgOutObj);
            obj.Add(_graph);

            rt = new RenderTarget(null, 1 << 29, new Color(0, 0, 0, 0));
            GameEngine.Instance.AddRenderTarget(rt);

            rt2 = new RenderTarget(null, 1 << 28, new Color(0, 0, 0, 0));
            GameEngine.Instance.AddRenderTarget(rt2);

            Bitmap bmp = new Bitmap(1, 1);

            bmp.SetPixel(0, 0, System.Drawing.Color.Black);

            UIImageRendererComponent _bgImage =
                new UIImageRendererComponent(TextureLoader.BitmapToTexture(bmp), false,
                                             0.65f, uiShader);

            UIImageRendererComponent _bgOutImage =
                new UIImageRendererComponent(TextureLoader.BitmapToTexture(bmp), false, 0.4f,
                                             uiShader);


            UITextRendererComponent _tText = new UITextRendererComponent(GameFont.DefaultFont, false, 1f, textShader)
            {
                Text = "GameEngine Console:"
            };
            UITextRendererComponent _tHint = new UITextRendererComponent(GameFont.DefaultFont, false, 1f, textShader)
            {
                Text = "GameEngine Console:"
            };

            UITextRendererComponent _tIn = new UITextRendererComponent(GameFont.DefaultFont, false, 1f, textShader)
            {
                Text = ""
            };

            UITextRendererComponent _tOut = new UITextRendererComponent(GameFont.DefaultFont, false, 1f, textShader)
            {
                Text = "Console Initialized.."
            };

            GraphDrawingComponent _gDraw = new GraphDrawingComponent(graphShader, false, 1f);

            _bgOutObj.AddComponent(_bgOutImage);
            _bgObj.AddComponent(_bgImage);
            _graph.AddComponent(_gDraw);
            _in.AddComponent(_tIn);
            _out.AddComponent(_tOut);
            _titleObj.AddComponent(_tText);
            _hint.AddComponent(_tHint);

            _gDraw.Scale    = new Vector2(0.5f, 0.5f);
            _gDraw.Position = new Vector2(0.5f);
            _gDraw.Points   = new[]
            {
                new Vector2(0f, 0f),
                new Vector2(1f, 1f),
            };

            _tText.Position = new Vector2(-0.39f, 0.353f);
            _tText.Scale    = new Vector2(2f, 2f);

            _tOut.Position = new Vector2(-0.33f, 0.31f);
            _tOut.Scale    = new Vector2(0.8f, 0.8f);

            _tIn.Position = new Vector2(-0.39f, -0.39f);
            _tIn.Scale    = new Vector2(1.5f, 1.5f);


            _tHint.Position = new Vector2(-0.46f, -0.46f);
            _tHint.Scale    = new Vector2(1.5f, 1.5f);


            _bgImage.Scale    = new Vector2(0.8f);
            _bgOutImage.Scale = new Vector2(0.7f);

            obj.AddComponent(new DebugConsoleComponent());
            return(obj);
        }