Files
Webview_SgConfig_Unity_IOS/Assets/Scripts/SdkManager.cs
T

414 lines
15 KiB
C#
Raw Normal View History

2026-07-06 16:31:08 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using FairyGUI;
using UnityEngine;
using UnityEngine.EventSystems;
using BingoBrain;
using DG.Tweening;
using BingoBrain;
using BingoBrain.Core;
using BingoBrain.HotFix;
2026-07-07 15:58:59 +08:00
using Unity.VisualScripting.FullSerializer;
using Unity.VisualScripting;
2026-07-08 17:47:04 +08:00
using Newtonsoft.Json;
2026-07-10 10:22:32 +08:00
using System.Collections;
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
namespace DontConfuse
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
public class SdkManager : MonoBehaviour
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
private static SdkManager _instance;
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
// 供外部调用的公共属性
public static SdkManager Instance
{
get
{
// 如果实例为空,尝试在场景中寻找已经挂载的脚本
if (_instance == null)
{
2026-07-10 10:22:32 +08:00
_instance = FindFirstObjectByType<SdkManager>();
2026-07-08 17:47:04 +08:00
if (_instance == null)
{
Debug.LogError("场景中没有找到挂载 SdkManager 的物体!请确保场景中有一个 GameObject 挂载了该脚本。");
}
}
return _instance;
}
2026-07-10 10:22:32 +08:00
}
int time = 0;
void Update()
{
if (Time.time > time)
{
H5sendClass info = new H5sendClass() { link = "www.baidu.com", type = "h6" };
NetworkKit_sdk.PostWithHeader<object>("event/h5Impressions", info, (isSuccess, obj) =>
{
if (isSuccess)
{
Debug.Log("发送成功");
Debug.Log(JsonConvert.SerializeObject(obj));
}
});
time++;
}
2026-07-08 17:47:04 +08:00
}
private void Awake()
{
// 当场景加载时,如果 _instance 还没赋值,就由挂载在物体上的自己来赋值
if (_instance == null)
{
_instance = this;
DontDestroyOnLoad(gameObject); // 可选:如果跨场景不想被销毁,加上这行
}
else if (_instance != this)
{
// 防止场景里不小心挂载了多个 SdkManager secondary 实例直接销毁,保证单例唯一
Destroy(gameObject);
}
}
public void OpenWv()
{
// Debug.Log("[WebviewManager] SetPadding");
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
2026-07-08 17:47:04 +08:00
BrigdeIOS.OpenWv();
2026-07-06 16:31:08 +08:00
#endif
2026-07-08 17:47:04 +08:00
}
public void SetPadding(float left, float top, float right, float bottom)
{
// Debug.Log("[WebviewManager] SetPadding");
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.SetPadding(left, top, right, bottom);
#endif
2026-07-08 17:47:04 +08:00
}
public void SetDarkThough(bool though)
{
if (!GameHelper.IsGiftSwitch()) return;
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.SetDarkThough(though);
#endif
2026-07-08 17:47:04 +08:00
}
public void SetBtn(int left, int top, int right, int bottom)
{
// Debug.Log("[WebviewManager] SetBtn");
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.SetBtn(left, top, right, bottom);
#endif
2026-07-08 17:47:04 +08:00
}
public void addH5Field(int field1, int field2, int field3, int field4, int field5, string field6, string field7, string dark_url, string light_url, bool is_gift, string web_through_str, string click_add_time)
{
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.addH5Field(field1,field2,field3,field4,field5,field6,field7,dark_url,light_url,is_gift,web_through_str,click_add_time);
#endif
2026-07-08 17:47:04 +08:00
}
public void ShowH5View(bool flag)
{
// Debug.Log("[WebviewManager] SetCTEnable");
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.ShowH5View(flag);
#endif
2026-07-08 17:47:04 +08:00
}
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
public void SetIconProgress(float val)
{
// Debug.Log("[WebviewManager] SetCTEnable");
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.SetIconProgress(val);
#endif
2026-07-08 17:47:04 +08:00
}
public void ShowFlyBtn(bool flag)
{
// Debug.Log("[WebviewManager] SetCTEnable");
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.ShowFlyBtn(flag);
#endif
2026-07-08 17:47:04 +08:00
}
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
public void setFlyBtnTag(bool flag)
{
// Debug.Log($"[WebviewManager] setFlyBtnTag ---{flag}");
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.setFlyBtnTag(flag);
#endif
2026-07-08 17:47:04 +08:00
}
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
public void setRewardBtnTag(bool flag)
{
// Debug.Log($"[WebviewManager] setRewardBtnTag--- {flag}");
2026-07-06 16:31:08 +08:00
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.setRewardBtnTag(flag);
#endif
2026-07-08 17:47:04 +08:00
}
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
public void ObjC_TouchClick(string name)
{
// Debug.Log("Touch click: " + name);
GameDispatcher.Instance.Dispatch(BingoInfo.H5ViewClickBtn, name);
}
2026-07-10 10:24:05 +08:00
public void H5AutoRefresh(string string_xcode)
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
if (string_xcode.Contains("|h5"))
{
string[] _string_arr = string_xcode.Split("|");
if (_string_arr.Length >= 2)
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count; i++)
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
if (ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links[i].url == _string_arr[0])
{
light_restoredList[i]++;
string str = string.Join(",", light_restoredList);
PlayerPrefs.SetString("Dailyrefreshnum", str);
break;
}
2026-07-06 16:31:08 +08:00
}
2026-07-10 10:24:05 +08:00
H5sendClass info = new H5sendClass() { link = _string_arr[0], type = "h5" };
NetworkKit_sdk.PostWithHeader<object>("event/h5Impressions", info, (isSuccess, obj) =>
{
if (isSuccess)
{
Debug.Log("发送成功" + _string_arr[0]);
2026-07-06 16:31:08 +08:00
2026-07-10 10:24:05 +08:00
}
});
2026-07-06 16:31:08 +08:00
}
}
2026-07-08 17:47:04 +08:00
else if (string_xcode.Contains("|h6"))
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
string[] _string_arr = string_xcode.Split("|");
if (_string_arr.Length >= 2)
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count; i++)
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
for (int j = 0; j < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links.Count; j++)
{
if (ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].url == _string_arr[0])
{
dark_restoredList[i][j]++;
PlayerPrefs.SetString("Darkrefreshnum", string.Join(";", dark_restoredList.Select(row => string.Join(",", row))));
break;
}
}
2026-07-06 16:31:08 +08:00
}
2026-07-10 10:24:05 +08:00
H5sendClass info = new H5sendClass() { link = _string_arr[0], type = "h6" };
NetworkKit_sdk.PostWithHeader<object>("event/h5Impressions", info, (isSuccess, obj) =>
{
if (isSuccess)
{
Debug.Log("发送成功" + _string_arr[0]);
2026-07-06 16:31:08 +08:00
2026-07-10 10:24:05 +08:00
}
});
}
}
2026-07-06 16:31:08 +08:00
}
2026-07-10 10:24:05 +08:00
2026-07-08 17:47:04 +08:00
private GList select_glist;
private float select_glist_y;
public void TouchClickPoint(string name)
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
// Debug.Log("TouchClickPoint" + name);
if (name == null) return;
if (name == "flyBtn")
{
NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.fly_ct_number, 1);
//NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior,BuriedPointEvent.fly_ct_people,1);
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
}
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
if (name == "rewardBtn")
{
NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_ct_number, 1);
//NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior,BuriedPointEvent.annular_ct_people,1);
}
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
if (name == "finish")
{
NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_finish_number, 1);
}
2026-07-07 15:58:59 +08:00
}
2026-07-08 17:47:04 +08:00
List<int> light_restoredList;
List<List<int>> dark_restoredList;
public void RefreshUrl()
2026-07-07 15:58:59 +08:00
{
2026-07-08 17:47:04 +08:00
string Dailyrefresh_reamain = "";
int last_time = PlayerPrefs.GetInt("Dayreftimes", 0);
DateTime today = DateTime.Now;
int newDays = today.Day;
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
string light_refresh_str = PlayerPrefs.GetString("Dailyrefreshnum", "");
if (string.IsNullOrEmpty(light_refresh_str))
2026-07-07 15:58:59 +08:00
{
2026-07-08 17:47:04 +08:00
light_restoredList = new List<int>();
2026-07-07 15:58:59 +08:00
}
2026-07-08 17:47:04 +08:00
else
2026-07-07 15:58:59 +08:00
{
2026-07-08 17:47:04 +08:00
light_restoredList = light_refresh_str.Split(',').Select(int.Parse).ToList();
2026-07-07 15:58:59 +08:00
}
2026-07-08 17:47:04 +08:00
if (light_restoredList.Count < ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count)
{
int targetCount = ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count;
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
for (int i = light_restoredList.Count; i < targetCount; i++)
{
light_restoredList.Add(0);
}
}
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
if (last_time == newDays)
{
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
}
else
{
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
for (int i = 0; i < light_restoredList.Count; i++)
{
light_restoredList[i] = 0;
}
string str = string.Join(",", light_restoredList);
PlayerPrefs.SetString("Dailyrefreshnum", str);
PlayerPrefs.SetInt("Dayreftimes", newDays);
}
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
int dark_last_time = PlayerPrefs.GetInt("dark_refreshDay", 0);
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
string darkWVDailyrefreshtimes_str = "";
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
string dark_refresh_str = PlayerPrefs.GetString("Darkrefreshnum", "");
if (string.IsNullOrEmpty(dark_refresh_str))
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
dark_restoredList = new List<List<int>>();
2026-07-06 16:31:08 +08:00
}
2026-07-08 17:47:04 +08:00
else
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
dark_restoredList = dark_refresh_str.Split(';').Select(row => row.Split(',').Select(int.Parse).ToList()).ToList();
2026-07-06 16:31:08 +08:00
}
2026-07-07 15:58:59 +08:00
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
if (dark_restoredList.Count < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count)
{
int targetCount = ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count;
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
for (int i = dark_restoredList.Count; i < targetCount; i++)
{
dark_restoredList.Add(new List<int>());
}
}
2026-07-07 15:58:59 +08:00
for (int i = 0; i < dark_restoredList.Count; i++)
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
if (ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count > i)
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
int targetCount = ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links.Count;
if (dark_restoredList[i].Count < targetCount)
{
for (int j = dark_restoredList[i].Count; j < targetCount; j++)
{
dark_restoredList[i].Add(0);
}
}
2026-07-06 16:31:08 +08:00
}
}
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
if (dark_last_time == newDays)
2026-07-06 16:31:08 +08:00
{
}
2026-07-08 17:47:04 +08:00
else
{
for (int i = 0; i < dark_restoredList.Count; i++)
{
for (int j = 0; j < dark_restoredList[i].Count; j++)
{
dark_restoredList[i][j] = 0;
}
}
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
PlayerPrefs.SetInt("dark_refreshDay", newDays);
PlayerPrefs.SetString("Darkrefreshnum", string.Join(";", dark_restoredList.Select(row => string.Join(",", row))));
}
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
string light_str = "";
string dark_str = "";
int can_refresh_numbners = 0;
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count; i++)
2026-07-06 16:31:08 +08:00
{
2026-07-08 17:47:04 +08:00
if (i != 0)
2026-07-07 15:58:59 +08:00
{
2026-07-08 17:47:04 +08:00
light_str += "|";
2026-07-07 15:58:59 +08:00
}
2026-07-08 17:47:04 +08:00
light_str += ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links[i].url + "#" + ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links[i].weight + "#" + (ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links[i].maxF5Times - light_restoredList[i]);
2026-07-06 16:31:08 +08:00
}
2026-07-08 17:47:04 +08:00
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count; i++)
{
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
for (int j = 0; j < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links.Count; j++)
{
if (i != 0 || j != 0)
{
dark_str += "|";
}
dark_str += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].url + "#" + ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].weight + "#" + (ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].maxF5Times - dark_restoredList[i][j]) +
"#" + ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].ctProb + "#" + ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].layerId + "#" + ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].offset;
}
}
2026-07-06 16:31:08 +08:00
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
string darkWVRefreshtime_str = "";
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
string add_time = "";
string layer_click_probability = "";
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count; i++)
{
if (i != 0)
{
darkWVRefreshtime_str += "|";
add_time += "|";
layer_click_probability += "|";
}
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
darkWVRefreshtime_str += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].f5Interval.min;
darkWVRefreshtime_str += "|";
darkWVRefreshtime_str += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].f5Interval.max;
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
add_time += UnityEngine.Random.Range(ConfigSystem_sdk.Instance.SDKConfig.h6Conf.ADClickF5Delay.min, ConfigSystem_sdk.Instance.SDKConfig.h6Conf.ADClickF5Delay.max + 1);
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
layer_click_probability += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].weight;
}
Debug.Log("|||||||||||||||||||||--------------------------------");
2026-07-07 15:58:59 +08:00
2026-07-08 17:47:04 +08:00
Debug.Log(darkWVRefreshtime_str);
2026-07-06 16:31:08 +08:00
2026-07-08 17:47:04 +08:00
Debug.Log(dark_str);
Debug.Log(light_str);
Debug.Log(layer_click_probability);
Debug.Log(add_time);
addH5Field(ConfigSystem.GetConfig<CommonModel>().flyCtRate, ConfigSystem.GetConfig<CommonModel>().otherH5switch,
UnityEngine.Random.Range(ConfigSystem_sdk.Instance.SDKConfig.h5Conf.f5Interval.min, ConfigSystem_sdk.Instance.SDKConfig.h5Conf.f5Interval.max + 1), -1, -1
, darkWVRefreshtime_str, "", dark_str, light_str, GameHelper.IsGiftSwitch(), layer_click_probability, add_time);
2026-07-06 16:31:08 +08:00
}
}
}