2012-12-30 67 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

回答