Making an Object-based Database

Hey it’s me, the GOOD programmer, Liam. Thought I’d fill you guys in on what I’ve been working on during the past few weeks. This post will be focusing on the object based Database system I made a while back.

After the team all agreed on the goals of this project, the first thing I worked on was the Encyclopedia Database. We wanted players in ADA to be able to scan objects in the game-world and view them in a Pokedex-esque UI system. This was one of the game-play mechanics that we wanted implemented before the games showcase at the end of semester.

Before I get into the boring nitty-gritty of what I did and how I did it, I just want to say that I went into this hoping to make this system as modular as possible. I wanted to reuse this system in future projects, so I tried to make sure not to tie it into ADA too harshly.

When I began, I knew that I wanted to use Generics to handle storing and editing each object in the system. I ended up using multiple Lists in this system though in hindsight, Dictionaries would have been a better choice. I created one list to hold ALL the objects and three sub-lists to sort out each individual object-type. This would have worked better with a Dictionary as it is easier to sort and file each of the objects in it and I wouldn’t have had to create three separate variables.

While making this system, I wanted to try and incorporate as many static methods as I could, as I knew our game was going to be a behemoth in terms of cpu usage. I made about 9 of these static methods, all of which interact with the lists in some way or another. For example, one of the functions is called FindAllDatabaseObjects and it, you guessed it, would find all of the relevant objects in the current scene.

After getting the main plan of attack down, I decided that I wanted to use some custom editor shenanigans to streamline to process of adding new database objects to the scene. Here’s how the database object looked in the editor after my first pass on the custom editor stuff:

ADA DatabaseObject

By hiding any unnecessary variables, I could prevent any artists from breaking my shiet. An example of this would be when the object type is set to Fauna, you won’t be able to set it’s Flora type in the inspector as its not a Flora object. Doing it this way allowed me to store all the variables for any object type in the one script and just hide the unrelated ones.

Here’s what the main database script that held all of the lists looked like in-editor:

ADA DatabaseManager

Those buttons were put in place so I could test the system without initiating the main game-loop. This cut down the time I spent adjusting the various finer points of the script such as the positions in which each UI would be instantiated. After creating these systems and customizing the Unity Editor to fit my needs, I designed the basic layout of the in-game UI. This is the first and, as of this post, current look of the UI:

ADA DatabaseUI

 

Advertisements