Code Wizard

 

Tired of changing the code generated by the Editor every time you create a C# class? ‘Code Wizard‘ can save you a lot of time!

 

UNITY ASSETS STORE ($5)

 

When you create a new MonoBehaviour in the Editor’s Project window, the code it generates looks something like this:

 

 

 

 

 

The result is not very useful. It dont include the namespace of your project, or that cool header of your company, or history, you dont like the code format, etc. You usually delete it and write it all from scratch, right?

Never again! With the help of ‘Code Wizard‘ and in just one click (actually two), you can have this:

 

 

Code Wizard‘ can save you a lot of time!

 

First steps.

Once installed, the first thing to do is configure it. You can do this by clicking on the menu Windows > Ibuprogames > Code Wizard Config. Any changes you make in this window will be automatically saved. If you work on several projects, you can create a configuration for each project. If you use a source revision control software (like Git or Subversion), add this file and your colleagues can use it too.

The first time it will ask if you want to create a new configuration file or use an existing one. Let’s create a new one. You have two sections for enter data, ‘Settings‘ and ‘Code‘. Let’s start with the first one.

 

  1. Name: the name of the company.
  2. Web: the web address of the company.
  3. Email: the company email.
  4. Location: the physical location of the company.
  5. Address: the physical address of the company.
  6. Product name: the name of the product,
  7. Author name¹. This field can not be empty if you select ‘History‘ in the ‘Code‘ tab.
  8. Author email¹. This field can not be empty if you select ‘History‘ in the ‘Code‘ tab.
  9. Author web¹.
  10. Ask file name¹: a dialog is displayed asking for the file name.
  11. File name¹: the default file name.
  12. Select file¹: the new file is selected in the ‘Project’ window.
  13. Ping file¹: the new file will be highlighted in the ‘Project’ window.

 

(¹): This information is local and will not be saved in the configuration file.

 

 

 

  1. License: select the software license that best suits your product. If you do not want to use any, select ‘No license‘. If you want to use your own, select ‘Custom‘ (see below).
  2. The path where the file of your custom license is.
  3. History: Add a history section after the license.
  4. Spaces or TABs: use tabs or spaces to indent².
  5. Spaces: if you use spaces to indent, how many spaces to use.
  6. Indent style: ‘Kernighan and Ritchie‘ or ‘Allman‘ style.
  7. Space before brace: insert a space before brace.
  8. Namespace: the namespace of the project.
  9. Use #region: divide the code using regions.
  10. MonoBehavior: the new class inherits from MonoBehaviour.
  11. Add some typical methods of MonoBehaviour.

 

(²): 80% of C# repos in Github use 4 spaces, 18% use tabs.

 

How to use it.

It is simple, once configured, create a new script as you usually do. But this time click on the ‘C# MonoBehaviour‘ option and Voilà! You have your new custom script ready!

 

 

 

How to use my own license.

If none of the licenses matches your project, you can use your own license. Just select ‘Custom‘ in ‘Licenses‘ and add a text file with your license. Each file can contain any of these keywords (between <>, both included, and case-sensitive), which ‘Code Wizard‘ will change:

 

  • <SHORT_DATE>: the current date, in short format (e.g. 12/29/2016).
  • <LONG_DATE>: the current date, in long format (e.g. Thursday, December 29, 2016).
  • <SHORT_TIME>: the current time, in short format (e.g. 5:00 PM).
  • <LONG_TIME>: the current time, in long format (e.g. 5:00:00 PM).
  • <YEAR>: the current year (e.g. 2017).
  • <DAY>: the current day (e.g. Thursday).

 

  • <COMPANY_NAME>: the company name.
  • <COMPANY_WEB>: the company web.
  • <COMPANY_EMAIL>: the company email.
  • <COMPANY_LOCATION>: the company location.
  • <COMPANY_ADDRESS>: the company address.

 

  • <PRODUCT_NAME>: the product commercial name.
  • <AUTHOR_NAME>: the author name.
  • <AUTHOR_WEB>: the author web.
  • <AUTHOR_EMAIL>: the author email.

 

  • <FILENAME>: the current file name and extension.

 

For example, a license like this:

 

<PRODUCT_NAME>.

COPYRIGHT (C) <YEAR> <COMPANY_NAME> – ALL RIGHTS RESERVED.
UNAUTHORIZED COPYING OF THIS FILE, VIA ANY MEDIUM IS STRICTLY PROHIBITED.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 

Would generate a template like this:

 

Happy coding!

You Might Also Like

No Comments

Leave a Reply