using System; namespace Runtime.ADAggregator { public abstract class ADPlayer { /// /// 0 未加载 、 1 加载中、 2 加载完成 /// protected int curState; public string Key; public string AdScene; protected ADListener adListener; public Action OnErrorAction; public AD_Type ADType { get; internal set; } public int State => curState; 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; } } 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 onVideoComplete); public virtual bool IsReadly() { return this.curState == 2; } public abstract void LoadAD(); public virtual void OnInit() { } public virtual void OnPlayRequestStarted() { } public virtual void EnterAdScenario(string scenario) { } /// /// 主动关闭广告 /// public virtual void CloseAD() { } public void OnError(object code, string message) { this.OnErrorAction?.Invoke(); this.OnErrorAction = null; curState = 0; } } }