• Register
Post news Report RSS The Level Editor

Project Xaron features a full in-game editor for creating custom levels which extends the games lifetime.

Posted by on

Introduction
One of the fundamental pillars of Project Xaron is mod support. When creating a game heavily based on replayability, I think not creating proper modding tools would be such a shame, which is why I allocate a lot of time to perfect the workflow for modders

The level editor itself is used solely for creating rooms and what I call obstacles. Rooms are small rooms, at the moment consisting of 12x10 tiles, which are strategically structured together on a 4x4 grid to create a level. Obstacles are prefabs which can be attached to rooms in order to keep them 'fresh' so you never see the same room twice.

In this article I will talk specifically about the level editor, which I chose to fully design with in-game UI to make the point of entry as low as possible. That doesn't mean it's not powerful, though, as every aspect of it is extendable through code. This means that you not only can create new content for Project Xaron, you can even create new tools!

Although I've created the fundamentals for the level editor, I would like to point out that this is a very early version. If you're reading this in the future you'll probably notice that everything looks very barebones, and that's because it is!

Tools
The level editor has a few different tools at this point, namely adding tiles, removing tiles and selecting tiles. These tools have all been designed using an API modders will have access to, meaning they can create their own tools if they so desire. Adding and deleting tiles is pretty self explanatory, but what does selecting mean? That brings me to my next topic - the properties window!

Here's a code snippet of how tools are defined.


using UnityEngine;

namespace Xaros.LevelEditor
{
    public class AddTileTool : ILevelEditorTool
    {
        public Sprite Thumbnail
        {
            get
            {
                if (_thumbnail == null)
                    LoadThumbnail();

                return _thumbnail;
            }
        }
        private Sprite _thumbnail;

        private void LoadThumbnail()
        {
            _thumbnail = ModManager.GetSprite("Core", "AddTileToolThumbnail.png");
        }
        public void PerformAction(Vector2 position)
        {
            if (!LevelEditorManager.Room.ContainsTile(position))
            {
                LevelEditorManager.Room.AddTile(position, LevelEditorManager.Tile);
                LevelEditorRenderer.AddObject(position, LevelEditorManager.Tile);
            }
        }
    }
}

Something that's really cool about Project Xaron is that it uses reflection to hook up modded tools into the editor. This means that all you have to do is put your .dll file into a folder and then you're good to go! No need to fidget around with some hard to read XML file in order to tell the game you want it to use your code.


Properties
The editor has a properties window which, you guessed is, is fully extendable through code. What this allows you is to select a tile, or the entire room, and then change certain properties regarding said object. At the moment for instance, this is how you define what type of room you're working on, but in the future I'll add spawn probability to tiles and a bunch of other features. I'd like to reiterate that this is obviously also modable!

Properties


Here's a code snippet of how properties are defined.


using System.Linq;
using System.Collections.Generic;

namespace Xaros.LevelEditor
{
    [CustomInspector(Target = typeof(Room))]
    public class RoomInspector : Inspector
    {
        public Room Target { get { return (Room)target; } }

        private List<string> RoomTypeOptions { get { return System.Enum.GetNames(typeof(RoomType)).ToList(); } }

        public override List<InspectorElement> Elements
        {
            get
            {
                return new List<InspectorElement>
                {
                    new InspectorDropdown("Room Type", RoomTypeOptions, (int)Target.TypeOfRoom, OnRoomTypeChanged),
                };
            }
        }
        private void OnRoomTypeChanged(int index)
        {
            Target.TypeOfRoom = (RoomType)index;
        }
    }
}

You'll notice that elements in the inspector are obviously packaged into a class and auto sorted so you don't have to fidget with getting the looks right. All you have to do is hook up the data and you're good to go!


Content Browser

The content browser is where you select which tile you want to work with. At the moment I really only have the basic terrain tile implemented, but adding tiles such as obstacle area and objects will be included in the near-term future.

Content Browser


Here's a code snippet!


using UnityEngine;

namespace Xaros.LevelEditor
{
    [System.Serializable]
    public class TerrainTile : Tile
    {
        public override Sprite InspectorIcon
        {
            get
            {
                if(_inspectorIcon == null)
                {
                    _inspectorIcon = ModManager.GetSprite("Core", "TerrainTile_InspectorIcon.png");
                }

                return _inspectorIcon;
            }
        }
        [System.NonSerialized]
        private Sprite _inspectorIcon;

        public override Sprite EditorSprite
        {
            get
            {
                if (_editorSprite == null)
                {
                    _editorSprite = ModManager.GetSprite("Core", "TerrainTile_EditorSprite.png");
                }

                return _editorSprite;
            }
        }
        [System.NonSerialized]
        private Sprite _editorSprite;
    }
}

You'll note that this object doesn't actually do anything. That's because it's just a terrain tile, it's sole purpose in the universe is to display an image.

You'll also notice that tiles are serialized. This is because rooms are compiled into *.room files, once again making sharing mods easier. Downloading a mod pack of new rooms is as simply as downloading a folder!

Container Browser
The container browser gives you an overview of all the currently created rooms, and in the future also obstacles! It will also allow you to create new objects, save, delete and rename them! Note that this tool will actually display all of the currently available rooms, meaning that you can even change the way the core game works if you're unhappy with my design!

ContainerBrowser


Source Code
Due to my commitment to creating a thriving modding community, I've decided to go open source! You can view the project in it's entirety on my BitBucket page. This is because I want modders to be as informed as possible. Understanding the API you're using is crucial when designing your own game objects, and I think this is a big step in the right direction.

Note that if you're a modder and this project sounds interesting to you, I would be more than interested in talking to you! I'm looking to work together with experienced modders in order to make your life easier

I hope you enjoyed my article. If you have any questions, feel free to send me a message or drop a comment.

- Daniel Everland

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: