In my professional work we have this awesome web-based Content Management System. In my indie project I do not have this so went about building a similar system directly in Unity using the power of Scriptable Objects. I am making a JRPG at the moment and that needs a lot of content so makes sense right?
Scriptable Objects are an underused gem in Unity and are a great way of storing data. Let’s look at this example:
Here I have a battle character in a scriptable object. I have built a system where I can use Animation Curves to define stats per level RPG Maker style and set up what ability is available at what elvel and all that other fun stuff.
In fact, I have a whole load of similar scriptable objects that hold all my data.
The neat thing I can do here is put these Scriptable Objects into asset bundles
And build them into my Streaming Assets
Now I can upload my asset bundles to Google Cloud, Amazon or Azure and download them when I need.
In order to make my awesome JRPG I needed some sort of Tile System to create awesome maps. I have some code to load data from Tiled, however, Unity recently added their own system and doing it in the editor itself is much cleaner in my opinion than doing it in an external tool. However, apart from the Manual, there are not a lot of tutorials on how to use it and I found the manual pretty sparse.
The way I wanted to do it is the way I had previously set out with Tiled:
Essentially I wanted there to be 3 layers. Background, Middle and Foreground. However, the docs were not great in showing a way to do that, and inevitably you were not able to set a layer per tile like I had been doing in the past when loading from Tiled. So looking back at Tiled itself, I realised the layers were actually 3 tilemaps. The solution in Unity; create 3 Tilemap objects
By creating 3 maps and then using the sorting layer to decide the draw order I could essentially have 3 layers like I did previously.
Similarly, as the player character only interacts with the middle layer, I only needed the physics object to be on the middle layer gameobject.
The last thing that did catch me out, and is a bit of a pain is having to go through is setting up if the tile is “Walkable” or not.
You essentially have to go to each individual tile asset and select the collider type. Which makes sense to be fair.
There are a load of awesome brushes as well you can grab from here:
It has been a while since I have done any type of tutorial or any technical related blog post, so I thought I would share the process of how I implemented a “cloak” effect on my character. Essentially in my game, I am adding a cloak skill and in order to visualize this to the player I want a sort of holographic semi-transparent cloak effect. Something magicy and Sci-Fi. So I jumped back into my shader coding.
If you need a quick refresh of the make up of shaders in Unity then here are a couple of previous posts (with horrendous typos that I should probably sort):
First we start by creating a Surface Shader and then strip it back so it just performs diffuse lighting, a good starting point for all shader creation.
Firstly in our properties section we are going to add… well… a new property
Which will expose the following “_DotProduct” float value to the editor that we add in our CG Program.
We also want to add a _MainTex property value pair into our shader.
We also want to change the tags.
This will render the shader in the transparent rendering queue and will ignore projectors. If we want, as the player character is becoming invisible, we can also add the “ForceNoShadowCasting” tag that will mean the object does not cast shadows.
We also want to disable the expensive PBR in this shader and switch it out for Lambertion reflectance before telling the CG program this is a transparent shader and then finally disable the lighting. Wow that was a long sentence.
The last thing we want to do before we actually jump into our surface function is change what actually gets run into the shader. In this case we want the world normal and view direction as well as what is already there.
Cool, now we whack this code in the surface function.
And we get this effect:
On a sphere it looks pretty basic although it makes a cool atmosphere effect one, similar to the one I used in my seasonal globe:
What this shader is doing is actually showing the silhouette of the object. If I swap the circle out for something else and we move around it we can see the outline changes.
After I tweaked the values a bit and applied it to my asset store model, here is what I got:
The gif doesn’t do it as much justice as in-game, but I actually think this is quite cool and that shader is cheaper than the previous refraction shader I was using.
I also had a little experiment for fun with my enemy model by adding a wave to all the verts and made what I am calling the “Demontor” shader