Encapsulation

posted in: Senior Team | 0

For mobile testing, we have been testing with just one level in the game. The PC version of the game has had menus for a while. Most recently, the menus have been updated to support switching characters and saving/loading the characters each time you play. This is based off of loading data into an xml document that stores player preferences for players 1 and 2 (It stores player two since there is a 2 player option on the PC).

The past versions of mobile had a smaller menu at one point, but it was removed to focus testing on the controls and performance. So the mobile menus with the xml saving was untested. Long story short it didn’t work correctly on the first merge. After some research it turn out saving and loading from files works slightly different between PC and Android. So we had to find a work around for that.

Another programmer was working on the loading and saving and wrote a class that handled all of that data. Inside that class was functions for loading and saving that handled the xml document. Since all we really saved in the document was integers representing the characters that the players were using, we were able to store the same data somewhere else for mobile using PlayerPrefs. Right now the way it is set up is through the use of platform defines.

#if UNITY_ANDROID
use playerprefs
#else
use xml saving
#endif

And that does the trick for now, unless our saving gets more complex. And since the saving and loading functions were encapsulated in a special class, once we figured out how to properly save on mobile, implementation was painless and simple.