2012-12-30 73 views
0

我目前正在使用一个自定义渲染引擎,建立在XNA之上的项目来绘制UI元素,如:按钮,标签,面板等。Visual Studio 2010扩展:解析代码,渲染结果

发动机结构相对简单。有一个屏幕管理器,拥有几个游戏屏幕。一个游戏屏幕实现扩展名为GameView的引擎基类。 GameView类负责处理用户界面元素hirerarchy。

开发人员可以将一些UI控件添加到游戏视图的方式非常简单,它的逻辑是由ASP.NET控制雇主制定的。您必须重写一个名为LoadControls()的方法,创建所需控件的实例并将它们添加到GameView控件集合中。

下面的例子:

public override void LoadControls() 
    { 
     ImageFrame titleImage = new ImageFrame(); 
     titleImage.ID = "TitleImage"; 
     titleImage.Move(GameUI.Location(ViewLocation.CenterTop, -332, 4)); 
    titleImage.Width = 664; 
    titleImage.Height = 166; 
     titleImage.Image = "image_title"; 
     this.UI.Controls.Add(titleImage); 

     ImageFrame freeImage = new ImageFrame(); 
     freeImage.ID = "FreeImage"; 
     freeImage.Move(GameUI.Location(ViewLocation.CenterTop, 160, 95)); 
     freeImage.Width = 170; 
     freeImage.Height = 76; 
     freeImage.Image = "image_free"; 
     freeImage.IsVisible = GameContext.Current.IsTrialMode; 
     this.UI.Controls.Add(freeImage); 

     Button playButton = new Button(); 
     playButton.ID = "PlayGameButton"; 
     playButton.Width = 216; 
     playButton.Height = 96; 
     playButton.Move(GameUI.Location(ViewLocation.CenterTop, -108, 130)); 
     playButton.Text = GameContext.Current.Dictionary[StringKeys.PlayGameButtonText]; 
     playButton.Font = FontNames.Floraless1; 
     playButton.FontScale = 1.3f; 
     playButton.FontPressedColor = Color.White * .8f; 
     playButton.Click += new EventHandler<EventArgs>(PlayGameButton_Click); 
     this.UI.Controls.Add(playButton); 
    } 

创建UI与代码很容易,但是当你需要创建复杂的布局,这真的很难搞清楚的结果。我想知道是否有可能为VS2010开发一个自定义扩展,从而呈现我的GameView控件雇主的“视图”。我不需要创建一个UI设计器。我只需要在代码编辑器中阅读一些手工编写的代码,并在我仍处于Visual Studio(不运行该应用程序)的同时实时显示结果。

简而言之,扩展visual studio 2010以创建自定义的“设计器”,可实时分析.cs代码,从而生成渲染输出,这是可能的吗?

+0

是的。查看[Markdown Mode for Visual Studio 2010](http://visualstudiogallery.msdn.microsoft.com/0855e23e-4c4c-4c82-8b39-24ab5c5a7f79)以获取灵感。来源[here](https://github.com/noahric/markdownmode) – dtb

回答