265 lines
9.0 KiB
C#
265 lines
9.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using BingoBrain.Core;
|
|
using UnityEngine;
|
|
using BingoBrain.Asset;
|
|
using BingoBrain.HotFix;
|
|
using System.Collections.Generic;
|
|
using Newtonsoft.Json;
|
|
using BingoBrain;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using DontConfuse;
|
|
namespace BingoBrain
|
|
{
|
|
public class ConfigSystem_sdk
|
|
{
|
|
|
|
private ConfigSystem_sdk()
|
|
{
|
|
}
|
|
private static readonly ConfigSystem_sdk _instance = new ConfigSystem_sdk();
|
|
|
|
public static ConfigSystem_sdk Instance
|
|
{
|
|
get { return _instance; }
|
|
}
|
|
|
|
private static Dictionary<Type, object> configData = new();
|
|
public void OnRequestGetConfig()
|
|
{
|
|
GameHelper.PostFunnelLogin("loadBegin");
|
|
var loginData = LoginModel_sdk.Instance;
|
|
|
|
var configFileName = "Json";
|
|
var configFileSavePath = $"{Application.persistentDataPath}/sdkConfig/";
|
|
var assetHotFixFilePath = $"{configFileSavePath}{configFileName}.txt";
|
|
var configFileNameKey = "sdkconfigFileName";
|
|
|
|
var CDNConfigFileName = loginData.setting;
|
|
string savedCfgName = PlayerPrefs.GetString(configFileNameKey);
|
|
bool needDownloadConfigFile = false;
|
|
|
|
if (!string.IsNullOrEmpty(CDNConfigFileName))
|
|
{
|
|
//如果本地Player Prefs里没有保存配置文件名
|
|
if (string.IsNullOrEmpty(savedCfgName))
|
|
{
|
|
// Debug.Log("[UNITY] No config file name saved.");
|
|
needDownloadConfigFile = true;
|
|
}
|
|
else
|
|
{
|
|
// Debug.Log($"[UNITY] Saved config name: {savedCfgName}, CDN config name: {CDNConfigFileName}");
|
|
//与CDN上的对比名称
|
|
if (!savedCfgName.Equals(CDNConfigFileName))
|
|
{
|
|
needDownloadConfigFile = true;
|
|
}
|
|
}
|
|
}
|
|
//Debug.Log($"[UNITY] needDownloadConfigFile: {needDownloadConfigFile}");
|
|
//默默地拉去新配置
|
|
// Debug.Log("kkkkkkkkkkkkkkkkkkkkkk" + needDownloadConfigFile);
|
|
// Debug.Log("kkkkkkkkkkkkkkkkkkkkkk" + savedCfgName);
|
|
|
|
if (needDownloadConfigFile || !File.Exists(assetHotFixFilePath))
|
|
{
|
|
IsfvKit.StartCoroutine(CachKit.GetTextFromUrl($"{loginData.cdn_url}/config/{CDNConfigFileName}",
|
|
configFileName, (content) =>
|
|
{
|
|
PlayerPrefs.SetString(configFileNameKey, CDNConfigFileName);
|
|
ParseConfig(content);
|
|
//CtrlDispatcher.Instance.Dispatch(CtrlMsg.NewConfigRead);
|
|
}, configFileSavePath));
|
|
}
|
|
|
|
//检查设备本地是否有配置文件
|
|
if (File.Exists(assetHotFixFilePath))
|
|
{
|
|
// Debug.Log($"[UNITY] Load config from datapath: {assetHotFixFilePath}");
|
|
ParseConfig(File.ReadAllText(assetHotFixFilePath));
|
|
// UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NetLoadingUI_Close);
|
|
AppDispatcher.Instance.Dispatch(CsjInfoC.LoginInit);
|
|
GameHelper.PostFunnelLogin("loadFinish");
|
|
}
|
|
}
|
|
|
|
private void ParseConfig(string json)
|
|
{
|
|
Debug.Log("sdk--------json" + json);
|
|
if (json == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!json.StartsWith("{"))
|
|
{
|
|
json = Encoding.UTF8.GetString(Base64Kit_sdk.Decrypt(Encoding.UTF8.GetBytes(json),
|
|
"com.matchgame.captaindicedubloons"));
|
|
}
|
|
Debug.Log("转化后的json" + json);
|
|
SetConfig(json);
|
|
|
|
Debug.Log(LoginModel_sdk.Instance.reg_time);
|
|
Debug.Log(GetRegisteredCalendarDaysByUTC(LoginModel_sdk.Instance.reg_time));
|
|
int reg_days = GetRegisteredCalendarDaysByUTC(LoginModel_sdk.Instance.reg_time);
|
|
bool open_dark_wv = true;
|
|
if (SDKConfig.h6Conf.switchCondition != null)
|
|
{
|
|
for (int i = 0; i < SDKConfig.h6Conf.switchCondition.retentionConf.Count; i++)
|
|
{
|
|
if ((reg_days >= SDKConfig.h6Conf.switchCondition.retentionConf[i].days.min) &&
|
|
(reg_days <= SDKConfig.h6Conf.switchCondition.retentionConf[i].days.max))
|
|
{
|
|
if (UnityEngine.Random.Range(0, 100) >= SDKConfig.h6Conf.switchCondition.retentionConf[i].prob)
|
|
{
|
|
open_dark_wv = false;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
Debug.Log(open_dark_wv);
|
|
if (open_dark_wv)
|
|
{
|
|
SdkManager.Instance.OpenWv();
|
|
// int flyswitch = ConfigSystem.GetConfig<CommonModel>().flyswitch;
|
|
// int propswitch = ConfigSystem.GetConfig<CommonModel>().propswitch;
|
|
// float top_offset = 150;//fgui中的顶部信息的高度
|
|
// float buttom_offset = 0;
|
|
// if (Screen.safeArea.y != 0)
|
|
// {//刘海屏
|
|
// top_offset += Screen.safeArea.y;
|
|
// }
|
|
|
|
// SdkManager.Instance.setFlyBtnTag(flyswitch == 1);
|
|
// SdkManager.Instance.setRewardBtnTag(propswitch == 1);
|
|
// SdkManager.Instance.SetBtn(ConfigSystem.GetConfig<CommonModel>().propCoord[0], ConfigSystem.GetConfig<CommonModel>().propCoord[1], 60, 60);
|
|
// SdkManager.Instance.SetPadding(0, top_offset / GRoot.inst.height, 0, buttom_offset / GRoot.inst.height);
|
|
SdkManager.Instance.SetDarkThough(true);
|
|
SdkManager.Instance.ShowH5View(false);
|
|
SdkManager.Instance.RefreshUrl();
|
|
}
|
|
}
|
|
public int GetRegisteredCalendarDaysByUTC(long regTimeTimestamp)
|
|
{
|
|
// 1. 转换为 0时区 的日期部分(抹去具体时分秒,变成 00:00:00)
|
|
DateTime regDateUtc = DateTimeOffset.FromUnixTimeSeconds(regTimeTimestamp).UtcDateTime.Date;
|
|
|
|
// 2. 获取当前 0时区 的日期部分
|
|
DateTime nowDateUtc = DateTimeOffset.UtcNow.UtcDateTime.Date;
|
|
|
|
// 3. 两个 0时区的日期直接相减
|
|
TimeSpan difference = nowDateUtc - regDateUtc;
|
|
|
|
int days = difference.Days;
|
|
return days < 0 ? 0 : days;
|
|
}
|
|
public RootObject SDKConfig;
|
|
private void SetConfig(string json_)
|
|
{
|
|
SDKConfig = JsonConvert.DeserializeObject<RootObject>(json_);
|
|
for (int i = 0; i < SDKConfig.h5Conf.links.Count; i++)
|
|
{
|
|
if (SDKConfig.h5Conf.links[i].maxF5Times < 0)
|
|
{
|
|
SDKConfig.h5Conf.links[i].maxF5Times = 99999;
|
|
}
|
|
}
|
|
for (int i = 0; i < SDKConfig.h6Conf.layerConfList.Count; i++)
|
|
{
|
|
for (int j = 0; j < SDKConfig.h6Conf.layerConfList[i].links.Count; j++)
|
|
{
|
|
if (SDKConfig.h6Conf.layerConfList[i].links[j].maxF5Times < 0)
|
|
{
|
|
SDKConfig.h6Conf.layerConfList[i].links[j].maxF5Times = 99999;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public class RootObject
|
|
{
|
|
public string bid;
|
|
public H5Conf h5Conf;
|
|
public H6Conf h6Conf;
|
|
}
|
|
|
|
public class H5Conf
|
|
{
|
|
public F5Interval f5Interval;//自动刷新间隔
|
|
public List<H5Link> links; // H5 的 Link
|
|
}
|
|
|
|
public class F5Interval
|
|
{
|
|
public int min;
|
|
public int max;
|
|
}
|
|
|
|
public class H5Link
|
|
{
|
|
public int id;
|
|
public string url;
|
|
public int weight;
|
|
public int maxF5Times;
|
|
}
|
|
|
|
public class H6Conf
|
|
{
|
|
public int layers;//层数总数
|
|
public ADClickF5Delay ADClickF5Delay;//延长时间
|
|
public SwitchCondition switchCondition;//开启条件
|
|
public List<LayerConfList> layerConfList;
|
|
}
|
|
|
|
public class ADClickF5Delay
|
|
{
|
|
public int min;
|
|
public int max;
|
|
}
|
|
|
|
public class SwitchCondition//开启条件
|
|
{
|
|
public List<RetentionConf> retentionConf; // 已经实例化为具体类型
|
|
}
|
|
|
|
public class RetentionConf//开启条件
|
|
{
|
|
public Days days;
|
|
public int prob;
|
|
}
|
|
|
|
public class Days
|
|
{
|
|
public int min;
|
|
public int max;
|
|
}
|
|
|
|
public class LayerConfList
|
|
{
|
|
public int layerId;//第几层
|
|
public int weight;//显示权重
|
|
public F5Interval f5Interval;//自动刷新间隔
|
|
public int offset;
|
|
public List<H6Link> links; // H6 内部图层的 Link
|
|
}
|
|
|
|
public class H6Link
|
|
{
|
|
public int id;
|
|
public string url;
|
|
public int weight;
|
|
public int maxF5Times;//刷新上限
|
|
public int ctProb;
|
|
public int ctProb2;
|
|
}
|
|
|
|
|
|
} |