123 lines
3.5 KiB
C#
123 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using EFSDK;
|
|
using Firebase.Analytics;
|
|
using UnityEngine;
|
|
|
|
namespace WZ
|
|
{
|
|
public class EFSdkManager : D_MonoSingleton<EFSdkManager>
|
|
{
|
|
private const string KEY_OKSPIN_SHOW_COUNT = "OKSPIN_SHOW_COUNT";
|
|
|
|
//互动广告位
|
|
private string okspinShowPos = "";
|
|
|
|
private Action<string> _webviewShowSuccessAction;
|
|
|
|
//保存的链接
|
|
private List<string> urls = new List<string>();
|
|
|
|
public void Init()
|
|
{
|
|
if (Application.isEditor)
|
|
{
|
|
return;
|
|
}
|
|
EFSdk.get().Init((actionType, str) =>
|
|
{
|
|
if (actionType == EFSdk.ActionType.H5_Load_Succ)
|
|
{
|
|
_webviewShowSuccessAction?.Invoke(str);
|
|
}
|
|
});
|
|
|
|
SetSDKEventCallback();
|
|
SetHdH5ImpressionCallback();
|
|
}
|
|
|
|
private void SetSDKEventCallback()
|
|
{
|
|
EFSdk.get().SetSDKEventCallback((eventName, dict) =>
|
|
{
|
|
FireBaseAnalyticsManager.Instance.LogEvent(eventName, dict);
|
|
ShuShuEvent.Instance.Track(eventName, dict);
|
|
});
|
|
}
|
|
|
|
// <summary>
|
|
/// 互动广告展示回调,此时可以计算上报互动广告展示次数和收益
|
|
/// </summary>
|
|
/// <param name="callback">string 是互动广告的url</param>
|
|
public void SetHdH5ImpressionCallback()
|
|
{
|
|
EFSdk.get().SetHdH5ImpressionCallback((pid) =>
|
|
{
|
|
//判断链接不为空
|
|
if (string.IsNullOrEmpty(pid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//展示次数
|
|
int count = PlayerPrefsUtils.GetPlayerPrefsInt(KEY_OKSPIN_SHOW_COUNT, 0);
|
|
count++;
|
|
PlayerPrefsUtils.SavePlayerPrefsInt(KEY_OKSPIN_SHOW_COUNT, count);
|
|
|
|
string url = GetUrl(pid);
|
|
|
|
//互动广告只有okSpin
|
|
float revenue = FireBaseRemoteConfigManager.Instance.GetRemoteConfigFloat("rev_okspin", 0);
|
|
|
|
//adjust
|
|
AdjustTrackEvent.Instance.TrackAdEvent(revenue, "H5ad_game", url, url);
|
|
//firebase
|
|
FireBaseAnalyticsManager.Instance.OnAdRevenueEvent("H5ad_game", "H5ad_game", url, AdsType.Fix, revenue, okspinShowPos, count);
|
|
//数数
|
|
ShuShuEvent.Instance.OnAdRevenueEvent("H5ad_game", "H5ad_game", url, AdsType.Fix.ToString(), revenue, okspinShowPos, count);
|
|
});
|
|
}
|
|
|
|
public void SetOkspinShowPos(string pos)
|
|
{
|
|
okspinShowPos = pos;
|
|
}
|
|
|
|
public void SetWebviewShowSuccessAction(Action<string> action)
|
|
{
|
|
_webviewShowSuccessAction = action;
|
|
}
|
|
|
|
public void AddUrl(int id, string url)
|
|
{
|
|
if (!urls.Contains(url))
|
|
{
|
|
urls.Add(url);
|
|
}
|
|
}
|
|
|
|
private string GetUrl(string pid)
|
|
{
|
|
foreach (var url in urls)
|
|
{
|
|
if (url.Contains(pid))
|
|
{
|
|
return url;
|
|
}
|
|
}
|
|
|
|
return pid;
|
|
}
|
|
|
|
private void OnApplicationFocus(bool hasFocus)
|
|
{
|
|
if (Application.isEditor)
|
|
{
|
|
return;
|
|
}
|
|
EFSdk.get().SetGameActive(hasFocus);
|
|
}
|
|
|
|
|
|
}
|
|
} |