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! It also includes code tools.
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!
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.
- Name: the name of the company.
- Web: the web address of the company.
- Email: the company email.
- Location: the physical location of the company.
- Address: the physical address of the company.
- Product name: the name of the product,
- Author name¹. This field can not be empty if you select ‘History‘ in the ‘Code‘ tab.
- Author email¹. This field can not be empty if you select ‘History‘ in the ‘Code‘ tab.
- Author web¹.
- Ask file name¹: a dialog is displayed asking for the file name.
- File name¹: the default file name.
- Select file¹: the new file is selected in the ‘Project’ window.
- 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.
- 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).
- The path where the file of your custom license is.
- History: Add a history section after the license.
- Spaces or TABs: use tabs or spaces to indent².
- Spaces: if you use spaces to indent, how many spaces to use.
- Indent style: ‘Kernighan and Ritchie‘ or ‘Allman‘ style.
- Space before brace: insert a space before brace.
- Namespace: the namespace of the project.
- Use #region: divide the code using regions.
- MonoBehavior: the new class inherits from MonoBehaviour.
- 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 select “Code Wizard” and then click on the template 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:
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:
‘Script Sonar‘ is the first of the many tools that we will add to ‘Code Wizard‘. With it you can find the objects of a scene that use your code.
To use ‘Script Sonar‘ just click on ‘Window > Ibuprogames > Code Wizard > Script Sonar‘
On the left you can see all your MonoBehaviuors that are used in the current scene. On the right, how many objects use them.
By clicking on the references, they will be automatically selected. If you click on the left, you will edit that file.