Unity projects
I'm learning Unity completely in public, every day for 55 days.
So far, I've worked on various aspects such as:
- HTTP network code to retrieve data and asset from a server
- Object pooling (both with Unity built in pool and my own implementation)
- First and third-person movement and mechanics
- Unit testing
- Asset integration (2D, 3D, Audio...)
- Animation management
Here are some of the concrete projects I've been working on:
A turn based combat with a flexible potion system
In order to demonstrate and push the CSV importer detailed in the next section, I decided to create a combat system that use the ScriptableObject generated.
One of the highlight is the inventory system, that implement at the user level drag and drop and tooltip display when hovering. On the code side, multiple overload methods allows adding items to a specific slot, or just to the inventory in general; if so, it automatically finds either the same object to stack it or a free spot.
Using inheritance, I repurpose the same logic to create an equipment slot that extend the functionality of the inventory slot (only allowing certain item type, for example).
The other big highlight of this demo is the potion system: when a potion is used, it adds itself as a component of the target, automatically plug into the main logic through delegates, and perform its logic when needed (damage the target, reduce the damage taken, skip a turn...), and finally delete itself once condition are met (after a number of turns, damage, or instantly after the effect has been applied)
Thanks to interfaces, the potion has exactly the same effect on both the enemy and the player, or any other element we would like to add in the game later on. This makes good use of the ECS architecture Unity encourages.
Potion effects can then easily be stacked without them caring about each other logic; this could be used beyond potion for spells, buff, and power-up.
This project told me a lot about modular design and keeping the code as decoupled as possible, and the great flexibility this discipline provide.
You can find the full source code of this project here (MIT License).
A script to import/export multiple ScriptableObject from a CSV file
I always prefer to have the option to modify things outside the editor, so I wanted to create a way to easily work with CSV and ScriptableObject combined.
This script, ran in the Editor via a menu, allows you to import multiple ScriptableObject (SO) from a CSV file, but also to export them back into the CSV once changes have been made inside the editor.
The implementations I saw online were tightly coupled to the target data, so I worked on making my script more flexible by the use of generics.
For example, the API for importing SOs from an CSV looks like this:
Import<[ScriptableObject Class]>("[CSV's name]", "[Folder that will contains the SOs]", "[Field used to name the SO]");
The ScriptableObject class must be part of a simple interface, just so I can run a constructor-like method with the data parsed from the CSV. Each SO is then responsible for handling and validating this data, which make the code way more organized, since the CSV handler doesn't have to care about which field are expected or the implementation details of each object.
If the SO has validated the data and initialized properly, it raises a flag and an asset is created in the correct folder.
This script allows the fast iteration of ScriptableObject, while not requiring for designers to manage and install Unity. This can really benefit heavy data games like RPGs, deckbuilders or Roguelike.
A good improvement to the code would be to pull the CSV from a Company's server or even Google Sheet with an API.
You can find the full source code of this project here (MIT License).
Each day, I'm posting my progress on my Mastodon account. This thread serve as a demonstration of how I learn and how fast I can pick up new tools and languages.