Tuesday, May 10, 2011

MonoDevelop file templates for Unity C# scripts

UPDATE(June 12, 2011): Added installation location description for MAC.

UPDATE(June 11, 2011): Added FAQ and one question/answer at the end of post.

UPDATE(May 11, 2011): Some last minute errors sneaked in template settings so MonoDevelop didn't load addin. Fixed version (0.81) is at new download link.

Description:
As the title says, here are some file templates for Unity, written in C#. It is initial version, I'm new to Unity and I didn't use all functions in practice, so this is some kind of... newbie template set :) If you have suggestions on how to improve them, or better yet you make some useful templates, feel free to share.

Installation:

Win XP
To install templates, extract package to "\MonoDevelop\Addins" folder and restart MonoDevelop (if it is already running).

MAC
To install templates, extract templates package and copy extracted folder to "Contents\MacOS\lib\monodevelop\AddIns" in MonoDevelop application package. Restart MonoDevelop (if it is already running).



MonoDevelop
To check if templates successfully loaded, go to New File dialog:

Here you should have few templates under QQ\Unity\C#:

If for some reason addin didn't successfully load on startup, go to Add-in Manager:

And try to Disable and Enable add-in, forcing it to reload:

Download:
Download here. Version 0.81

Links:
Reference on creating MonoDevelop file templates:
Monodevelop: Howto add a WinForm project and file template
Writing an Add-In - MonoDevelop
Extension Tree Reference - MonoDevelop
Forum:
Unity Forum thread

FAQ:

Q:
I used your package to develop my own template system, but, the package don't come in file menu, even when I disable/enable it. what's the problem?

A:
I made some tests and here are some conclusions.

On restart of MonoDevelop, if your .addin.xml has some errors or is not well formed xml file, MonoDevelop will not load it (if it has a cached working version of previous .addin.xml it will load that one).

Using enable/disable will not reload .addin.xml, only .xft.xml files. So if you make changes in .addin.xml and want to see them, you should restart MonoDevelop.

To know if changed .addin.xml has errors, you could change its 'name' and if you don't see in Add-in Manager a new name, but an old one, you know it didn't load because of errors, so previous cached file was loaded.

If some of .xtf.xml files didn't load, you can see in Message Log that there was a problem (Menu: View->Pads->Message Log). You will not see .addin.xml errors in Message Log.

If you can't find out what could be wrong with your .addin.xml you can contact me by email on my blog.

2 comments:

  1. Thanks ! I've been looking for this for some time.
    I like the proper C# bracketing :)

    One thing you could do to make it even more Unity compliant would be to add support for attributes like RequireComponent and AddComponentMenu.
    For example, adding the following right before the class declaration of the camera script :
    [AddComponentMenu ("Veloce/${Name}")] // Adds the script to a predefined category
    [RequireComponent (typeof (Camera))] // checks for a Camera component on the gameObject

    Cheers,

    ReplyDelete
  2. Excellent site, keep up the good work my colleagues would love this. I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog .
    If you love gaming for unity games kindly visit….
    Unity game templates

    ReplyDelete