Posted August 20, 2025 by Dyrkabes
#learning #code #architectural design #patterns
I am adding music and sound effects to Mathemando. And want to share my learning regarding that.
That's it, thanks for your attention.
Now seriously.
I first created the game mechanics: buttons, menus, UX in general. That was fun till I realised that I also want to add vibration. Luckily for me, the game was still small. So I added a couple of vibration functions like those below.
VibrationManager.VibrateSoft() VibrationManager.VibrateLight() VibrationManager.VibrateMedium()
Tested the app, all was fine. The app originally only went to TestFlight and I focused on the web version and additional mechanics. I wanted to release and get feedback as soon as possible and neglected further enhancements. That led me to some problems later.
I realised that I want to push the game on the AppStore. Releasing is always a pain – not only because of all the things around it like making screenshots and descriptions and licences, but because I cannot just release something, it should be well done. I decided to add sound. Immediately, there was one issue. How do I add sound effect in all the places? It is now at least four scenes, multiple buttons, different interactions. I could search for each and then add the effect, then test, search and fix again and again – that would work for such a project. But that was highly ineffective.
Could you guess a better solution?
1...
2...
3...
I could just search for places where I invoked `VibrationManager`. Easy. Apart from two problems
While it is doable there is a better approach that could have saved me some time.
It consists of three steps
In other words, that would mean:
// Step 1
public static class UXFeedbackManager // Define the event in one central place
{
public static void PlayButtonTapFeedback() // Method can be empty
}
// Step 2
// Some class with buttons
public void MakeMoreRelaxing()
{
UXFeedbackManager.PlayButtonTapFeedback(); // Call it. Yes, my game can make things more relaxing
// other logic
}
// Step 3
public static void PlayButtonTapFeedback()
{
VibrationManager.VibrateLight(); // Have some real implementation
SoundManager.shared.DidTapButton(); // In general, those methods are a Facade pattern
}
What benefits does it bring?