PolyLabs | Version 1.2 | Nov 3, 2020 | support@polylabs.co
File Generator Pro is a rethinking of the built-in script creation system in Unity. When developing games, you'll find that many of your files aren't MonoBehaviours, but the Create C# Script option in Unity only provides the ability to create a default class deriving from MonoBehaviour.
File Generator Pro enables you to create classes, interfaces, enums, and structs. It is capable validating classes and implementing complex inheritance on file creation, and even allows you to create multiple classes at once using the batch tool! Additionally, this tool has the ability to generate general-purpose files such as JSON, XML, Text, and even Markdown files.
File Generator Pro has two primary ways of being utilized; via the top menu and the project window context-menu.
To open the tool using the top menu, navigate to Tools => File Generator Pro => New File...
In the Project window, you can either select the Create dropdown, or select any folder in your hierarcy where you would like to create a file and right-click Create => File Generator Pro => NewFile...
Selecting on a file or directory in the Assets folder will result in the source destination to default to the currently selected object in the project hierarchy.
Note: You can still change the file destination at any time!
Clicking on any icon in the selection menu will navigate to the appropriate creation menu.
Class Name: the name of the class you will be creating. This will also be the name of the resulting file.
Access: the access of a C# entity defines its visibility to other classes. Public is selected by default.
Class Type: defines whether the class is a default (concrete) class, abstract, or static.
Super Class: the super (base, parent, etc..) class that will be inherited from. Depending on the preferences, the generated class will attempt to implement any unimplemented abstract methods for you.
Namespace: the namespace that this class will belong to.
Interfaces: This is a list container for all of the interfaces that this class will implement. Interfaces can be listed in any way that feels comfortable, as long as they are separated by a comma, space, or newline (or any combination of the three).
Default Imports: The default imports that are pre-generated in all Unity C# files.
xxxxxxxxxx
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
System.Serializable: should the class be serializable?
Default Constructor: should the generator create a default constructor for the class?
The source folder is selected by using the Browse.. button. Something to note is that the source file can only be created within the Assets folder.
Selecting Create & Open will generate the file and open it in the default code editor set in the Unity preferences.
Interface Name: the desired name of the interface.
Access: the visibility of the interface to other entities.
Namespace: the namespace that this interface will reside in.
Interfaces: the interfaces that this interface will be inheriting from or extending.
Enum Name: the name of the enum to be created.
Access: the visibility of the enum type.
Namespace: the namespace that this enum will belong to.
Enum Values: similar to the interface text boxes, you can input the values you want the enum to contain, and they will be automatically added to the code.
System.Serializable: should the enum be serializable?
Struct Name: the name of the struct to be created.
Namespace: the namespace that this struct will belong to.
Access: the visibility of this struct.
System.Serializable: should the struct be serializable?
Class Names: similar to the interface text boxes, you can insert the names of the classes you want to create using commas, spaces, and newlines (in any combination).
Access: the visibility of the classes being created.
Class Type: will the classes be concrete (default), abstract, or static?
Super Class: the base class that all the classes will derive from.
Interfaces: a list of interfaces that the classess will implement
System.Serializable: are the classes going to be serializable?
Default Constructor: should the generator add default constructors to the classes?
Namespace: the namespace that the classes will belong to.
With this, the Namespace field in each category will automatically be populated with the chosen namespace. This takes effect project-wide. By default, this is left empty.
Defines the code preference for how to format where curly braces should go in code. Newline is selected by default.
Newline
xxxxxxxxxx
public class MyClass
{
public void MyMethod()
{
// ...
}
}
Sameline
xxxxxxxxxx
public class MyClass {
public void MyMethod() {
// ...
}
}
When auto-implementing class methods, this option defines what should be placed in the method body by default.
Return Default
xxxxxxxxxx
public class MyClass
{
public int MyMethod()
{
// TODO: implement this method.
return 0;
}
}
NotImplementedException
xxxxxxxxxx
public class MyClass
{
public int MyMethod()
{
// TODO: implement this method.
throw new System.NotImplementedException();
}
}
True by default. When selected, the generator will attempt to automatically populate the newly created class with the correct methods. It is able to recursively traverse inheritance trees to find any unimplemented abstract
methods, and will also implement all interface methods.
When not selected, only the class definition will be provided, and a constructor if chosen.
Not Reccomended, false by default (see FAQ). Setting the overwrite preference to true allows generated files of the same name as existing files to overwrite the contents of those files. Take extra care when contemplating if this should be enabled.
True by default. When implementing classes that inherit multiple interfaces, there is a possibility for two interfaces to have the same method signatures, but different return values. This clash can create errors, and can be remedied by explicitly implementing the interfaces (with its own drawbacks).
When not selected, whenever two or more interfaces are being implemented, they will always be explicitly implemented to avoid errors.
When I type in a UnityEngine super class, it says that the name isn't found. Why?
Except for MonoBehaviour, which is treated as a special case for a default super class, any entity (class, interface, struct, enum, etc..) that is part of the UnityEngine (or UnityEditor) namespace needs to contain the fully qualified name.
For Example
ScriptableObject
=> UnityEditor.ScriptableObject
EditorWindow
=> UnityEditor.EditorWindow
MonoBehaviour
=> UnityEngine.MonoBehaviour
is valid by this rule, but both are acceptable
I can't find a class or interface when trying to use inheritance, how can I fix this?
Usually, this comes down to making sure spelling is correct, and checking that you are using the fully qualified name of your entity; if the class or interface is contained in a namespace, make sure you are entering it in as "MyNamespace.MyClass".
If you have done both of these without remedy, reach out to our support contact with a description of your issue.
Why Can't MonoBehaviour classes be serialized?
Unity does not support serialization for MonoBehaviour classes, so any properties within the class you want to serialize will need to be individually serialized. Separating the data into a non-MonoBehaviour class is a common solution to this issue.
Why did my new file fail to write?
There are a variety of reasons that a file might not be able to be created, including:
Why is the overwrite option not recommended?
When creating a new file or a batch of classes, the last thing you would want to have happen is to accidentally overwrite an important file! While a good version control system would allow this to be easily undone (and everyone should use one when developing games!) , we want to make sure that you fully understand the potential dangers that can come from not being careful with the feature, especially in the case where you do not have a VCS in place.
If you have any questions, concerns, issues, or feature requests don't hesitate to reach out to us at
To best help with an issue, please provide the version number in the support tab of the editor utility, and a description of your issue.