RevenueCat / purchases-unity

Unity in-app purchases and subscriptions made easy.
https://www.revenuecat.com/
MIT License
94 stars 15 forks source link

API improvements #482

Open Legoless opened 2 months ago

Legoless commented 2 months ago

This PR adds two API improvements:

  1. Purchases Listener is currently an abstract MonoBehaviour, which ties the behaviour to Unity components. This is not bad, but it does limit you, which is entirely not needed, if you mostly use the API from code. There's no other requirement that this should in fact be an abstract class (aside from the ability to set it in Editor). So a new interface is introduced instead and backwards support is added, so that the UpdatedCustomerInfoListener implements the interface. Field is now set as private and serialized, so it can remain set in Editor, but via code Listener property should be used.

  2. The whole Purchases object which is required for RevenueCat to operate initializes itself fairly late in Start function. This is a problem, if you need to do anything beforehand as we're booting our game up in Awake method. The script order is usually undefined and we've seen many differences in it between real devices and Editor, so sometimes Purchases would prepare itself for API type of configuration, sometimes we would be too early calling Configure and crash with NullPointerException on internal _wrapper. To get around this problem, we extracted initialization of wrapper to a separate function that only creates the instances once, but can be called many times. That way Configure will Prepare the wrapper, before it calls to it's Setup method.