Script Generator for Unity Documentation


For the TL;DR watch the YouTube tutorial: https://www.youtube.com/watch?v=aUaLx3P2MxY

The plugin

I was doing with you tutorial for test-driven development and unity (http://blogs.unity3d.com/2014/06/03/unit-testing-part-2-unit-testing-monobehaviours/). I found that in order to write a tests that had all of the components for the humble object pattern I was forced to write 4 files every time I wanted to create a Mono Behavior. This quickly showed me that I needed to produce a templating system in the unity editor in order to produce these files every time. I then thought back to my earlier game development difficulties and realized that the ability to generate scripts with actually be an extremely helpful tool.

When putting together the system for templating I realized also that I have an organizational pattern in my projects. This pattern requires you to create a folder structure. That made it clear that the pattern should also work in the folder structure along with the templating system.

With the plugin you can now go to the create menu when building assets and select generate from template and a menu will pop up with the various templates available.

In order to replace text in the file path file names or content we put a pound sign in front and at the end of each string just like the templates that are in default Unity Scripts.

This plugin will be the first time I attempt to put anything on the Unity asset store let’s hope it makes it up there. This tool will be useful to me regardless and without it I cannot easily implement the humble object pattern with mono behaviors.

Dependencies

If you want to run the unit tests in the project, it depends on the Unity Testing Tools located here: https://www.assetstore.unity3d.com/en/#!/content/13802
Specifically the unit tests use NSubstitute

Using the Script Generator

To use the generator simply right click on a selected folder and go to Create > Generate From Template.

Then select the template you want to use. For this example I will use the Humble Object Template

Then the input parameter dialogue will come up. This is where you can enter new templatable values.

The files will all be generated and properly named

The values inside the scripts will also be named appropriately.

Creating New Templates

First create a file called Template.config
Inside you will put the Template Keys with # signs surrounding them.

Then a semicolon followed by a description.
You are now ready to create the script templates and folders.
For folders simply use the #key# value for folder names you want to template.


For files create the file name with the #key#values in the names as well as the file extension followed by .template.

`


Inside those files fill the information out. You can use #key# for values to be converted to strings. You can also use ##key# to lowercase the values before templating them. Allowing for style changes when working with the generated code.



Thanks for using our plugin. Please send me questions and information to @DeadyApps on twitter.



0 comments:

Post a Comment