h5sdk提交
This commit is contained in:
@@ -0,0 +1,246 @@
|
||||
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;
|
||||
|
||||
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");
|
||||
}
|
||||
// else //没有就从StreamingAssets读取
|
||||
// {
|
||||
// var path = $"{Application.streamingAssetsPath}/Config/{configFileName}.txt";
|
||||
// #if UNITY_IOS
|
||||
// path = "file://" + path;
|
||||
// #endif
|
||||
// // Debug.Log($"[UNITY] Load config from streaming asset: {path}");
|
||||
// IsfvKit.StartCoroutine(CachKit.GetTextFromUrl(path, configFileName, content =>
|
||||
// {
|
||||
// ParseConfig(content);
|
||||
// // UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NetLoadingUI_Close);
|
||||
// AppDispatcher.Instance.Dispatch(CsjInfoC.LoginInit);
|
||||
// GameHelper.PostFunnelLogin("loadFinish");
|
||||
// }, configFileSavePath));
|
||||
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
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"));
|
||||
// json = Base64Kit.Decode(json, "com.matchgame.captaindicedubloons");
|
||||
}
|
||||
Debug.Log("转化后的json" + json);
|
||||
SetConfig(json);
|
||||
if (true)
|
||||
{
|
||||
// SdkManager.
|
||||
}
|
||||
// CtrlDispatcher.Instance.Dispatch(CtrlMsg.Game_StartBefore);
|
||||
|
||||
}
|
||||
RootObject SDKConfig;
|
||||
private void SetConfig(string json_)
|
||||
{
|
||||
SDKConfig = JsonConvert.DeserializeObject<RootObject>(json_);
|
||||
|
||||
|
||||
// for (int i = 0; i < SDKConfig.h5Conf.links.Count; i++)
|
||||
// {
|
||||
// light_weblist.Add(data_new[i]);
|
||||
// }
|
||||
|
||||
|
||||
// List<int> type_list = new List<int>();
|
||||
|
||||
|
||||
// for (int i = 0; i < SDKConfig.h6Conf.layerConfList.Count; i++)
|
||||
// {
|
||||
|
||||
|
||||
|
||||
// dark_weblist.Add(data_new[i]);
|
||||
|
||||
// if (!type_list.Contains(data_new[i].wvType))
|
||||
// {
|
||||
// web_through_str += data_new[i].wvthrough;
|
||||
// web_through_str += "|";
|
||||
// type_list.Add(data_new[i].wvType);
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// web_through_str.Remove(web_through_str.Length - 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user