Files
CC-Framework.Commercialization/Runtime/ADAggregator/ADPlayer.cs

94 lines
2.0 KiB
C#
Raw Normal View History

2023-01-10 18:03:30 +08:00
using System;
namespace Runtime.ADAggregator
{
public abstract class ADPlayer
{
/// <summary>
/// 0 未加载 、 1 加载中、 2 加载完成
/// </summary>
protected int curState;
public string Key;
2023-09-14 14:21:41 +08:00
public string AdScene;
2023-01-10 18:03:30 +08:00
protected ADListener adListener;
public Action OnErrorAction;
2023-07-31 09:57:20 +08:00
public AD_Type ADType { get; internal set; }
2023-01-10 18:03:30 +08:00
public int State => curState;
2026-04-22 17:41:45 +08:00
public virtual int MaxLoadAttempts
{
get
{
return ADType == AD_Type.AwardVideo ? 2 : 1;
}
}
public virtual float LoadRetryDelaySeconds
{
get
{
return ADType == AD_Type.AwardVideo ? 0.75f : 0f;
}
}
public virtual bool AutoPreloadOnInit
{
get
{
return false;
}
}
2023-01-10 18:03:30 +08:00
public ADPlayer Init(string key)
{
this.Key = key;
this.curState = 0;
adListener = new ADListener();
this.OnInit();
return this;
}
public bool IsLoading()
{
return curState == 1;
}
public abstract void ShowAD(Action onClose, Action<bool> onVideoComplete);
2023-01-28 17:47:11 +08:00
public virtual bool IsReadly()
{
return this.curState == 2;
}
2023-01-10 18:03:30 +08:00
public abstract void LoadAD();
public virtual void OnInit()
{
}
2026-04-22 17:41:45 +08:00
public virtual void OnPlayRequestStarted()
{
}
public virtual void EnterAdScenario(string scenario)
{
}
2023-01-10 18:03:30 +08:00
/// <summary>
/// 主动关闭广告
/// </summary>
public virtual void CloseAD()
{
}
2023-01-28 17:47:11 +08:00
public void OnError(object code, string message)
{
this.OnErrorAction?.Invoke();
this.OnErrorAction = null;
curState = 0;
}
2023-01-10 18:03:30 +08:00
}
2026-04-22 17:41:45 +08:00
}