Welcome back #fealtyfollowers!
It is great to be back to writing code! Last week I implemented character portraits and family heraldry. Previously, portraits were a single image and the heraldry a backing field with some predefined devices. In the new implementation, these two things are similar - they are both composite images of multiple layers; what is different between them is the layers themselves.
The images I was using in Alpha 1 were exposed to the game by adding them to a SpriteManager GameObject through the Unity interface. This was great for getting stuff done, but was not going to work when I need to add or change many sprites. I deleted that SpriteManager object (You served us well , R.I.P.) and added the oh-so-awesome Better Streaming Assets plugin to the project.
Streaming Assets are a way to use external assets in your Unity project. Because they are external, Unity doesn’t manage them or know anything about them. Instead, you have control of when/how to load these resources from the filesystem. This way of working with resources means you have to write a little more code to integrate them into the project but brings two awesome benefits to our situation which involves working with lots of images:
I can add/remove/change the files without having to do anything in Unity; the files are loaded by their path, so I just have to put them in the correct place
YOU could use whatever art you wanted - just make the files in the right folders
In Unity portraits and coat of arms are represented by the same prefab - MultiLayeredImageWidget. This game object simply takes layers and then draws them. This is simply and worked well, but the coat of arms needed a little more logic for properly masking bottom layers below the shield shape.
Heres an example of things:
The UI is a bit janked right now, but its all going to the trash anyway :p
I pointed out in the beginning that between portaits and coat of arms the difference was in the layers that make up each type of image. Currently portraits have 13 possible layers, and a coat of arms has 3. I hard-coded these at first to get everything working but I knew that these layers were going to change - particularly the coat of arms, which is going to have layers for applying patterns, multiple devices, etc.
To make this system more flexible I defined the layers for each type of image in an XML file. This file also defines where the assets for that type should be. If you are following along at home, that means you can totally redo the portrait/coat of arms system if you wanted to - make your own layers, use your own art, etc.
This will all come in handy when my imaginary designer friend starts contributing to the project and doesn’t need me to change code!
I will be using the same XML reading system to add all the entities (i.e. buildings, traits, events, etc.) to the game as I go - which means all that data will be changeable too.
So with that, I marked the Portrait feature complete and Families is close behind with the only piece to go the Family tree UI (which I hope to start tonight!)
These features are awesome and important, but they do not add gameplay themselves - but that’s whats coming next when we get to Vassals!
Thanks for reading :) Drop me a comment below!