An important part of creating CP Social was creating a way for developers to have a simple way of implementing cross-platform functionalities without the hassle of having to dive through multiple documentations websites to implement the same feature for all supported platforms.
How?
CP Social works as a layer between the developers code and the code of the underlying platform specific api’s. An abstract version of this is shown in the image below.
CP Social works as a translator for all underlying api’s, by doing this a developer only has to know how to use CP social’s api, instead of having to research and learn, in this case, four different ways of implementing the same feature, with 4 different api’s.
Not a lot of code
The way I achieved such a simple api is how CP Social works internally. CP Social includes a configurator that can be used from within the Unity editor. Using this configurator a lot of work has already been done when the game starts.
Example
An example of this work preparation can be seen in when adding achievements to CP Social. In stead of using 3 different id’s for an achievement, you add a fourth one. This fourth one is used as a universal reference to that achievement.
So the only thing you have to do is supply CP Social with this universal reference name, and it figures out the rest.
Comparison
If you would like an example how CP Social can be used in a Unity project, you can check the documentation, or at the examples below.
The examples below show code that is used to sign in using CP Social or how to unlock an achievement when using CP Social compare to how a developer would have to implement the same functionality when using the Steam api, Android api and iOS api separately.
Signing in
Using CP Social
The image above shows the a method with the code needed to sign in through CP Social on Android, iOS, Steam and the fallback Unsupported platform.
Total method length: 4 (Comments & white lines not included)
Without using CP Social
The image above shows an example of the logic CP Social uses to sign in on Android, iOS and Steam. But this times written as if CP Social would not exist.
Total method length: 47 lines (Comments & white lines not included)
Unlocking an achievement
CP Social
The image above show how to unlock an achievement asynchronously on Android, iOS, Steam and the fallback Unsupported platform using CP Social
Total method length: 8 lines (Comments & white lines not included)
Without CP Social
Without using CP Social it’s not possible to unlock an achievement on all supported platforms at once. But below would be a best case scenario using 3 separate methods.
Total method length: 19 lines (Comments & white lines not included)
Total method length: 18 lines (Comments & white lines not included)
Total method length: 19 lines (Comments & white lines not included)