175 lines
4.3 KiB
C#
175 lines
4.3 KiB
C#
namespace Guru
|
|
{
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
public partial class GuruSDK: MonoBehaviour
|
|
{
|
|
public const string Version = "0.1.0";
|
|
public static readonly string Tag = "[Guru]";
|
|
|
|
private static GuruSDK _instance;
|
|
/// <summary>
|
|
/// 单利引用
|
|
/// </summary>
|
|
public static GuruSDK Instance
|
|
{
|
|
get
|
|
{
|
|
if(null == _instance)
|
|
{
|
|
_instance = CreateInstance();
|
|
}
|
|
return _instance;
|
|
}
|
|
|
|
}
|
|
|
|
private GuruSDKInitConfig _initConfig;
|
|
private Action<bool> _onCompleteCallback;
|
|
|
|
private static GuruSDKModel _model;
|
|
|
|
internal static GuruSDKInitConfig InitConfig => Instance._initConfig;
|
|
internal static GuruSDKModel Model => GuruSDKModel.Instance;
|
|
|
|
|
|
/// <summary>
|
|
/// Debug Mode
|
|
/// </summary>
|
|
public static bool IsDebugMode
|
|
{
|
|
get
|
|
{
|
|
#if UNITY_EDITOR || DEBUG
|
|
return true;
|
|
#endif
|
|
return false;
|
|
}
|
|
}
|
|
|
|
#region 初始化
|
|
|
|
|
|
private static GuruSDK CreateInstance()
|
|
{
|
|
var go = new GameObject(nameof(GuruSDK));
|
|
DontDestroyOnLoad(go);
|
|
_instance = go.AddComponent<GuruSDK>();
|
|
return _instance;
|
|
}
|
|
|
|
|
|
public static void Init(Action<bool> onComplete)
|
|
{
|
|
Init(GuruSDKInitConfig.Build(), onComplete);
|
|
}
|
|
|
|
public static void Init(GuruSDKInitConfig config, Action<bool> onComplete)
|
|
{
|
|
LogI($"---- Guru SDK init ----");
|
|
LogI(config.ToString());
|
|
Instance.StartWithConfig(config, onComplete);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 启动SDK
|
|
/// </summary>
|
|
/// <param name="config"></param>
|
|
/// <param name="onComplete"></param>
|
|
private void StartWithConfig(GuruSDKInitConfig config, Action<bool> onComplete)
|
|
{
|
|
Model.PropBLevel.OnValueChanged += OnBLevelChanged;
|
|
Model.PropBPlay.OnValueChanged += OnBPlayChanged;
|
|
|
|
_initConfig = config;
|
|
_onCompleteCallback = onComplete;
|
|
|
|
//---------- Start Firebase ------------
|
|
FirebaseUtil.InitFirebase(OnFirebaseReady);
|
|
FirebaseUtil.OnFetchRemoteSuccess += OnFetchRemoteSuccess;
|
|
//---------- Start Facebook ------------
|
|
FBService.Instance.StartService();
|
|
}
|
|
|
|
private void OnFetchRemoteSuccess()
|
|
{
|
|
Callbacks.Remote._onRemoteFetchComplete?.Invoke();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开始各种组件初始化
|
|
/// </summary>
|
|
private void OnFirebaseReady()
|
|
{
|
|
LogI($"--- #1 SDK Init complete ---");
|
|
if (InitConfig.IAPEnabled)
|
|
{
|
|
LogI($"--- #2 Init IAP ---");
|
|
InitIAP(_initConfig.GoogleKeys, _initConfig.AppleRootCerts); // 初始化IAP
|
|
}
|
|
|
|
if (!InitConfig.UseCustomConsent)
|
|
{
|
|
LogI($"--- #3 Start Consent Flow ---");
|
|
StartConsentFlow();
|
|
}
|
|
|
|
//TODO: 开始Remote初始化
|
|
|
|
if(!string.IsNullOrEmpty(IPMConfig.IPM_UID)) SetUID(IPMConfig.IPM_UID);
|
|
|
|
_onCompleteCallback?.Invoke(true);
|
|
}
|
|
|
|
private void OnBLevelChanged(int blevel)
|
|
{
|
|
SetUserBLevel(blevel);
|
|
}
|
|
|
|
private void OnBPlayChanged(int bplay)
|
|
{
|
|
SetUserBPlay(bplay);
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Misc
|
|
|
|
/// <summary>
|
|
/// 打开页面
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
public static void OpenURL(string url)
|
|
{
|
|
GuruWebview.OpenPage(url);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Logging
|
|
|
|
|
|
public static void LogI(object message)
|
|
{
|
|
Debug.Log($"{Tag} {message}");
|
|
}
|
|
|
|
public static void LogW(object message)
|
|
{
|
|
Debug.LogWarning($"{Tag} {message}");
|
|
}
|
|
|
|
public static void LogE(object message)
|
|
{
|
|
Debug.LogError($"{Tag} {message}");
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |