using Unity.Services.Core;
namespace UnityEngine.Purchasing
{
class UnityServicesInitializationChecker : IUnityServicesInitializationChecker
{
const string UgsUninitializedMessage =
"Unity In-App Purchasing requires Unity Gaming Services to have been initialized before use.\n" +
"- Find out how to initialize Unity Gaming Services by following the documentation https://docs.unity.com/ugs-overview/services-core-api.html#InitializationExample\n" +
"or download the 06 Initialize Gaming Services sample from Package Manager > In-App Purchasing > Samples.\n" +
"- If you are using the codeless API, you may want to enable the enable Unity Gaming Services automatic initialization " +
"by checking the Automatically initialize Unity Gaming Services checkbox at the bottom of the IAP Catalog window";
readonly ILogger m_Logger;
public UnityServicesInitializationChecker(ILogger logger)
{
m_Logger = logger;
}
public void CheckAndLogWarning()
{
if (IsUninitialized())
{
LogWarning();
}
}
bool IsUninitialized()
{
try
{
return UnityServices.State == ServicesInitializationState.Uninitialized;
}
catch (ServicesInitializationException exception)
{
m_Logger.LogIAPWarning($"Exception while getting UnityServices.State: {exception.Message}");
return false;
}
}
void LogWarning()
{
m_Logger.LogIAPWarning(UgsUninitializedMessage);
}
}
}