Achievement unlocked!

The last couple of months I’ve been working on an achievement system. The goal is to sell the asset on the Unity store. There are already a few of them out there, but what we offer, we consider unique. But no development goes without a hitch and right now I’m in the middle of the biggest one. Ok, that’s a lie, it’s a big structural change in the code, that’s all, but biggest hitch sounds better 😛 .

The system itself is fairly straight forward, you have a front-end, where the developer can enter data and you have a back-end, which stores the data. This part is fairly simple, but as we’re closing in on testing, I wanted to go through the code, look at re-usability and data flow. The re-usability part for this project I would say is okay. There’s a parser that can be modified and be re-used. There’s a couple of other classes that are used as  data models, that also can be re-used. Other than that there’s nothing we can truly re-use. But for this project, I consider that fine. Then I started looking at the data flow. From the image below, you can see the arrows are going pretty much all over the place:class dataflow setup

Now I haven’t been working on this from the start, so a lot of the data and how it flows was not my design, but looking at that, I found out I needed to change the code. The question is how to do it. I don’t want to give away too much, like I said this is something that we want to sell on the Unity store, but what I can say is that to communicate with the back-end, we use event calls. The problem that I see with this way is that I don’t want to have events when the back-end updates or otherwise utilize data. I want to have events on buttons that I click in the UI, but when getting data.

In this case, events are not used when clicking the UI directly, but rather have events attached to one class that calls another class that triggers the events. I’ve already removed one class that was between there too. So at first it was: Button click -> Class method -> another class method -> a third class method that triggered the event.

What I want to accomplish now is: Button Click – trigger Event. The affected methods that subscribe would then do what they needed to do. The hitch is that I need to plan the system over. Removing a lot old code, but in the end, I think it will be much simpler. Going from the scheme above to:
new dataflow setup

At least on paper this looks better. I will probably go through and re-iterate this at some point, but there is a point where changes don’t contribute that much. Now all there is left is to put theory into practice. Just a quick note about the picture. To the left is a box with 3 classes that I will get rid of, that I don’t believe I need anymore. To the right in the box there are 3 classes that are only supposed to be used during run-time, where one of them is a singleton template object, so it’s just used for inheritance. Then the bigger box is the event class that I want to utilize. Basically in the form I have planned in my head it is only supposed to be the events. The buttons will effectively call those events and the subscribing classes should execute their methods, depending on the event call.

This will be a first time for me trying to plan code based on a system that has already been created and re-iterating to get it better. I have re-iterated stuff before, but those times I’ve never really planned, because most of the time the re-iteration has been small chunks at a time. Now all that remains is to get the event system to work as I want it to. Once it does, the system should, I hope, have 3 more classes that are re-usable for other projects as well.