Visual Studio 2010扩展:解析代码,渲染结果

时间:2012-12-30 13:19:02

标签: c# visual-studio-2010 sdk xna designer

我目前正在开发一个项目,该项目使用在XNA之上构建的自定义渲染引擎来绘制UI元素,例如:按钮,标签,面板等。

发动机结构相对简单。有一个屏幕管理器,可以容纳几个游戏屏幕。实现了一个游戏屏幕,扩展了一个名为GameView的引擎基类。 GameView类负责处理UI元素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代码并生成渲染输出?

1 个答案:

答案 0 :(得分:0)

这可能会让您入门:Create custom Visual Studio designer