Adding Code Files to a Game Project
Introduction
This tutorial will cover how to add files to a project using FlatRedBall plugins. We will be adding .cs files to a project when the project is initially loaded.
Creating a project
The first step is to create a Glue Plugin project. To do this:
Launch the NewProjectCreator through the start menu.
Select "Glue Plugin Template"
Enter the project name
Select the location
Click "Make my project!"
Adding files to projects
Next we'll add files that we want added to our project. To do this:
Create one or more files that you would like to include through your plugin
Add these files into your plugin project
For each file in your project, right-click and select "Properties"
Change "Build Action" to "Embedded Resource"
Editing the PluginBase-inheriting Class
Once you've added the files you want to include we'll write the code to include these files in projects that Glue is managing. First, add an instance of a CodeBuildItemAdder:
Next we'll write the code to add the "Embedded Resource" files to the project managed by Glue. Add the following code to your plugin class' StartUp method:
The code above is pulled from a project where the project name is StateInterpolationPlugin, and the files Back.cs and Bounce.cs were added directly in the project (as opposed to being added in a folder). If the files are added in a folder (such as MyFolder) then you will need to change the file names (such as "StateInterpolationPlugin.MyFolder.Back.cs"). After making the "Add" calls, we need to tell the CodeBuildItemAdder where to save the files in the project that it is going to modify. To do this, add the following call:
This will result in the files being placed in a folder called "DesiredOutputFolder". Finally we'll need to tell Glue that these files should be added to the project. To do this:
Troubleshooting
If your files do not show up, you can troubleshoot the process as follows:
Look at the output window of Glue - if your plugin has crashed then Glue will display a callstack
Put try/catch statements around relevant code, such as PerformAddAndSave, and see the exception message for more information on what might be happening
Select Plugins->Manage Plugins to see all plugins and investigate any failures which may have occurred.
Conclusion
That's all there is to it. Now all of the code items marked as Embedded Resource and added to the CodeBuildItemAdder will be added to any project loaded with Glue when the plugin is installed.
Last updated