187 lines
4.6 KiB
C#
187 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace PhxhSDK
|
|
{
|
|
public class SDKManager : Singlenton<SDKManager>
|
|
{
|
|
private string applicationUserName;
|
|
|
|
public string ApplicationUserName
|
|
{
|
|
set { applicationUserName = value; }
|
|
get { return applicationUserName; }
|
|
}
|
|
|
|
private string applicationUserID;
|
|
|
|
public string ApplicationUserID
|
|
{
|
|
set { applicationUserID = value; }
|
|
get { return applicationUserID; }
|
|
}
|
|
|
|
public enum SdkName
|
|
{
|
|
TapTap,
|
|
CrashSight,
|
|
FireBase,
|
|
}
|
|
|
|
private readonly SdkName[] earlyInitSdk =
|
|
{
|
|
#if SDK_TAPTAP
|
|
SdkName.TapTap,
|
|
#endif
|
|
#if SDK_CRASHSIGHT
|
|
SdkName.CrashSight,
|
|
#endif
|
|
#if SDK_FIREBASE
|
|
SdkName.FireBase,
|
|
#endif
|
|
};
|
|
|
|
private readonly SdkName[] normalInitSdk =
|
|
{
|
|
};
|
|
|
|
private readonly SdkName[] afterLoginInitSdk =
|
|
{
|
|
};
|
|
|
|
private readonly Dictionary<SdkName, SdkHelper> sdkHelpers = new(16);
|
|
|
|
//需要初始化sdk在游戏初始化之前的sdk写在这里
|
|
public void InitEarly()
|
|
{
|
|
try
|
|
{
|
|
foreach (var sdkName in earlyInitSdk) EarlyInitSdk(sdkName);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
DebugUtil.LogError("sdk初始化失败, e = {0}", e);
|
|
}
|
|
}
|
|
|
|
//正常初始化的sdk写这
|
|
public void Init()
|
|
{
|
|
try
|
|
{
|
|
foreach (var sdkName in normalInitSdk) InitSdk(sdkName);
|
|
}
|
|
catch
|
|
{
|
|
DebugUtil.LogError("sdk初始化失败");
|
|
}
|
|
}
|
|
|
|
//账号登陆后初始化的sdk写这
|
|
public void AfterLoginInit()
|
|
{
|
|
try
|
|
{
|
|
foreach (var sdkName in afterLoginInitSdk) AfterLoginInitSdk(sdkName);
|
|
}
|
|
catch
|
|
{
|
|
DebugUtil.LogError("sdk初始化失败");
|
|
}
|
|
}
|
|
|
|
public void ReleaseAfterLoginInit()
|
|
{
|
|
foreach (var helper in afterLoginInitSdk)
|
|
{
|
|
if (sdkHelpers[helper] != null)
|
|
{
|
|
sdkHelpers[helper].Release();
|
|
sdkHelpers.Remove(helper);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
foreach (var helper in sdkHelpers) helper.Value.Update();
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
foreach (var helper in sdkHelpers) helper.Value.Release();
|
|
sdkHelpers.Clear();
|
|
}
|
|
|
|
public SdkHelper GetSdkHelper(SdkName name)
|
|
{
|
|
SdkHelper helper = null;
|
|
if (sdkHelpers.TryGetValue(name, out helper)) return helper;
|
|
|
|
DebugUtil.LogError("sdk : {0} 没有开启", name);
|
|
return null;
|
|
}
|
|
|
|
private void InitSdk(SdkName name)
|
|
{
|
|
if (sdkHelpers.ContainsKey(name))
|
|
{
|
|
DebugUtil.LogError("sdk: {0} 已经初始化过了", name.ToString());
|
|
}
|
|
else
|
|
{
|
|
var helper = CreateHelper(name);
|
|
helper.Init();
|
|
sdkHelpers.Add(name, helper);
|
|
}
|
|
}
|
|
|
|
private void EarlyInitSdk(SdkName name)
|
|
{
|
|
if (sdkHelpers.ContainsKey(name))
|
|
{
|
|
DebugUtil.LogError("sdk: $0 已经初始化过了", name.ToString());
|
|
}
|
|
else
|
|
{
|
|
var helper = CreateHelper(name);
|
|
helper.EarlyInit();
|
|
sdkHelpers.Add(name, helper);
|
|
}
|
|
}
|
|
|
|
private void AfterLoginInitSdk(SdkName name)
|
|
{
|
|
if (sdkHelpers.ContainsKey(name))
|
|
{
|
|
DebugUtil.LogError("sdk: $0 已经初始化过了", name.ToString());
|
|
}
|
|
else
|
|
{
|
|
var helper = CreateHelper(name);
|
|
helper.AfterLoginInit();
|
|
sdkHelpers.Add(name, helper);
|
|
}
|
|
}
|
|
|
|
private SdkHelper CreateHelper(SdkName name)
|
|
{
|
|
switch (name)
|
|
{
|
|
#if SDK_TAPTAP
|
|
case SdkName.TapTap:
|
|
return new TapTapSdkHelper();
|
|
#endif
|
|
#if SDK_CRASHSIGHT
|
|
case SdkName.CrashSight:
|
|
return new CrashSightSdkHelper();
|
|
#endif
|
|
#if SDK_FIREBASE
|
|
case SdkName.FireBase:
|
|
return new FireBaseSdkHelper();
|
|
#endif
|
|
default: return null;
|
|
}
|
|
}
|
|
}
|
|
} |