update: fix Ads Model 计算问题

feature/Inventory
胡宇飞 2024-01-08 20:32:47 +08:00
parent 9a5c201899
commit f9e295df2b
5 changed files with 162 additions and 21 deletions

View File

@ -15,10 +15,24 @@ namespace Guru
public static readonly float DelayTime = 1f; // 延迟启动时间
private static string _adId = "";
public static string AdId => _adId; // Google AdId
public static string AdId
{
get
{
if(string.IsNullOrEmpty(_adId)) FetchGoogleAdId();
return _adId; // Google AdId
}
}
private static string _adujstId = "";
public static string AdjustId => _adujstId; // Adjust AdId;
public static string AdjustId
{
get
{
if (string.IsNullOrEmpty(_adujstId)) _adujstId = Adjust.getAdid();
return _adujstId; // Adjust AdId;
}
}
@ -83,10 +97,10 @@ namespace Guru
// });
// });
FetchAdId(); // 异步加载AdId
FetchGoogleAdId(); // 异步加载AdId
}
public static void FetchAdId()
public static void FetchGoogleAdId()
{
Adjust.getGoogleAdId(gid =>
{

View File

@ -34,6 +34,8 @@ namespace Guru
public static Action OnRewardLoaded;
public static Action OnRewardFailed;
private AdsModel _model;
/// <summary>
/// 启动广告服务
/// </summary>
@ -48,6 +50,7 @@ namespace Guru
_isAutoLoadAds = autoLoadAds;
_isDebugMode = isDebugMode;
_onSdkInitReady = callback;
_model = AdsModel.Create();
this.Log("AD SDK Start Init");
//-------------- 初始化回调 ------------------
@ -114,14 +117,14 @@ namespace Guru
private double TchAD001RevValue
{
get => PlayerPrefs.GetFloat(nameof(TchAD001RevValue), 0f);
set => PlayerPrefs.SetFloat(nameof(TchAD001RevValue), (float)value);
get => _model.TchAD001RevValue;
set => _model.TchAD001RevValue = value;
}
private double TchAD02RevValue
{
get => PlayerPrefs.GetFloat(nameof(TchAD02RevValue), 0f);
set => PlayerPrefs.SetFloat(nameof(TchAD02RevValue), (float)value);
get => _model.TchAD02RevValue;
set => _model.TchAD02RevValue = value;
}
public void OnAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
@ -155,10 +158,10 @@ namespace Guru
{
TchAD001RevValue += revenue;
double revenueValue = TchAD001RevValue;
this.Log("[TaichConfig]", $"获取累计收入TchAD001RevValue:{revenueValue}");
Debug.Log($"[TaichConfig] get <TchAD001RevValue> totally: {revenueValue}");
if (revenueValue >= Analytics.Tch001TargetValue)
{
this.Log("[TaichConfig]", "获取太极收入累计超过0.01打点");
Debug.Log($"[TaichConfig] call <tch_ad_rev_roas_001> with value: {revenueValue}");
Analytics.Tch001ADRev(revenueValue);
TchAD001RevValue = 0.0;
}
@ -174,10 +177,10 @@ namespace Guru
TchAD02RevValue += revenue;
double revenueValue = TchAD02RevValue;
this.Log("[TchConfig]", $"获取累计收入TchAD02RevValue:{revenueValue}");
Debug.Log($"[TchConfig] get <TchAD02RevValue> totally: {revenueValue}");
if (revenueValue >= 0.2f)
{
this.Log("[TchConfig]", "获取太极收入累计超过0.2打点");
Debug.Log($"[TchConfig] call <tch_ad_rev_roas_02> with value:");
Analytics.Tch02ADRev(revenueValue);
TchAD02RevValue = 0.0;
}

View File

@ -0,0 +1,127 @@
namespace Guru
{
using UnityEngine;
public class AdsModel
{
private AdsModelStorage _storage;
public int radsRewardCount = 0;
public double tchAd001Value = 0;
public double tchAd02Value = 0;
public int RadsRewardCount
{
get => radsRewardCount;
set
{
radsRewardCount = value;
Save();
}
}
public double TchAD001RevValue
{
get => tchAd001Value;
set
{
tchAd001Value = value;
Save();
}
}
public double TchAD02RevValue
{
get => tchAd02Value;
set
{
tchAd02Value = value;
Save();
}
}
private void Save()
{
_storage.Save(ToJson());
}
public string ToJson()
{
return JsonUtility.ToJson(this);
}
public static AdsModel Create()
{
AdsModel model;
AdsModelStorage storage;
AdsModelStorage.Create(out model, out storage);
model._storage = storage;
return model;
}
}
internal class AdsModelStorage : MonoBehaviour
{
private const string INSTANCE_NAME = "GuruSDK";
private bool _needToSave = false;
private string _jsonData = "";
public static void Create(out AdsModel model, out AdsModelStorage storage)
{
model = null;
storage = null;
var go = GameObject.Find(INSTANCE_NAME);
if (go == null) go = new GameObject(INSTANCE_NAME);
AdsModelStorage _ins = null;
if (!go.TryGetComponent<AdsModelStorage>(out storage))
{
storage = go.AddComponent<AdsModelStorage>();
}
string json = PlayerPrefs.GetString(nameof(AdsModel), "");
if (!string.IsNullOrEmpty(json))
{
model = JsonUtility.FromJson<AdsModel>(json);
}
else
{
model = new AdsModel();
}
}
public void Save(string json)
{
_jsonData = json;
_needToSave = true;
}
#region 生命周期
void Update()
{
if (_needToSave)
{
PlayerPrefs.SetString(nameof(AdsModel), _jsonData);
_needToSave = false;
}
}
#endregion
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b436508368c24a179b99a5aec61d1f0b
timeCreated: 1704713051

View File

@ -100,8 +100,7 @@ namespace Guru
if (_hasGotAdjustId) return;
string adjustId = AdjustService.AdjustId;
if (!string.IsNullOrEmpty(adjustId)
&& string.IsNullOrEmpty(IPMConfig.ADJUST_ID))
if (!string.IsNullOrEmpty(adjustId))
{
IPMConfig.ADJUST_ID = adjustId;
}
@ -132,11 +131,6 @@ namespace Guru
// Debug.Log($"---[ANA] ADID: {adId}");
IPMConfig.ADJUST_ADID = adId;
}
else
{
AdjustService.FetchAdId();
}
#else
// ============= ADID is not supported on Adjust iOS API ==============
IPMConfig.ADJUST_ADID = VALUE_NOT_FOR_IOS;;