update core

This commit is contained in:
2023-02-25 19:00:31 +08:00
parent e19d1f4339
commit abc996cdc9
4 changed files with 54 additions and 236 deletions

View File

@@ -6,9 +6,10 @@ namespace Runtime.ADAggregator
{
public class ADManager : MonoBehaviour
{
private static ADManager _instance;
private static bool mIsCreate = false;
private static ADManager _instance;
private static bool mIsCreate = false;
private static bool mIsGMModel = false;
public static ADManager Instance
{
get
@@ -21,7 +22,7 @@ namespace Runtime.ADAggregator
Destroy(objs[i]);
}
_instance = new GameObject().AddComponent<ADManager>();
_instance = new GameObject().AddComponent<ADManager>();
_instance.name = "[GameUpdater] <color=yellow>NoInit<color>";
DontDestroyOnLoad(_instance);
_instance.InitTimeSystem();
@@ -34,7 +35,7 @@ namespace Runtime.ADAggregator
}
#if UNITY_ANDROID
public AndroidJavaObject activityContext { get; private set; }
public AndroidJavaObject activityContext { get; private set; }
#endif
/// <summary>
@@ -55,8 +56,9 @@ namespace Runtime.ADAggregator
#pragma warning disable CS0414
private bool _isInit = false;
#pragma warning restore CS0414
public void Init(Action onCallback , string userId, ADConfig adConfig , IAdController controller , params object[] args)
public void Init(Action onCallback, string userId, ADConfig adConfig, IAdController controller,
params object[] args)
{
_isInit = true;
_instance.name = "[GameUpdater] <color=green>Init<color>";
@@ -70,20 +72,31 @@ namespace Runtime.ADAggregator
_adConfig = adConfig;
onCallback?.Invoke();
#endif
}
/// <summary>
/// 测试模式,此模式下,不会播放、加载任何广告,但是会模拟广告播放成功,正式版本不能调用此方法
/// </summary>
public void SetTestModel()
{
mIsGMModel = true;
}
public bool IsRealy(AD_Type adType)
{
#if UNITY_EDITOR
return true;
#endif
if (!_isInit || mIsGMModel)
{
return true;
}
#pragma warning disable CS0162
if (AD_Dicts.ContainsKey(adType) == false)
{
AD_Dicts[adType] = PlayerCreate(adType);
}
return AD_Dicts[adType].IsReadly();
#pragma warning restore CS0162
}
@@ -93,6 +106,10 @@ namespace Runtime.ADAggregator
#if UNITY_EDITOR
return;
#endif
if (!_isInit || mIsGMModel)
{
return;
}
// Debug.LogError("准备加载广告" + adType);
#pragma warning disable CS0162
if (!IsRealy(adType))
@@ -118,7 +135,16 @@ namespace Runtime.ADAggregator
/// <param name="callback"></param>
public void AsyncPlayAD(AD_Type adType, string adScene, Action<bool> callback)
{
_adController.EventLog("adScene" , adScene);
#if UNITY_EDITOR
callback?.Invoke(true);
return;
#endif
if (!_isInit || mIsGMModel)
{
callback?.Invoke(true);
return;
}
_adController.EventLog("adScene", adScene);
try
{
_curAsyncPlayer?.Kill();
@@ -126,13 +152,14 @@ namespace Runtime.ADAggregator
{
AD_Dicts[adType] = PlayerCreate(adType);
}
var player = AD_Dicts[adType];
_curAsyncPlayer = new AsyncAdPlayer(player, callback);
}
catch (Exception e)
{
Debug.LogError(e);
_adController.EventLog("error" , "showAdError" , e.Message);
_adController.EventLog("error", "showAdError", e.Message);
callback?.Invoke(false);
}
}
@@ -142,6 +169,10 @@ namespace Runtime.ADAggregator
#if UNITY_EDITOR
return null;
#endif
if (!_isInit || mIsGMModel)
{
return null;
}
#pragma warning disable CS0162
return _adController.CreateAdPlayer(type);
#pragma warning restore CS0162
@@ -152,6 +183,10 @@ namespace Runtime.ADAggregator
#if UNITY_EDITOR
return;
#endif
if (!_isInit || mIsGMModel)
{
return;
}
#pragma warning disable CS0162
if (adType != AD_Type.AwardVideo)
{
@@ -169,11 +204,11 @@ namespace Runtime.ADAggregator
private List<Action> _updateList;
private const int DefaultLength = 1024;
private List<AdTimeHandler> _timeHandlers;
private void InitTimeSystem()
{
this._updateList = new List<Action>(DefaultLength);
this._timeHandlers = new List<AdTimeHandler>();
this._updateList = new List<Action>(DefaultLength);
this._timeHandlers = new List<AdTimeHandler>();
}
private void _InvokeUpdate(List<Action> list)
@@ -192,7 +227,7 @@ namespace Runtime.ADAggregator
list[i].Invoke();
}
}
for (int i = this._timeHandlers.Count - 1; i >= 0; i--)
{
var timeHandler = this._timeHandlers[i];
@@ -207,8 +242,8 @@ namespace Runtime.ADAggregator
}
}
private void Update() => this._InvokeUpdate(this._updateList);
private void Update() => this._InvokeUpdate(this._updateList);
public AdTimeHandler CreateTimer(float delay, Action callback, Action<float> update = null)
{
if (delay <= 0)
@@ -249,7 +284,7 @@ namespace Runtime.ADAggregator
{
this._updateList.Remove(updater);
}
#endregion
public void CloseMask()
@@ -261,6 +296,5 @@ namespace Runtime.ADAggregator
{
_adController.SetMask(true);
}
}
}