Quest editor in Unity3D

For my first Unity3D custom editor I chose to make a quest editor, most simplified as possible for my needs but as much customizable as possible to make quest creation and editing simple for non programming developers.

This is the required example of quest code for this post:

quest

And this is the base class for conditions:

condition

I’m not going to enter into many details about all Unity3D class libraries, like ScriptableObject required to save custom assets, if needed a dedicated post can be created to explain that.

One of the fundamental ideas for a quest is that they have certain requirements to complete, these requirements are dictated by the Conditions, each quest can have an arbitrary number of conditions in order to complete, these need to be created by programmers in order to be used by designers, the requirement to use them in the editor is to inherit them from Condition and be instantiable with an empty constructor, the editor itself searches for these classes in all libraries in the Unity project using c# instrospection libraries.

By right clicking on the editor a context menu should open and show an interface like the following:

condition added

And here is an example of the demo condition I created form this post, simple enough to be shown on the UI:

on enemy killed condition

After this small overview on how to extend the editor here is an representation of the editor after adding a condition to the current editable quest:

quest editor

Since different conditions will be created they will need to be displayed with all the possible public properties to be shown to the user to edit them, luckily Unity3D already contains an Editor that deals with this, as you can see here:

http://docs.unity3d.com/ScriptReference/Editor.html

But by using this editor for the first time for my surprise another condition property was added to the UI, the Script property, which is a drag and drop field for scripts, but this was something that I didn’t want to have on my editor, so for this I needed to extend the Editor class as the following:

extended editor

The removal of the Script property is a bit of a hidden feature, I couldn’t find any sort of documentation for it, so I had to iterate over the properties of ScriptableObject to try to find the name used in order to remove the property from the Editor.

And to use it the following lines of code are used:

var editor = Editor.CreateEditor(Condition, typeof(ConditionEditor));

editor.OnInspectorGUI();

With the top menu from the quest editor new custom assets can be serialized and saved to the project folder in order to being used like any other custom asset, allowing new Quests to be created with the the minimum programming effort as possible, giving designers more freedom and productivity.

Further improvements

At the moment the Quest object is quite minimalistic, giving no space for Quest rewards and other configurable parameters, the next phase in my development plan is to create another editor for item assets where the user can create different game items with different types of use, saved on the project folder, allowing the user to drag and drop them to this editor as rewards for completing the Quest.

Further development

After creating working conditions the next step in development will be to create a script allowing the Unity3D GameObject to become a “Quest Giver” an entity well known in many RPGs, simply be drag and dropping a created Quest into the Quest Giver.

Software developer in Edinburgh, passionate about web and solutions for difficult problems, in my free time I like to do game development coding, art, level design and story writing.

Your email address will not be published. Required fields are marked *