Code Wizard - Unity Asset Store - Nephasto

A set of tools to improve the quality of the code in the development of your games.

πŸ›’ Store

Code Wizard’ provides you with a set of very useful tools to improve your code and make your everyday life easier. These tools are:

  • 'Build History', collects information from all the builds you have made.
  • 'Code Templates', generate better and more personalized code templates with a single click.
  • 'Ensure That', shield your code against variables with unwanted values.
  • 'Code Sonar', easily find all your code used in the current scene and the objects that use them.

Build History

 

It keeps track of all the builds you do and shows you all the information that interests you. You can also export all the saved information to other systems using a CSV file. Open this tool in ‘Window > Nephasto > Code Wizard > Build History’ (or by pressing Ctrl/cmd + Alt + h) and you will see something like this:

 

At the top you will see a list with information about all the builds you make. The first column (1) shows whether the compilation finished successfully or not.

The next column (2) shows the platform of the build. The third and fourth columns show the date (3) and how long it lasted (4).

In the next two you can see how many files were processed (5) and the final size (6). The last column (8) informs you about how many errors and warnings occurred.

Finally, you can click on the trash icon (8) to delete that row.

By activating some of the checkbox at the bottom (9) you can activate a more visual way to see parameters such as duration, files, size and errors / warnings.

 

Finally you can import (10) / export (11) or delete all the data (12) by clicking on any of the buttons at the bottom.

Code Templates

 

When you create a new MonoBehaviour, the code generated by the Editor looks something like this:

 

Little useful and nothing sexy. It doesn’t include the namespace of your project, nor that cool header from your company, nor the history and you may not like the indentation of the code used either. Usually you delete it and write it all from scratch, right?

Never more! With the help of the ‘Code Template’ and with a single click (actually two), you will have something like this:

 

The first thing you should do is configure your preferences, opening ‘Editor > Project Settings > Code Wizard’ and selecting ‘Code Templates’.

 

First you must enter your data (1): name, email and website (optional). All this data is saved locally, so it will not interfere with other users of your version control.

The following are the company data (2): name, email, website and its location. Finally in ‘Product’ you can configure the name of the product.

The next thing you need to configure is how you want the code to be generated. The first is what type of license you want to use. If you can’t find any, you can create your own template by selecting ‘Custom’. If you do, you must create a text file and add it just below. In the file you can use all these keywords:

  • {SHORT_DATE}: the current date, in short format (eg 01/01/2077).
  • {LONG_DATE}: the current date, in long format (e.g. Thursday, December 29, 2077).
  • {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. 2077).
  • {DAY}: the current day (e.g. Thursday).
  • {COMPANY_NAME}: the name of the company.
  • {COMPANY_WEB}: the company’s website.
  • {COMPANY_EMAIL}: the company’s email.
  • {COMPANY_LOCATION}: the location of the company.
  • {COMPANY_ADDRESS}: the address of the company.
  • {PRODUCT_NAME}: the name of the product.
  • {AUTHOR_NAME}: the author who created the file.
  • {AUTHOR_WEB}: the author’s website.
  • {AUTHOR_EMAIL}: the author’s email.
  • {FILENAME}: the name of the current file and its extension.

For example, a custom 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.

I would generate code like this:

 

If you enable ‘History’, you will add the history section to the header. In ‘Coding style’ select if you want to use space (80% on Github) or TABs (18% on Githab) to indent the code blocks. You can change the style to indent code blocks in ‘Indent style’, which can be ‘Kernighan and Ritchie’ or ‘Allman ‘.

If you use a namespace, add it in ‘Namespace’. If you like using #region, enable them in ‘Use #region’. You can also automatically add the most used functions when creating a MonoBehavior if you activate ‘Add MB. methods ‘.

Finally you can configure the behavior of the tool in ‘Behaviour’. These settings will be saved locally. If you activate ‘Ask file name’, a dialog will open asking you the name of the file to create. If not, the default name will be used that you can change in ‘Default file name’. By activating ‘Select file’, the newly created file will be automatically selected in the ‘Project’ window of the Editor. You can also make it highlighted by activating ‘Ping file’.

When you have everything configured, creating new code files is as easy as creating a new file and selecting the ‘Code Templates’ options.

 

Ensure That

Ensure That’ is a game development oriented code library that extends the functionality of Assertions.Assert. An Assert allows you to test if the value of variables is as expected. If your requirements are not met, an Exception with information about the error would be thrown. These types of checks are usually only active in development versions.

For example, if we have a method within a MonoBehaviour that is in charge of processing the damage received to our player:

1
2
3
4
private void ProcessDamage(Bullet bullet)
{
  this.life -= bullet.damage;
}

What if bullet is null? What if ‘life’ is less than zero? By adding some checks to the beginning of the method we will know during development if any of this is happening.

1
2
3
4
5
6
7
private void ProcessDamage(Bullet bullet)
{
  Assert.IsNotNull(bullet, "The bullet cannot be null.");
  Assert.IsTrue(this.life > 0, "You're shooting at a corpse.");

  this.life -= bullet.damage;
}

Asserts are also useful for creating Unit Test of your games.

The problem is that Assertions.Assert has only eight methods and you possibly wish it had more and supported more types.

Stop dreaming and discover the more than 100 methods that ‘Ensure That’ offers you. All tested with their Unit Tests included in the asset. See the code in ‘Nephasto/CodeWizard/Runtime/EnsureThat’.

 

Here are some usage examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
private void AddToInventary(Item item, int slotIndex)
{
  EnsureThat.IsNotNull(item, "The item cannot be null.");
  EnsureThat.IsValidIndex(slotIndex, listSlots, $"Index {slotIndex} for '{nameof(listSlots)}'.");
  this.listSlots[slotIndex] = item;
}

private Item GetFirstItem()
{
  // Also check that it is not null ;)
  EnsureThat.NotEmpty(this.listSlots, $"'{nameof(listSlots)}' must not be empty.");
  return this.listSlots[0];
}

private List<Item> GetInventory()
{
  EnsureThat.AllNotNull(this.listSlots, $"'{nameof(listSlots)}' contains some null items.");
  return this.listSlots;
}

private Durability GetItemDurability(Item item)
{
  EnsureThat.HasComponent<Durability>(item, $"'{nameof(item)}' does not have the component 'Durability'.");
  return item.GetComponent<Durability>();
}

private void DoJump(Vector3 point)
{
  EnsureThat.DistanceIsLess(player.position, point, 10.0f, $"The point is too far.");
  player.Jump(point);
}

Code Sonar

 

With ‘Code Sonar’ you can easily find all the code used in the current scene and the objects that use it. Just click on “Window > Nephasto > Code Wizard > Code Sonar” (or hit Ctrl/cmd + Alt + s).

 

In the area on the left (1) you will see the scripts that are being used in the scene you have open. Click on any of them to access the editor quickly. On the right (2) you will see how many objects use them. Click on the text to select all the objects in the editor.

Any questions or suggestions you have, I will be happy to answer you in

hello@nephasto.com