Making the Battle Logic and the UI Play Nice


Context

Considering how I'd like to make a career as a gameplay programmer, I decided it'd be fine to handle most of the UI logic in Unity Visual Scripting (UVS). It saved a lot of time, especially thanks to the help of the Community Extensions. This approach makes things easier on UI artists too, since they can implement most of the logic there without me needing to step in too often. Still, there were issues to address. The big one being...


The Language Event Barrier

The UI and the battle logic couldn't listen for each others' events directly. Thus, I needed to use C# as glue to compensate through the Adapter Pattern. I set up a static class (called UIGlobalEventTrigger) to let UVS announce its own events. Here's a small snippet:


Snippet


Now, you may be asking... "Tespy, what's with that static method? Doesn't UVS have a node that lets you just trigger a UnityAction without that?" The answer, unfortunately, is no. Otherwise, I wouldn't have added in such middlemen-within-middlemen. As for the other way around, having the UI respond to the rest of the battle system... Adapter Pattern to the rescue (again)! I created a class called BattleEventRelayer that did what it sounds like: listen to the non-UI battle events and relay it to UVS. It would do that by executing UnityEvents, letting the Script Graph (in response) trigger the corresponding UVS Global Events. Here's a little peek:


Snippet

Snippet


It felt a bit awkward to implement, but it got the job done. Maybe the next time I work on a turn-based project, I can find a more graceful way to go about this stuff...

Get Trigram Islands

Leave a comment

Log in with itch.io to leave a comment.