diff --git a/Assets/CrazyZoo/Runtime/Logic/Helper/GameHelper.cs b/Assets/CrazyZoo/Runtime/Logic/Helper/GameHelper.cs index 6394c3f..90177ef 100644 --- a/Assets/CrazyZoo/Runtime/Logic/Helper/GameHelper.cs +++ b/Assets/CrazyZoo/Runtime/Logic/Helper/GameHelper.cs @@ -125,7 +125,7 @@ namespace ScrewsMaster public static void ShowInterstitial(string key) { - #if !UNITY_EDITOR +#if !UNITY_EDITOR //if(Random.Range(0, 100)>ConfigSystem.GetConfig().interstitialtype) return; MaxADKit.ShowInterstitial(key, isSuccess => { @@ -1100,18 +1100,27 @@ namespace ScrewsMaster public static void AddInterAdNumber() { look_interad_numbers++; - if (IsGiftSwitch() && !SaveData.GetSaveobject().is_get_removead && look_interad_numbers >= ConfigSystem.GetConfig().playtimes) + if (IsGiftSwitch() && look_interad_numbers >= ConfigSystem.GetConfig().playtimes) { look_interad_numbers = 0; if (Random.Range(0, 100) < ConfigSystem.GetConfig().interstitialtype) { - if (UIManager.Instance.IsExistUI(UIConst.H5UI)) - GameHelper.ShowInterstitial("interstitial_h5reward"); - else - UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.AdcomingUI_Open); + GameHelper.ShowInterstitial("interstitial_h5reward"); } } + // if (IsGiftSwitch() && !SaveData.GetSaveobject().is_get_removead && look_interad_numbers >= ConfigSystem.GetConfig().playtimes) + // { + // look_interad_numbers = 0; + + // if (Random.Range(0, 100) < ConfigSystem.GetConfig().interstitialtype) + // { + // if (UIManager.Instance.IsExistUI(UIConst.H5UI)) + // GameHelper.ShowInterstitial("interstitial_h5reward"); + // else + // UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.AdcomingUI_Open); + // } + // } } public static Dictionary statusDic = new Dictionary(); @@ -1321,7 +1330,7 @@ namespace ScrewsMaster { isAd = false; } - return true;//zhushi + return true;//zhushi // return false;//zhushi return isAd; } @@ -1346,7 +1355,7 @@ namespace ScrewsMaster m_gameTimes = 0; PlayerPrefs.SetInt("game_times", m_gameTimes); -Debug.Log("fasongshichang"); + Debug.Log("fasongshichang"); NetworkKit.PostWithHeader("event/gameTime", respData, (isSuccess, obj) => { Debug.Log($"PlayGameTimeEvent==== {m_gameTimes}"); diff --git a/Assets/CrazyZoo/Runtime/Logic/MainScene.cs b/Assets/CrazyZoo/Runtime/Logic/MainScene.cs index de9c965..31d7576 100644 --- a/Assets/CrazyZoo/Runtime/Logic/MainScene.cs +++ b/Assets/CrazyZoo/Runtime/Logic/MainScene.cs @@ -87,10 +87,10 @@ namespace ScrewsMaster SaveingPotHelper.CheckSaveingPot(); SaveingPotHelper.TestingClearTime(); - if (GameHelper.IsGiftSwitch()) - { - WebviewManager.Instance.openWebview(); - } + // if (GameHelper.IsGiftSwitch()) + // { + // WebviewManager.Instance.openWebview(); + // } }); } @@ -98,6 +98,7 @@ namespace ScrewsMaster private void ShowScene() { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.GameLoginUI_Open); + LoginSystem_sdk.Instance.RequestLogin(); } public override void Dispose() diff --git a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/GetTaskReward/GetTaskRewardUI.cs b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/GetTaskReward/GetTaskRewardUI.cs index 54ecb80..7557390 100644 --- a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/GetTaskReward/GetTaskRewardUI.cs +++ b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/GetTaskReward/GetTaskRewardUI.cs @@ -10,6 +10,7 @@ using FGUI.G009_video; using Newtonsoft.Json; using Roy.Datas; using Random = UnityEngine.Random; +using DontConfuse; namespace ScrewsMaster { @@ -55,7 +56,7 @@ namespace ScrewsMaster closeCallback?.Invoke(); if (_settlementData != null && _settlementData.is_h5_reward) { - WebviewManager.Instance.ShowH5View(true); + SdkManager.Instance.ShowH5View(true); GameDispatcher.Instance.Dispatch(GameMsg.resetH5progress); } @@ -87,7 +88,7 @@ namespace ScrewsMaster if (_settlementData.is_h5_reward) { - WebviewManager.Instance.ShowH5View(false); + SdkManager.Instance.ShowH5View(false); } _isTaskReward = false; diff --git a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/H5/H5UI.cs b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/H5/H5UI.cs index c468c7a..980a901 100644 --- a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/H5/H5UI.cs +++ b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/H5/H5UI.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using DG.Tweening; +using DontConfuse; using FGUI.G004_webview; using Roy.Datas; using UnityEngine; @@ -111,7 +112,7 @@ namespace ScrewsMaster { _flySwitch = GameHelper.GetCommonModel().flyswitch == 1; _propSwitch = GameHelper.GetCommonModel().propswitch == 1; - WebviewManager.Instance.ShowFlyBtn(true); + SdkManager.Instance.ShowFlyBtn(true); // HallManager.Instance.SetInH5(true); model.show102 = GameHelper.Get102(); @@ -195,7 +196,7 @@ namespace ScrewsMaster float amount = (float)iconTime / ConfigSystem.GetConfig().ThroughRewardCD; - WebviewManager.Instance.SetIconProgress(amount); + SdkManager.Instance.SetIconProgress(amount); if (!_propSwitch) { @@ -319,8 +320,7 @@ namespace ScrewsMaster { GameHelper.showGameUI = true; - WebviewManager.Instance.setInH5View(false); - WebviewManager.Instance.ShowH5View(false); + SdkManager.Instance.ShowH5View(false); // WebThroughUtil.WebThroughDisable(H5WebThroughType.OnlineH5, ui.btn_icon); StopFly(); countDownKit?.OnDestroy(); @@ -343,8 +343,7 @@ namespace ScrewsMaster // ui.TopBox.y += Screen.safeArea.y; } - WebviewManager.Instance.setInH5View(true); - WebviewManager.Instance.ShowH5View(true); + SdkManager.Instance.ShowH5View(true); makeupTaskData_saveing = SaveData.GetSaveobject().saveingpot_history[SaveData.GetSaveobject().saveingpot_history.Count - 1]; InitData(); InitView(); @@ -406,7 +405,7 @@ namespace ScrewsMaster // ui.com_fly.visible = leftTime <= 0; if (leftTime > 0) { - WebviewManager.Instance.ShowFlyBtn(false); + SdkManager.Instance.ShowFlyBtn(false); isFlyShow = false; StopFlyCountdown(); @@ -414,7 +413,7 @@ namespace ScrewsMaster } else { - if (!isFlyShow) WebviewManager.Instance.ShowFlyBtn(true); + if (!isFlyShow) SdkManager.Instance.ShowFlyBtn(true); isFlyShow = true; StartFly(); diff --git a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/MakeupConfirm/MakeupConfirmUI.cs b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/MakeupConfirm/MakeupConfirmUI.cs index 3979fc4..b30dc9a 100644 --- a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/MakeupConfirm/MakeupConfirmUI.cs +++ b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/MakeupConfirm/MakeupConfirmUI.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using FGUI.A000_common; using FGUI.G018_GameHome; +using DontConfuse; namespace ScrewsMaster { @@ -51,7 +52,7 @@ namespace ScrewsMaster HallManager.Instance.UpdateSecondEvent -= updateSpeedCD; GameHelper.showGameUI = true; - WebviewManager.Instance.SetDarkThough(true); + SdkManager.Instance.SetDarkThough(true); gameDispatcher.Dispatch(GameMsg.MakeUpConfirmUIClosed); } @@ -66,7 +67,7 @@ namespace ScrewsMaster userUid = GameHelper.GetLoginModel().uid; ad_cool_down = ConfigSystem.GetConfig().WithdrawalaccelerationCD; //PreferencesMgr.Instance.MakeupTaskH5Time = 999999999; - WebviewManager.Instance.SetDarkThough(false); + SdkManager.Instance.SetDarkThough(false); if (AppConst.isPt()) { ui.lang.selectedIndex = com_confirm.Lang_pt; diff --git a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/Profile/ProfileUI.cs b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/Profile/ProfileUI.cs index 9edcbfd..2ad9046 100644 --- a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/Profile/ProfileUI.cs +++ b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/Profile/ProfileUI.cs @@ -1,5 +1,6 @@ namespace ScrewsMaster { + using DontConfuse; using FairyGUI; using FGUI.G006_menu; @@ -38,7 +39,7 @@ namespace ScrewsMaster protected override void OnClose() { - WebviewManager.Instance.SetDarkThough(true); + SdkManager.Instance.SetDarkThough(true); CommonHelper.FadeOut(ui); } @@ -49,7 +50,7 @@ namespace ScrewsMaster protected override void OnOpenBefore(object args) { - WebviewManager.Instance.SetDarkThough(false); + SdkManager.Instance.SetDarkThough(false); InitData(); InitView(); } diff --git a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/Prop/PropUI.cs b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/Prop/PropUI.cs index 49a1e17..438d0ae 100644 --- a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/Prop/PropUI.cs +++ b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/Prop/PropUI.cs @@ -128,13 +128,13 @@ namespace ScrewsMaster //初始化页面逻辑 private void InitView() { - var addPrice = ConfigSystem.GetConfig().Purchaseprops; - var mergePrice = ConfigSystem.GetConfig().Purchaseprops; - var cleanPrice = ConfigSystem.GetConfig().Purchaseprops; + // var addPrice = ConfigSystem.GetConfig().Purchaseprops; + // var mergePrice = ConfigSystem.GetConfig().Purchaseprops; + // var cleanPrice = ConfigSystem.GetConfig().Purchaseprops; _payBoxPrice = (int)ConfigSystem.GetConfig().addspace; if (type != 3) { - _payBoxPrice = 1; + _payBoxPrice = ConfigSystem.GetConfig().Purchaseprops; } @@ -221,7 +221,7 @@ namespace ScrewsMaster else if (type == 2) GameHelper.AddItemNumber(ItemEnum.ClearHole, 1); SetButtonsTouchable(false); CtrlCloseUI(); - ShowScrews.Instance.ShowToast("Successful purchase"); + ShowScrews.Instance.ShowToast("Exchange successful"); } else { @@ -249,7 +249,7 @@ namespace ScrewsMaster ShowScrews.Instance.OnSuccessPayBox1(num); SetButtonsTouchable(false); CtrlCloseUI(); - ShowScrews.Instance.ShowToast("Successful purchase"); + ShowScrews.Instance.ShowToast("Exchange successful"); } else { diff --git a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/SaveingPot/SaveingPotUI.cs b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/SaveingPot/SaveingPotUI.cs index 84b937e..b3d32be 100644 --- a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/SaveingPot/SaveingPotUI.cs +++ b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/SaveingPot/SaveingPotUI.cs @@ -10,6 +10,7 @@ using UnityEngine.PlayerLoop; using Spine.Unity; using DG.Tweening; using FGUI.G018_GameHome; +using DontConfuse; namespace ScrewsMaster { @@ -49,7 +50,7 @@ namespace ScrewsMaster { HallManager.Instance.UpdateSecondEvent -= updateSpeedCD; closeCallback?.Invoke(); - WebviewManager.Instance.SetDarkThough(true); + SdkManager.Instance.SetDarkThough(true); GameDispatcher.Instance.Dispatch(GameMsg.RefreshSaveingPot); } private SkeletonAnimation ske_pot; @@ -67,7 +68,7 @@ namespace ScrewsMaster UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Close); ske_pot = FXManager.Instance.SetFx(ui.ani_potparent, Fx_Type.fx_savepot, ref closeCallback); ske_pot.state.SetAnimation(0, "edie", true); - WebviewManager.Instance.SetDarkThough(false); + SdkManager.Instance.SetDarkThough(false); SaveingPotHelper.TestingClearTime(); makeupTaskData = SaveData.GetSaveobject().saveingpot_history[SaveData.GetSaveobject().saveingpot_history.Count - 1]; // makeupTaskData.H5Time = 99999999999999; diff --git a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/SheepPlay/SheepPlayUI.cs b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/SheepPlay/SheepPlayUI.cs index 32c795d..3c15019 100644 --- a/Assets/CrazyZoo/Runtime/Logic/ModuleUI/SheepPlay/SheepPlayUI.cs +++ b/Assets/CrazyZoo/Runtime/Logic/ModuleUI/SheepPlay/SheepPlayUI.cs @@ -643,18 +643,18 @@ namespace ScrewsMaster ui.btn_task.red.visible = SaveData.getRed(); if (!GameHelper.IsGiftSwitch()) return; - if ((!SaveData.GetSaveobject().is_get_packreward || !SaveData.GetSaveobject().is_get_removead) && !SaveData.GetSaveobject().is_autopack_show - && GameHelper.showGameUI && (Time.time > (ConfigSystem.GetConfig().Activetimes * 60))) - { + // if ((!SaveData.GetSaveobject().is_get_packreward || !SaveData.GetSaveobject().is_get_removead) && !SaveData.GetSaveobject().is_autopack_show + // && GameHelper.showGameUI && (Time.time > (ConfigSystem.GetConfig().Activetimes * 60))) + // { - PackRewardData param = new PackRewardData(); - param.isAutoPop = true; - param.isNeedScroll = false; - UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PackrewardUI_Open, param); - SaveData.GetSaveobject().is_autopack_show = true; - SaveData.GetSaveobject().is_autopack_show_day = DateTime.Now.Day; - SaveData.saveDataFunc(); - } + // PackRewardData param = new PackRewardData(); + // param.isAutoPop = true; + // param.isNeedScroll = false; + // UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PackrewardUI_Open, param); + // SaveData.GetSaveobject().is_autopack_show = true; + // SaveData.GetSaveobject().is_autopack_show_day = DateTime.Now.Day; + // SaveData.saveDataFunc(); + // } } } } \ No newline at end of file diff --git a/Assets/Plugins/iOS/CircularProgressBar.h b/Assets/Plugins/iOS/CircularProgressBar.h new file mode 100644 index 0000000..abdc71d --- /dev/null +++ b/Assets/Plugins/iOS/CircularProgressBar.h @@ -0,0 +1,18 @@ +// +// CircularProgressBar.h +// TestGameWeb +// +// Created by Mac on 2024/1/30. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface CircularProgressBar : UIView +-(void)updateUI; +-(void)animateCircleWithStrokeEnd:(float)end; +-(void)setProgress:(float)value; +@end + +NS_ASSUME_NONNULL_END diff --git a/Assets/Plugins/iOS/HapticFeedbackManager.h.meta b/Assets/Plugins/iOS/CircularProgressBar.h.meta similarity index 93% rename from Assets/Plugins/iOS/HapticFeedbackManager.h.meta rename to Assets/Plugins/iOS/CircularProgressBar.h.meta index ad3c285..ee116a5 100644 --- a/Assets/Plugins/iOS/HapticFeedbackManager.h.meta +++ b/Assets/Plugins/iOS/CircularProgressBar.h.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c9ce6d3a070acdf4394bf7556c953c27 +guid: b2a448b036fdc7344a094869a27dea0f PluginImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Plugins/iOS/CircularProgressBar.m b/Assets/Plugins/iOS/CircularProgressBar.m new file mode 100644 index 0000000..275fec8 --- /dev/null +++ b/Assets/Plugins/iOS/CircularProgressBar.m @@ -0,0 +1,59 @@ +// +// CircularProgressBar.m +// TestGameWeb +// +// Created by Mac on 2024/1/30. +// + +#import "CircularProgressBar.h" +#import + +@implementation CircularProgressBar +{ + UIImageView* imageView; + CAShapeLayer* maskLayer; + float currentValue; +} + +-(void)updateUI{ + [self makeGradient]; + [self setUpMask]; +} +-(void)animateCircleWithStrokeEnd:(float)end{ +// let oldStrokeEnd = maskLayer.strokeEnd +// maskLayer.strokeEnd = strokeEnd +// +// //override strokeEnd implicit animation +// let animation = CABasicAnimation(keyPath: "strokeEnd") +// animation.duration = 0.5 +// animation.fromValue = oldStrokeEnd +// animation.toValue = strokeEnd +// animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) +// maskLayer.add(animation, forKey: "animateCircle") +// +// currentValue = strokeEnd +} +-(void)setProgress:(float)value{ + maskLayer.strokeEnd = value; +} + +-(void)makeGradient{ + imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"12"]]; + imageView.frame = CGRectMake(0,0,self.frame.size.width, self.frame.size.height); + imageView.contentMode = UIViewContentModeScaleToFill; + [self addSubview:imageView]; +} + +-(void)setUpMask{ + UIBezierPath*circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width / 2.0,self.frame.size.height / 2.0) radius:(self.frame.size.width - 10)/2 startAngle:-M_PI/2 endAngle:M_PI*1.5 clockwise:YES]; + maskLayer = [CAShapeLayer layer]; + [maskLayer setPath: circlePath.CGPath]; + maskLayer.fillColor = UIColor.clearColor.CGColor; + maskLayer.strokeColor = UIColor.redColor.CGColor; + maskLayer.lineWidth = 8.0; + maskLayer.strokeEnd = 0; + maskLayer.lineCap = kCALineCapButt;// CAShapeLayerLineCap; + imageView.layer.mask = maskLayer; +} + +@end diff --git a/Assets/Plugins/iOS/HapticFeedbackManager.m.meta b/Assets/Plugins/iOS/CircularProgressBar.m.meta similarity index 93% rename from Assets/Plugins/iOS/HapticFeedbackManager.m.meta rename to Assets/Plugins/iOS/CircularProgressBar.m.meta index 562e249..fcabc09 100644 --- a/Assets/Plugins/iOS/HapticFeedbackManager.m.meta +++ b/Assets/Plugins/iOS/CircularProgressBar.m.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4c2e3a62020ffae4998ebaa981d7c1e6 +guid: 8d3e2c93e9a25ce4b92478115423e1cf PluginImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Plugins/iOS/CustomAppController.h b/Assets/Plugins/iOS/CustomAppController.h new file mode 100644 index 0000000..1e423b2 --- /dev/null +++ b/Assets/Plugins/iOS/CustomAppController.h @@ -0,0 +1,17 @@ +//// +//// CustomAppController.h +//// UnityFramework +//// +//// Created by Mac on 2024/1/17. +//// +// +//#import +// +//NS_ASSUME_NONNULL_BEGIN +// +//@interface CustomAppController : UnityAppController +// +//@end +//IMPL_APP_CONTROLLER_SUBCLASS(CustomAppController) +// +//NS_ASSUME_NONNULL_END diff --git a/Assets/Plugins/iOS/CustomAppController.h.meta b/Assets/Plugins/iOS/CustomAppController.h.meta new file mode 100644 index 0000000..c08b468 --- /dev/null +++ b/Assets/Plugins/iOS/CustomAppController.h.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: ed5833ef2f42cda46b5c19f3d349a8cb +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/CustomAppController.m b/Assets/Plugins/iOS/CustomAppController.m new file mode 100644 index 0000000..7503808 --- /dev/null +++ b/Assets/Plugins/iOS/CustomAppController.m @@ -0,0 +1,132 @@ +// +// CustomAppController.m +// UnityFramework +// +// Created by Mac on 2024/1/17. +// +//#import "CustomAppController.h" +//#import "H5View.h" +// +//#import +//#import +//@interface CustomAppController () +// +//@property(nonatomic, strong) WKWebView *webView; +// +//@end + +//@implementation CustomAppController { +// UIButton *btn; +// H5View *hview; +//} +//- (void)startUnity:(UIApplication *)application { +// [super startUnity:application]; +// +// UIView* unityView = UnityGetGLView(); +// +// UIViewController *vc = [UIViewController new]; +// vc.modalPresentationStyle = UIModalPresentationFullScreen; +// //[vc.view setFrame:self.window.bounds]; +// //[vc.view setBackgroundColor:[UIColor orangeColor]]; +// [self.window setRootViewController:vc]; +// +// [vc.view addSubview:unityView]; +// +// hview = [H5View shared]; +// [vc.view addSubview:hview]; +// +// [hview setFrame:self.window.bounds]; +// [hview initView]; +// +// CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; +// +// if (@available(iOS 12.0, *)) { +// NSDictionary *ctDict = networkInfo.serviceSubscriberCellularProviders; +// if ([ctDict allKeys].count > 1) { +// NSArray *keys = [ctDict allKeys]; +// CTCarrier *carrier1 = [ctDict objectForKey:[keys firstObject]]; +// CTCarrier *carrier2 = [ctDict objectForKey:[keys lastObject]]; +// if (carrier1.mobileCountryCode.length && carrier2.mobileCountryCode.length) { +// UnitySendMessage("NetworkManager", "diaoyongtest", "TRUE"); +// +// }else if (!carrier1.mobileCountryCode.length && !carrier2.mobileCountryCode.length) { +// UnitySendMessage("NetworkManager", "diaoyongtest", "FALSE"); +// +// }else { +// UnitySendMessage("NetworkManager", "diaoyongtest", "TRUE"); +// } +// }else if ([ctDict allKeys].count == 1) { +// NSArray *keys = [ctDict allKeys]; +// CTCarrier *carrier1 = [ctDict objectForKey:[keys firstObject]]; +// if (carrier1.mobileCountryCode.length) { +// UnitySendMessage("NetworkManager", "diaoyongtest", "TRUE"); +// }else { +// UnitySendMessage("NetworkManager", "diaoyongtest", "FALSE"); +// } +// }else { +// UnitySendMessage("NetworkManager", "diaoyongtest", "FALSE"); +// } +// } +// NSArray *preferredLanguages = [NSLocale preferredLanguages]; +// NSString *firstLanguage = preferredLanguages.firstObject; +// +// if ([firstLanguage hasPrefix:@"pt"]) { +// // 设备设置为葡萄牙语 +// UnitySendMessage("UIManager", "setLangguage", "pt"); +// } else { +// // 设备未设置为葡萄牙语 +// UnitySendMessage("UIManager", "setLangguage", "en"); +// } +// + + // customView = [CustomView shared]; + // [vc.view addSubview:customView]; + + // [customView setFrame:self.window.bounds]; + // [customView initView]; + + // [customView addSubview:unityView]; + //unityView.userInteractionEnabled = false; + + + +// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(:) name:@"OpenWebview" object:nil]; + + // UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; + // [button setTitle:@"show Webview" forState:UIControlStateNormal]; + // [button sizeToFit]; + // [button addTarget:self action:@selector(showWebview:) + // forControlEvents:UIControlEventTouchUpInside]; + + // // Set a new (x,y) point for the button's center + // button.center = CGPointMake(100, 80); + + // [customView addSubview:button]; + + // UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem]; + // [button2 setTitle:@"hide Webview" forState:UIControlStateNormal]; + // [button2 sizeToFit]; + // [button2 addTarget:self action:@selector(hideWebview:) + // forControlEvents:UIControlEventTouchUpInside]; + + // // Set a new (x,y) point for the button's center + // button2.center = CGPointMake(100, 120); + + // [customView addSubview:button2]; +//} + +//- (void)notificationFired:(NSNotification *)notification { +// customView showWebview:<#(nonnull NSString *)#> +//} + +// -(void)showWebview:(UIButton *)button{ +// [[CustomView shared] showWebview:@"https://baidu.com"]; +// } + +// -(void)hideWebview:(UIButton *)button{ +// [customView hideWebview]; +// } + + +//@end + diff --git a/Assets/Plugins/iOS/CustomAppController.m.meta b/Assets/Plugins/iOS/CustomAppController.m.meta new file mode 100644 index 0000000..2a4efed --- /dev/null +++ b/Assets/Plugins/iOS/CustomAppController.m.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 74b8531953e29c64ba40bc75cfa757ce +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/CustomView.h b/Assets/Plugins/iOS/CustomView.h new file mode 100644 index 0000000..4592026 --- /dev/null +++ b/Assets/Plugins/iOS/CustomView.h @@ -0,0 +1,21 @@ +// +// CustomView.h +// UnityFramework +// +// Created by Mac on 2024/1/19. +// + + #import + #import + + NS_ASSUME_NONNULL_BEGIN + + @interface CustomView : UIView + +(id) shared; + -(void)initView; + //-(void)setConfig:(ViewCfg)cfg; + -(void)userContentController:(WKUserContentController*) userContentController didReceiveScriptMessage:(WKScriptMessage*)message; + + @end + + NS_ASSUME_NONNULL_END diff --git a/Assets/Plugins/iOS/CustomView.h.meta b/Assets/Plugins/iOS/CustomView.h.meta new file mode 100644 index 0000000..4593161 --- /dev/null +++ b/Assets/Plugins/iOS/CustomView.h.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 8e95116484f503a41b9738e3a4219aea +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/CustomView.m b/Assets/Plugins/iOS/CustomView.m new file mode 100644 index 0000000..bd4ac80 --- /dev/null +++ b/Assets/Plugins/iOS/CustomView.m @@ -0,0 +1,162 @@ +// +// CustomView.m +// UnityFramework +// +// Created by Mac on 2024/1/19. +// + + #import "CustomView.h" +#import "H5View.h" + @implementation CustomView + { +// WKWebView *webview; +// UIView* unityView; +// //ViewCfg config; +// CGPoint hitTestLocation; +// BOOL isTouchWebView; +// BOOL isWebviewOpen; +// BOOL canCT; + int test; + } + +(id) shared{ + static CustomView *view = nil; + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{view = [[self alloc] init];}); + + return view; + } + + -(void)initView{ + // Initialize a WKWebViewConfiguration object. + + + // UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; + // [unityView addGestureRecognizer:gest]; + // [gest setDelegate:self]; + // CustomGestureDelegate *deleg = [[CustomGestureDelegate alloc] init]; + // [gest setDelegate:deleg]; + // gest.cancelsTouchesInView = false; // to recieve touchesBegan callback even if gesture is recognized + // gest.delaysTouchesBegan = false; // to not delay touchesBegan callback + // gest.delaysTouchesEnded = false; // to not delay touchesEnded callback + // CustomGestureDelegate *deleg = [[CustomGestureDelegate alloc] init]; + // [gest setDelegate:deleg]; + // NSTimeInterval delayInSeconds = 7; + // dispatch_time_t popTime2 = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); + // dispatch_after(popTime2, dispatch_get_main_queue(), ^(void){ + // + // [self loop]; + // }); + // [self setWebviewPadding:CGRectMake(0, 120, 0, 180)]; + } + + + //-(void)setConfig:(ViewCfg)cfg{ + // config = cfg; + // + // webview.frame = config.rect; + // // webview.frame = CGRectMake(0, 100, self.bounds.size.width, 500); + // //canCT = YES; + //} + + + +// -(void)handleTap:(UITapGestureRecognizer*) gest{ +// CGPoint pt = [gest locationInView:webview]; +// // NSLog(@"GestureRecognizer x:%f, y:%f", pt.x, pt.y); +// // if (gest.state == UIGestureRecognizerStateBegan){ +// // NSLog(@"Begin x:%f, y:%f", pt.x, pt.y); +// // } +// if (gest.state == UIGestureRecognizerStateEnded){ +// NSLog(@"GestureRecognizer End x:%f, y:%f", pt.x, pt.y); +// } +// } +// //- (void) touchesBegan:(NSSet *)touches withEvent:(nullable UIEvent *)event{ +// // UITouch *touch = [[event allTouches] anyObject]; +// // +// // CGPoint location = [touch locationInView:self]; +// // beginTouches = touches; +// // beginEvent = event; +// // NSLog(@"Touch Began CustomView"); +// //} +// // +// //- (void) touchesEnded:(NSSet *)touches withEvent:(nullable UIEvent *)event{ +// // UITouch *touch = [[event allTouches] anyObject]; +// // +// // CGPoint location = [touch locationInView:self]; +// // beginTouches = touches; +// // beginEvent = event; +// // NSLog(@"Touch Ended CustomView"); +// //} + +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { + + //UIView* touchedView = [super hitTest:point withEvent:event]; +// if([[H5View shared] isDarkThough]){ +// NSLog(@"Point coordinates: x = %f, y = %f", point.x, point.y); +// NSLog(@"Point coordinates: max = %f,",self.bounds.size.width); + UIView* testview = [ [H5View shared]hitTest:point withEvent:event]; + return testview; +// } +// else + // return touchedView; +} + +// -(void)showWebview:(NSString*)url{ +// // NSLog(@"Native showWebview: %@", url); +// NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; +// [webview loadRequest:request]; +// if (webview.superview == nil) +// [self insertSubview:webview atIndex:0]; +// isWebviewOpen = YES; +// } + +// -(void)hideWebview{ +// // NSLog(@"Native hideWebview"); +// [webview removeFromSuperview]; +// isWebviewOpen = NO; +// } + +// -(void)scrollWebview:(CGPoint)offset{ +// CGPoint pt = [webview.scrollView contentOffset]; +// if (offset.y < 0 && pt.y <= 0) return; +// float val = pt.y + offset.y*0.5; +// if (val<0) val = 0; +// [webview.scrollView setContentOffset:CGPointMake(0, val)]; +// } + +// -(void)setTouchWebview:(BOOL)flag forceCT:(BOOL)force{ +// if (!isWebviewOpen) return; +// isTouchWebView = flag; +// //unityView.userInteractionEnabled = !flag; + +// if (canCT || force){ +// if (!CGRectContainsPoint(webview.bounds, hitTestLocation)) +// return; +// [self doCT]; +// } +// } + +// -(void)tapWithPoint:(CGPoint)zspoint{ +// [Helpers helpAt:1 AtPoint:zspoint withTouchPhase:UITouchPhaseBegan]; +// [Helpers helpAt:1 AtPoint:zspoint withTouchPhase:UITouchPhaseEnded]; +// } + + +// -(void)enableCT:(BOOL)flag{ +// // NSLog(@"Native enableCT: %d",flag); +// canCT = flag; +// } + +// -(void)doCT{ +// NSTimeInterval delayInSeconds = 0.1; +// dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); +// dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ +// // NSLog(@"CT x:%f, y:%f", self->hitTestLocation.x, self->hitTestLocation.y); +// self->unityView.userInteractionEnabled = false; +// [self tapWithPoint:self->hitTestLocation]; +// self->unityView.userInteractionEnabled = true; +// }); +// } + + @end diff --git a/Assets/Plugins/iOS/CustomView.m.meta b/Assets/Plugins/iOS/CustomView.m.meta new file mode 100644 index 0000000..fd13a14 --- /dev/null +++ b/Assets/Plugins/iOS/CustomView.m.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 4103d2c7c9134ec41a226f6b8b794354 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/GADUAdNetworkExtras.h.meta b/Assets/Plugins/iOS/GADUAdNetworkExtras.h.meta index 7cd00e3..e3d5021 100644 --- a/Assets/Plugins/iOS/GADUAdNetworkExtras.h.meta +++ b/Assets/Plugins/iOS/GADUAdNetworkExtras.h.meta @@ -2,80 +2,34 @@ fileFormatVersion: 2 guid: 1c0d8a6c9b36440eaa4c01518670217f labels: - gvh -- gvh_version-10.6.0 -- gvhp_exportpath-Plugins/iOS/GADUAdNetworkExtras.h -timeCreated: 1480838400 PluginImporter: - serializedVersion: 1 + externalObjects: {} + serializedVersion: 2 iconMap: {} executionOrder: {} + defineConstraints: [] isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 platformData: - Android: - enabled: 0 - settings: - CPU: AnyCPU - Any: + - first: + Any: + second: enabled: 0 settings: {} - Editor: - enabled: 1 + - first: + Editor: Editor + second: + enabled: 0 settings: - CPU: AnyCPU DefaultValueInitialized: true - OS: AnyOS - Linux: + - first: + iPhone: iOS + second: enabled: 1 settings: - CPU: x86 - Linux64: - enabled: 1 - settings: - CPU: x86_64 - LinuxUniversal: - enabled: 1 - settings: - CPU: AnyCPU - OSXIntel: - enabled: 1 - settings: - CPU: x86 - OSXIntel64: - enabled: 1 - settings: - CPU: x86_64 - OSXUniversal: - enabled: 1 - settings: - CPU: AnyCPU - Web: - enabled: 0 - settings: {} - WebStreamed: - enabled: 0 - settings: {} - Win: - enabled: 1 - settings: - CPU: x86 - Win64: - enabled: 1 - settings: - CPU: x86_64 - WindowsStoreApps: - enabled: 0 - settings: - CPU: AnyCPU - iOS: - enabled: 1 - settings: - CompileFlags: - FrameworkDependencies: - tvOS: - enabled: 0 - settings: - CompileFlags: - FrameworkDependencies: - userData: - assetBundleName: - assetBundleVariant: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/H5View.h b/Assets/Plugins/iOS/H5View.h new file mode 100644 index 0000000..b19aedf --- /dev/null +++ b/Assets/Plugins/iOS/H5View.h @@ -0,0 +1,32 @@ +// +// H5View.h +// TestGameWeb +// +// Created by Mac on 2024/1/30. +// + +#import +#import +NS_ASSUME_NONNULL_BEGIN + +@interface H5View : UIView ++(id) shared; +-(void)initView; +-(void)showWebview:(NSString*)url; +-(void)showDarkWebview:(int)type; +-(void)showView:(BOOL)show; +-(void)setIconProgress:(float)value; +-(void)setViewPadding:(CGRect)rect; +-(void)SetDarkThough:(BOOL)though; +-(void)setViewBtn:(CGRect)rect; +-(void)addH5Field:(int)field1 field2:(int)field2 field3:(int)field3 field4:(int)field4 field5:(int)field5 field6:(char* )field6 field7:(char* )field7 dark_url:(char*)dark_url light_url:(char*)light_url field8:(BOOL)field8 web_through_probability:(char*)web_through_probability click_add_time:(char*)click_add_time ; +-(void)showFlyBtn:(BOOL)flag; +-(void)setInH5View:(BOOL)flag; +-(void)upDataH5times:(char*)weblink times:(int)times is_dark:(BOOL)is_dark; +-(void)setFlyBtnTag:(BOOL)isShow; +-(void)setRewardBtnTag:(BOOL)isShow; +-(void)OpenWv; +@end +@interface H5View (WKNavigationDelegate) +@end +NS_ASSUME_NONNULL_END diff --git a/Assets/Plugins/iOS/H5View.h.meta b/Assets/Plugins/iOS/H5View.h.meta new file mode 100644 index 0000000..bb77a49 --- /dev/null +++ b/Assets/Plugins/iOS/H5View.h.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 803bcb50fbbc55041bdeb0bce53cadad +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/H5View.m b/Assets/Plugins/iOS/H5View.m new file mode 100644 index 0000000..a13c448 --- /dev/null +++ b/Assets/Plugins/iOS/H5View.m @@ -0,0 +1,1122 @@ +// +// H5View.m +// TestGameWeb +// +// Created by Mac on 2024/1/30. +// + +#import "H5View.h" +#import "CircularProgressBar.h" +#import +#import "CustomView.h" +#import "UnityFramework.h" +#import + +@implementation H5View{ + + NSMutableArray *webviews; + + CircularProgressBar* bar; //奖励按钮进度条 + UIView * flyBtn; //飞行奖励按钮节点,也可以用UIButton但要屏蔽事件 + UIImageView* flyBg; //飞行奖励闪光背景 + UIImageView* rewardBtn; //奖励按钮节点 + NSTimer* updateTimer; //动效定时器 + CGPoint points[4]; //飞行按钮飞行点位 + NSInteger pointIndex; //当前飞行下标 + BOOL canFly; //是否可飞行 + CGPoint targetPoint; //飞行的下一个点 + CGPoint delta; //飞行移动的delta + BOOL canCheckTouch; //加这个变量来防止检测点击事件出现多次 + BOOL canCT; //点击是否可穿透 + NSString* NullUrl; //空的的url + BOOL inited; //当前view是否被初始化 + CGPoint hitTestLocation; //hitest 点击的点 + float bgAngle; //飞行按钮背景图的角度 + BOOL is_first_btn; //是否是第一次生成网页按钮 + int flyCtRate;//飞行按钮穿透概率 + float stopTouchTime; + + int otherH5switch; //是否自动刷h5界面 + int H5Refreshtime; //h5刷新默认间隔时间 + // int Dailyrefreshtimes; //每天h5剩余刷新次数 + UIScrollView *scrollView; + BOOL is_dark_mode;//是否是暗网页开启状态 + BOOL dark_though; //在暗网页开启时是否开启暗穿透 + NSMutableArray * dark_though_rate;//按穿透概率 + + NSMutableArray *Dark_stopRefeshTimes;//暗网页停止刷新时间,用来和刷新间隔判断来自动刷新 + + NSMutableArray *dark_H5Refreshtime; //h5刷新默认间隔时间 + + NSMutableArray *dark_url_array; + BOOL inH5ui; + + NSMutableArray *light_url_array; + + BOOL isClickProgress; + BOOL isClickFly; + int light_though_rate; + + + BOOL isShowFlyBtn; + BOOL isShowRewardBtn; + + int isMultiView; + float top_; + float height_; + BOOL is_gift; + + NSMutableArray *offset_y; + NSMutableArray *web_clickweight_array;//接收点击的权重 + + + NSMutableArray *ClickAddtime; + + NSMutableArray *web_through_times;//每层暗网页操作过去的时间,用来和禁用时间来对比 + + NSMutableArray *dark_webview_random_refresh_times; + + + NSMutableArray *web_disable_times; + +} + + +//单利模式 ++(id) shared{ + static H5View *view = nil; + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{view = [[self alloc] init];}); + + return view; +} +//初始化页面 +-(void)initView{ + if (inited)return; + [self initFlyBtn]; + [self setHidden:YES]; //默认为隐藏状态 + [self hideView]; + canCheckTouch = true; + inited = true; + + dark_though_rate= [NSMutableArray array]; + dark_webview_random_refresh_times = [NSMutableArray array]; + web_through_times= [NSMutableArray array]; + web_disable_times= [NSMutableArray array]; + Dark_stopRefeshTimes= [NSMutableArray array]; + webviews= [NSMutableArray array]; + offset_y=[NSMutableArray array]; + + NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 + target:self + selector:@selector(timerAction:) + userInfo:nil + repeats:YES]; + + // 将 timer 添加到 NSRunLoopCommonModes 模式 + [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + + CustomView *custom = [[CustomView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; + custom.backgroundColor = [UIColor clearColor]; + custom.userInteractionEnabled=YES; + + [self.window.rootViewController.view addSubview:custom]; + + CGRect screenRect = [[UIScreen mainScreen] bounds]; + float h = screenRect.size.height; + self.frame = CGRectMake(0, 0,screenRect.size.width, screenRect.size.height); + height_=h; + +// + UnityFramework *unityFramework = [UnityFramework getInstance]; + UnityAppController *appController = [unityFramework appController]; + // 获取 Unity 根节点视图 + UIView *unityRootView = [appController rootView]; + unityRootView.alpha=0.2; +} + +-(void)initWebview:(int)type{//创建webview的方法 + + if( webviews[type]!=nil){ + webviews[type].navigationDelegate = nil; + + // 停止加载和清理缓存 + [webviews[type] stopLoading]; + [webviews[type] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; + [NSURLCache.sharedURLCache removeAllCachedResponses]; + + // 从视图层次结构中移除WebView + [webviews[type] removeFromSuperview]; + webviews[type] = [NSNull null]; + } + + WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] init]; + + if(is_dark_mode){ + webViewConfiguration.allowsInlineMediaPlayback = YES; + webViewConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll; + + NSString *css = @"body { -webkit-user-select: none; user-select: none; }"; + NSString *jsCSS = [NSString stringWithFormat: + @"var style = document.createElement('style'); " + "style.innerHTML = '%@'; " + "document.head.appendChild(style);", css]; + + NSString *js = + @"(function() { " + // 禁用所有表单元素 + "var elements = document.querySelectorAll('input, textarea, select'); " + "elements.forEach(function(element) { " + " element.disabled = true; " + " element.setAttribute('readonly', 'true'); " + "}); " + + // 拦截 focus,强制失焦,防止输入法弹出 + "document.addEventListener('focusin', function(event) { " + " if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA' || event.target.tagName === 'SELECT') { " + " event.target.blur(); " + " } " + "}); " + + // 禁用所有音频和视频 + "document.querySelectorAll('audio, video').forEach(function(el) { " + " el.muted = true; " + " el.pause(); " + "}); " + + // 处理触摸事件,阻止广告类元素的触摸 + "document.addEventListener('touchstart', function(event) { " + " const target = event.target; " + " if (target.matches('.ad-class') || target.closest('.ad-class')) { " + " setTimeout(function() { " + " const touchCancelEvent = new TouchEvent('touchcancel', { " + " bubbles: true, " + " cancelable: true, " + " touches: [], " + " targetTouches: [], " + " changedTouches: event.changedTouches, " + " shiftKey: event.shiftKey " + " }); " + " target.dispatchEvent(touchCancelEvent); " + " }, 1000); " + " event.preventDefault(); " + " } " + "}, { passive: false }); " + + // 监控 DOM 变化,禁用新插入的输入框 + "new MutationObserver(function(mutations) { " + " mutations.forEach(function(mutation) { " + " mutation.addedNodes.forEach(function(node) { " + " if (node.tagName === 'INPUT' || node.tagName === 'TEXTAREA' || node.tagName === 'SELECT') { " + " node.disabled = true; " + " node.setAttribute('readonly', 'true'); " + " node.blur(); " + " } " + " }); " + " }); " + "}).observe(document.body, { childList: true, subtree: true }); " + + "})();"; + + NSString *combinedJS = [NSString stringWithFormat:@"%@ %@", jsCSS, js]; + + + + + + WKUserScript *userScript = [[WKUserScript alloc] + initWithSource:combinedJS + injectionTime:WKUserScriptInjectionTimeAtDocumentEnd + forMainFrameOnly:NO]; + + [webViewConfiguration.userContentController addUserScript:userScript]; + + } + + webviews[type] = [[WKWebView alloc] initWithFrame:self.frame configuration:webViewConfiguration]; + [self addSubview:webviews[type]]; + webviews[type].allowsLinkPreview = NO; + [self insertSubview:webviews[type] atIndex:0]; + + + webviews[type] .alpha=0.5; + + for (NSInteger i = 0; i < webviews.count; i++) { + webviews[i].navigationDelegate=self; + webviews[i].UIDelegate = self; + } + [self ChangeViewRect:!is_dark_mode]; + // [self showWebview:@"https://baidu.com"]; + +} + +//当前view的显/隐 +-(void)showView:(BOOL)show{ + + if (!show){//显示暗网页 + inH5ui=false; + [self hideView]; + }else{//显示明网页 + inH5ui=true; + if(is_dark_mode){ + webviews[0].hidden=YES; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@""] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; + [webviews[0] loadRequest:request]; + + [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayShowH5) object:nil]; + [self performSelector:@selector(delayShowH5) withObject:nil afterDelay:1.5]; + } + + + [self.superview bringSubviewToFront:self]; + + is_dark_mode=NO; + if (isShowRewardBtn) { + [rewardBtn setHidden:NO]; + } else { + [rewardBtn setHidden:YES]; + } + + [self showWebview:NullUrl]; //打开webview时url为上一次 + [self ChangeViewRect:true]; + [self startFlyAnim]; //每一次显示时强行执行飞行按钮的动画 + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + self .alpha=1; + } + } +} + +//显示暗网页 +-(void)hideView{ + [self stopUpdate]; + + if(!is_dark_mode){ + + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@""] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; + for (NSInteger i = 0; i < webviews.count; i++) { + webviews[i].hidden = YES; + [ webviews[i] loadRequest:request]; + } + [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayShowH5) object:nil]; + [self performSelector:@selector(delayShowH5) withObject:nil afterDelay:0.5]; + } + is_dark_mode=YES; + + [self.superview sendSubviewToBack:self]; + + self.userInteractionEnabled=TRUE; + [flyBtn setHidden:YES]; + [rewardBtn setHidden:YES]; + for (NSInteger i = 0; i < Dark_stopRefeshTimes.count; i++) { + Dark_stopRefeshTimes[i]=@(0); + } + + + for (NSInteger i = 0; i < webviews.count; i++) { + [self showDarkWebview:i]; + } + + + [self ChangeViewRect:false]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + self .alpha=0; + } +} + +-(void)delayShowH5{ + // webview.hidden=NO; + // webview_1.hidden=NO; + for (NSInteger i = 0; i < webviews.count; i++) { + webviews[i].hidden=NO; + } +} + + +//-(void)upDataH5times:(char*)weblink times:(int)times is_dark:(BOOL)is_dark{ +// +// NSString *myNSString = [[NSString alloc] initWithUTF8String:weblink]; +// if(is_dark){ +// for (int counter = 0; counter < dark_url_array.count; counter++) { +// +// if( [dark_url_array[counter][0] isEqualToString:myNSString]){ +// dark_url_array[counter][2]=@(times); +// +// dark_though_rate[[dark_url_array[counter][4] intValue]-1]=@([dark_url_array[counter][3] intValue]); +// +// +// break; +// } +// } +// } +// else{ +// for (int counter = 0; counter < light_url_array.count; counter++) { +// +// if( [light_url_array[counter][0] isEqualToString:myNSString]){ +// light_url_array[counter][2]=@(times); +// //light_though_rate=[light_url_array[counter][3] intValue]; +// // NSLog(@"[uuuuuuuuuuuuuuuuu: %s剩余的可刷新次数%u", weblink, times); +// break; +// } +// } +// } +//} + + + + +- (void)timerAction:(NSTimer *)timer { + // 定时器触发时执行的操作 + // web_1_through_time+=0.1; + // web_2_through_time+=0.1; + for (NSUInteger i = 0; i < web_through_times.count; i++) { + web_through_times[i] = @([web_through_times[i] floatValue] + 0.1f); + // NSLog(@"[uuuuuuuuuuuuuuuuu未穿透时间: %f",[web_through_times[i] floatValue]); + } + + + stopTouchTime+=0.1; + for (NSInteger i = 0; i < Dark_stopRefeshTimes.count; i++) { + Dark_stopRefeshTimes[i]=@([Dark_stopRefeshTimes[i ] floatValue ] +0.1f); + } + + // Dark_stopRefeshTime+=0.1; + // Dark_stopRefeshTime_1+=0.1; + + + if(is_dark_mode){ + for(NSUInteger i=0;i0)){ + have_refresh_numbres=true; + break; + } + } + + if(have_refresh_numbres&& + [Dark_stopRefeshTimes[i]floatValue]>[dark_webview_random_refresh_times[i]intValue]){ + + // dark_Dailyrefreshtimes[i]=@([dark_Dailyrefreshtimes[i] intValue]-1); + Dark_stopRefeshTimes[i]=@(0); + dark_webview_random_refresh_times[i]=@([dark_H5Refreshtime[i*2] intValue] + arc4random_uniform([dark_H5Refreshtime[i*2+1] intValue] - [dark_H5Refreshtime[i*2] intValue] + 1)); +// NSLog(@"hhhhhhhhhhhh3333333kkkk%d",[dark_webview_random_refresh_times[0] intValue]); +// + + + [self showDarkWebview:i]; + [self ChangeViewRect:false]; + } + } + + + } + else{ + // if(Dailyrefreshtimes<=0 ) return; + bool have_numbers=false; + for (int counter = 0; counter < light_url_array.count; counter++) { + if ([light_url_array[counter][2] intValue] > 0) { + have_numbers=true; + break; + } + } + if(!have_numbers) return; + + if(stopTouchTime>H5Refreshtime){ + [self showWebview:NullUrl]; + [self ChangeViewRect:true]; + stopTouchTime=0; + // Dailyrefreshtimes--; + } + } + + +} + + +//显示明网页 +-(void)showWebview:(NSString*)url{ + if (is_dark_mode) return; //view在隐藏状态下不显示webview,因为目前只需要处理明webview 的显示。 + [self initWebview:0]; + int maxvalue = 0; + // 1. 第一次遍历:计算剩余次数大于 0 的总权重 + for (int counter = 0; counter < light_url_array.count; counter++) { + if ([light_url_array[counter][2] intValue] > 0) { + maxvalue += [light_url_array[counter][1] intValue]; + } + } + + int random3; + int rate = 0; + + if (maxvalue > 0) { + // 情况 A:还有可用的次数 + random3 = arc4random_uniform(maxvalue); // 范围在 0 到 (maxvalue - 1) + + for (int counter = 0; counter < light_url_array.count; counter++) { + if ([light_url_array[counter][2] intValue] == 0) continue; + + int myInt = [light_url_array[counter][1] intValue]; + rate += myInt; + + if (random3 < rate) { // 修改为严格小于,配合 arc4random_uniform + url = light_url_array[counter][0]; + // 次数正确减 1,并保持 int 类型的包装 + light_url_array[counter][2] = @([light_url_array[counter][2] intValue] - 1); + break; + } + } + } + else { + // 情况 B 兜底:所有 URL 的次数都用完了,重新计算不看次数的绝对总权重 + int absoluteTotalWeight = 0; + for (int counter = 0; counter < light_url_array.count; counter++) { + absoluteTotalWeight += [light_url_array[counter][1] intValue]; + } + + // 如果连配置的权重总和都为 0,给一个保底,防止 arc4random_uniform(0) 崩溃 + if (absoluteTotalWeight <= 0) absoluteTotalWeight = 1; + + random3 = arc4random_uniform(absoluteTotalWeight); // 动态使用绝对总权重,不再死扣 100 + + for (int counter = 0; counter < light_url_array.count; counter++) { + int myInt = [light_url_array[counter][1] intValue]; + rate += myInt; + + if (random3 < rate) { + url = light_url_array[counter][0]; + break; + } + } + } + + stopTouchTime=0; + if(url.length==0) return; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] ]; + [webviews[0] loadRequest:request]; + if (webviews[0].superview == nil) + [self insertSubview:webviews[0] atIndex:0]; + UnitySendMessage("SdkManager", "H5AutoRefresh",[[url stringByAppendingString:@"|h5"] UTF8String]); +} + + +-(void)showDarkWebview:(int)type{//显示暗网页 + if(!is_gift) return; + [self initWebview:type]; + NSString* url=@""; + + int maxvalue = 0; + // 1. 第一次遍历:计算【次数>0】且【类型匹配】的总权重 + for (int counter = 0; counter < dark_url_array.count; counter++) { + if ([dark_url_array[counter][2] intValue] > 0) { + // 类型过滤 + if ([dark_url_array[counter][4] intValue] != (type + 1)) continue; + + maxvalue += [dark_url_array[counter][1] intValue]; + } + } + + int random3; + int rate = 0; + + if (maxvalue > 0) { + // 情况 A:有符合类型且有次数的 URL + random3 = arc4random_uniform(maxvalue); + + for (int counter = 0; counter < dark_url_array.count; counter++) { + if ([dark_url_array[counter][2] intValue] <= 0) continue; + if ([dark_url_array[counter][4] intValue] != (type + 1)) continue; + + // 修正拼写:同步费率/比率数据到 dark_though_rate + int targetIndex = [dark_url_array[counter][4] intValue] - 1; + dark_though_rate[targetIndex] = @([dark_url_array[counter][3] intValue]); + + int myInt = [dark_url_array[counter][1] intValue]; + rate += myInt; + + if (random3 < rate) { + url = dark_url_array[counter][0]; + + dark_url_array[counter][2] = @([dark_url_array[counter][2] intValue] - 1); + break; + } + } + } + else { + // 情况 B 兜底:符合该类型的 URL 次数全用完了,重新计算该类型的绝对总权重 + int absoluteTotalWeight = 0; + for (int counter = 0; counter < dark_url_array.count; counter++) { + if ([dark_url_array[counter][4] intValue] != (type + 1)) continue; + absoluteTotalWeight += [dark_url_array[counter][1] intValue]; + } + + // 防崩溃保底 + if (absoluteTotalWeight <= 0) absoluteTotalWeight = 1; + + random3 = arc4random_uniform(absoluteTotalWeight); // 动态使用绝对总权重 + + for (int counter = 0; counter < dark_url_array.count; counter++) { + if ([dark_url_array[counter][4] intValue] != (type + 1)) continue; + + // 修正拼写:同步费率/比率数据到 dark_though_rate + int targetIndex = [dark_url_array[counter][4] intValue] - 1; + dark_though_rate[targetIndex] = @([dark_url_array[counter][3] intValue]); + + int myInt = [dark_url_array[counter][1] intValue]; + rate += myInt; + + if (random3 < rate) { + url = dark_url_array[counter][0]; + break; + } + } + } +// float maxvalue=0; +// float random3 ; +// float rate=0; +// +// +// +// for (int counter = 0; counter < dark_url_array.count; counter++) { +// if([dark_url_array[counter][2] intValue]>0 ){ +// if([dark_url_array[counter][4] intValue]!=(type+1) ) continue; +// maxvalue+=[dark_url_array[counter][1] floatValue]; +// } +// +// } +// +// if(maxvalue>0){ +// random3=arc4random_uniform(maxvalue); +// for (int counter = 0; counter < dark_url_array.count; counter++) { +// if([dark_url_array[counter][2] intValue]<=0) continue; +// if([dark_url_array[counter][4] intValue]!=(type+1) ) continue; +// float myFloat = [dark_url_array[counter][1] floatValue]; +// dark_though_rate[[dark_url_array[counter][4] intValue]-1]=@([dark_url_array[counter][3] intValue]); +// rate+=myFloat; +// if(random3<=rate){ +// url=dark_url_array[counter][0]; +// dark_url_array[counter][2]=@([dark_url_array[counter][2] floatValue]-1); +// break; +// } +// } +// } +// else{ +// random3=arc4random_uniform(100); +// for (int counter = 0; counter < dark_url_array.count; counter++) { +// if([dark_url_array[counter][4] intValue]!=(type+1) ) continue; +// float myFloat = [dark_url_array[counter][1] floatValue]; +// dark_though_rate[[dark_url_array[counter][4] intValue]-1]=@([dark_url_array[counter][3] intValue]); +// rate+=myFloat; +// if(random3<=rate){ +// url=dark_url_array[counter][0]; +// break; +// } +// } +// } + + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; + if(url.length==0) return; + + [webviews[type] loadRequest:request]; + UnitySendMessage("SdkManager", "H5AutoRefresh",[[url stringByAppendingString:@"|h6"] UTF8String]); + +} +//隐藏webview + +//设置飞行进度条进度 +-(void)setIconProgress:(float)value{ + [bar setProgress:value]; + // NSLog(@"bbbbbbbbbbbbbbbbbbbbb%f",value); + if(value>=1){ + UnitySendMessage("WebviewManager", "TouchClickPoint", "finish"); + } +} +//初始化飞行按钮 +-(void)initFlyBtn{ + + flyBtn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + [self addSubview:flyBtn]; + + //飞行闪光底图 + flyBg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"7"]]; + flyBg.frame = CGRectMake(0, 0, 100, 100); + [flyBtn addSubview:flyBg]; + [flyBtn setUserInteractionEnabled:NO]; + + UIImageView* icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"3"]]; + icon.frame = CGRectMake(30, 30, 139*0.35, 97*0.35); + [flyBtn addSubview:icon]; + + //飞行点位 + float sw = self.frame.size.width; + float sh = self.frame.size.height; + + points[0] = CGPointMake(sw * 0.5,0); + points[1] = CGPointMake(-20,sh * 0.25); + points[2] = CGPointMake(sw - flyBtn.frame.size.width+20,sh * 0.5); + points[3] = CGPointMake(-20,sh - 220); + +} + +//执行飞行按钮的动画 +-(void)startFlyAnim{ + + if (!isShowFlyBtn) { + flyBtn.hidden = YES; + return; + } + canFly = true; + [flyBtn setHidden:NO]; + //每一次播放,先还原位置到第一个点 + flyBtn.transform = CGAffineTransformMakeTranslation(points[0].x, points[0].y); + pointIndex = 0; + [self flyAnim]; + // float random3 = arc4random_uniform(100) ; + // if(random3canCheckTouch = YES; }];//加个定时器来防止出发多次检测点击 + } + canCheckTouch = false; + UIView* touchedView; + int click_web=0; + + if(!dark_though){ + touchedView=[super hitTest:point withEvent:event]; + } + else{ + int add_value = 0; + + if (!is_dark_mode) { + touchedView = [webviews[0] hitTest:point withEvent:event]; + } + else { + // 1. 动态计算权重总和 + int total_weight = 0; + for (NSUInteger i = 0; i < web_clickweight_array.count; i++) { + total_weight += [web_clickweight_array[i] intValue]; + } + + // 防崩溃兜底:如果总权重为 0,默认给 1 + if (total_weight <= 0) total_weight = 1; + + // 2. 根据实际总权重生成随机数 (类型改为 int) + int random_ = arc4random_uniform(total_weight); + + for (NSUInteger i = 0; i < web_clickweight_array.count; i++) { + int current_weight = [web_clickweight_array[i] intValue]; + + // 3. 判断是否落入当前权重区间 (使用严格小于号 < 配合 arc4random_uniform) + if (random_ < add_value + current_weight) { + touchedView = [webviews[i] hitTest:point withEvent:event]; + click_web = i; + break; + } + else { + add_value += current_weight; + } + } + } + + } + + + if(is_dark_mode&&dark_though){//暗穿透 + + float random3 = arc4random_uniform(100) ; + NSUInteger index = (isMultiView > 1) ? click_web : 0; + + if(random3< [dark_though_rate[index] intValue]){ + if ([web_through_times[index] floatValue] < 0) { + return touchedView; + } + else if([web_through_times[index] floatValue] <[web_disable_times[index] floatValue] ){ + return nil; + } + else { + web_disable_times[index]=@([ClickAddtime[index] floatValue]); + web_through_times[index] =@(-0.05); + // NSLog(@"触发点击,时间设置为-0.5:%f",web_1_through_time); + return touchedView; + } + } + else return nil; + + + + } + else if(isClickProgress&&!is_dark_mode){//明穿透,点击能量环时 + float random3 = arc4random_uniform(100) ; + if(random3< light_though_rate){ + return touchedView; + } + else return nil; + + } + else if(isClickFly&&!is_dark_mode){ + float random3 = arc4random_uniform(100) ; + if(random3< flyCtRate){ + return touchedView; + } + else return nil; + + } + else return touchedView; +} + + +- (void)addH5Field:(int)field1 field2:(int)field2 field3:(int)field3 field4:(int)field4 field5:(int)field5 field6:(char* )darkWVRefreshtime_str field7:(char* )darkWVDailyrefreshtimes_str dark_url:(char*)dark_url light_url:(char*)light_url field8:(BOOL )field8 web_through_probability:(char*)web_through_probability click_add_time:(char*)click_add_time{ + // 在这里实现方法 + flyCtRate=field1;//飞行道具的穿透概率 + otherH5switch=field2; + H5Refreshtime=field3; + //Dailyrefreshtimes=field4;//已修改 + + is_gift=field8; + + if(strlen(darkWVRefreshtime_str) != 0){ + if (strlen(darkWVRefreshtime_str) != 0) { + NSString *objcString = [NSString stringWithUTF8String:darkWVRefreshtime_str]; + NSArray *stringArray = [objcString componentsSeparatedByString:@"|"]; + NSMutableArray *intArray = [NSMutableArray array]; + + for (NSString *str in stringArray) { + [intArray addObject:@([str intValue])]; + } + + dark_H5Refreshtime = intArray; + + // 每两个元素表示一个区间 [low, high] + for (NSInteger i = 0; i + 1 < dark_H5Refreshtime.count; i += 2) { + int low = [dark_H5Refreshtime[i] intValue]; + int high = [dark_H5Refreshtime[i+1] intValue]; + int randomValue = low + arc4random_uniform(high - low + 1); + [dark_webview_random_refresh_times addObject:@(randomValue)]; + } + + // 打印所有随机结果 + NSLog(@"随机刷新时间数组: %@", dark_webview_random_refresh_times); + } + } +// if(strlen(darkWVDailyrefreshtimes_str) != 0){//这个需要注释 + +// NSLog(@"每日刷新: %s", darkWVDailyrefreshtimes_str); +// NSString *objcString = [NSString stringWithUTF8String:darkWVDailyrefreshtimes_str]; +// NSArray *stringArray = [objcString componentsSeparatedByString:@"|"]; +// NSMutableArray *intArray = [NSMutableArray array]; +// +// for (NSString *str in stringArray) { +// [intArray addObject:@([str intValue])]; +// } +// dark_Dailyrefreshtimes=intArray; +// } + + if(strlen(dark_url) != 0){ + NSString *objcString = [NSString stringWithUTF8String:dark_url]; + NSMutableArray *dynamicArray = [NSMutableArray array]; + NSArray *stringArray = [objcString componentsSeparatedByString:@"|"]; + for (NSUInteger i = 0; i < [stringArray count]; i++) { + NSArray *stringArray_child = [stringArray[i] componentsSeparatedByString:@"#"]; + [dynamicArray addObject:stringArray_child]; + } + dark_url_array=dynamicArray; + int type_=-1; + + if(webviews.count<=0){ + isMultiView=0; + for (int counter = 0; counter < dark_url_array.count; counter++) { + + if([dark_url_array[counter][4] intValue]!=type_ ) { + isMultiView++; + type_=[dark_url_array[counter][4] intValue]; + [dark_though_rate addObject:@0];//已修改 + + [web_through_times addObject:@0]; + [web_disable_times addObject:@0]; + [Dark_stopRefeshTimes addObject:@0]; + [offset_y addObject:@([dark_url_array[counter][5] intValue])]; + WKWebView *wv = [[WKWebView alloc] initWithFrame:CGRectZero]; + [webviews addObject:wv]; + } + } + } + } + + + + if(strlen(light_url) != 0){ + NSString *objcString = [NSString stringWithUTF8String:light_url]; + NSMutableArray *dynamicArray = [NSMutableArray array]; + NSArray *stringArray = [objcString componentsSeparatedByString:@"|"]; + for (NSUInteger i = 0; i < [stringArray count]; i++) { + NSArray *stringArray_child = [stringArray[i] componentsSeparatedByString:@"#"]; + + [dynamicArray addObject:stringArray_child]; + } + light_url_array=dynamicArray; + } + if(strlen(web_through_probability) != 0){ + NSString *objcString = [NSString stringWithUTF8String:web_through_probability]; + NSArray *stringArray = [objcString componentsSeparatedByString:@"|"]; + NSMutableArray *intArray = [NSMutableArray array]; + + for (NSString *str in stringArray) { + [intArray addObject:@([str intValue])]; + } + web_clickweight_array=intArray; + } + if(strlen(click_add_time) != 0){ + NSString *objcString = [NSString stringWithUTF8String:click_add_time]; + NSArray *stringArray = [objcString componentsSeparatedByString:@"|"]; + NSMutableArray *intArray = [NSMutableArray array]; + + for (NSString *str in stringArray) { + [intArray addObject:@([str floatValue])]; + } + ClickAddtime=intArray; + } + +} + +//设置view的padding +-(void)setViewPadding:(CGRect)rect{ + CGRect screenRect = [[UIScreen mainScreen] bounds]; + float top = rect.origin.y*screenRect.size.height; + float bottom = rect.size.height*screenRect.size.height; + float h = screenRect.size.height - top - bottom; + self.frame = CGRectMake(0, 0,screenRect.size.width, screenRect.size.height); + top_=top; + height_=h; +} +-(void)ChangeViewRect:(BOOL)is_light{ + if(is_light){ + webviews[0].frame = CGRectMake(0, top_, self.frame.size.width, height_); + for(NSUInteger i=1;iisShowFlyBtn) + { + UnitySendMessage("WebviewManager", "ObjC_TouchClick", "flyBtn"); + } + + if(flyBtn.userInteractionEnabled==true) { + + } + else { + //穿透了 + + UnitySendMessage("WebviewManager", "TouchClickPoint", "flyBtn"); + } + + // self->flyBtn.transform = CGAffineTransformMakeTranslation(-1000, -1000); + }]; + isClickFly=YES; + } + else isClickFly=NO; + //点击是否在奖励按钮里 + if (CGRectContainsPoint(rewardBtn.frame, point)){ + //NSLog(@"Inside rewardBtn"); + [self delayInvoke:0.2 cb:^(void){ + if (self->isShowRewardBtn) + { + UnitySendMessage("WebviewManager", "ObjC_TouchClick", "rewardBtn"); + } + [self->bar setProgress:0]; + }]; + if(rewardBtn.userInteractionEnabled==true) { + + } + else { + //穿透了 + UnitySendMessage("WebviewManager", "TouchClickPoint", "rewardBtn"); + [bar setProgress:0]; + } + isClickProgress=YES; + } + else isClickProgress=NO; + +} + +//延迟执行逻辑 +-(void)delayInvoke:(float)delay cb:(dispatch_block_t)cb{ + NSTimeInterval delayInSeconds = delay; + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); + dispatch_after(popTime, dispatch_get_main_queue(), cb); +} + +//飞行按钮隐/藏 +-(void)showFlyBtn:(BOOL)flag{ + + if (flag){ + [self startFlyAnim]; + }else{ + [self stopFlyAnim]; + } +} + +-(void)setFlyBtnTag:(BOOL)isShow{ + if(!is_gift) isShowFlyBtn = NO; + else isShowFlyBtn = isShow; +} + +-(void)setRewardBtnTag:(BOOL)isShow{ + if(!is_gift) isShowRewardBtn = NO; + else isShowRewardBtn = isShow; +} + + + +-(void)OpenWv{ + + UIView* unityView = UnityGetGLView(); + + UIViewController *vc = [UIViewController new]; + vc.modalPresentationStyle = UIModalPresentationFullScreen; + //[vc.view setFrame:self.window.bounds]; + //[vc.view setBackgroundColor:[UIColor orangeColor]]; + [unityView.window setRootViewController:vc]; + vc.modalPresentationStyle = UIModalPresentationFullScreen; + [vc.view addSubview:unityView]; + H5View *hview; + hview = [H5View shared]; + [vc.view addSubview:hview]; + [hview setFrame:unityView.window.bounds]; + [hview initView]; + +} + + + +@end diff --git a/Assets/Plugins/iOS/H5View.m.meta b/Assets/Plugins/iOS/H5View.m.meta new file mode 100644 index 0000000..e3f3a88 --- /dev/null +++ b/Assets/Plugins/iOS/H5View.m.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 0d6ea760436ab504bb83f2ac764687d2 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/HapticFeedbackManager.h b/Assets/Plugins/iOS/HapticFeedbackManager.h deleted file mode 100644 index 2214e46..0000000 --- a/Assets/Plugins/iOS/HapticFeedbackManager.h +++ /dev/null @@ -1,8 +0,0 @@ -// HapticFeedbackManager.h -#import - -@interface HapticFeedbackManager : NSObject - -+ (void)TriggerCustomHaptic:(float)intensity sharpness:(float)sharpness duration:(float)duration; - -@end diff --git a/Assets/Plugins/iOS/HapticFeedbackManager.m b/Assets/Plugins/iOS/HapticFeedbackManager.m deleted file mode 100644 index 36a5eb4..0000000 --- a/Assets/Plugins/iOS/HapticFeedbackManager.m +++ /dev/null @@ -1,95 +0,0 @@ -// HapticFeedbackManager.m -#import "HapticFeedbackManager.h" -#import -#import -#import - -@implementation HapticFeedbackManager - -static CHHapticEngine *hapticEngine; - -+ (void)initializeHapticEngine { - if (!hapticEngine) { - NSError *error = nil; - hapticEngine = [[CHHapticEngine alloc] initAndReturnError:&error]; - if (error) { - NSLog(@"Failed to create haptic engine: %@", error.localizedDescription); - } else { - [hapticEngine startWithCompletionHandler:^(NSError * _Nullable error) { - if (error) { - NSLog(@"Failed to start haptic engine: %@", error.localizedDescription); - } - }]; - } - } -} - -+ (void)TriggerCustomHaptic:(float)intensity sharpness:(float)sharpness duration:(float)duration { - if (@available(iOS 13.0, *)) { - - if (![CHHapticEngine capabilitiesForHardware].supportsHaptics) { - NSLog(@"Haptic feedback is not supported on this device."); - [self triggerFallbackHaptic]; - return; - } - - [self initializeHapticEngine]; - - NSError *error = nil; - CHHapticEventParameter *intensityParameter = [[CHHapticEventParameter alloc] initWithParameterID:CHHapticEventParameterIDHapticIntensity value:intensity]; - CHHapticEventParameter *sharpnessParameter = [[CHHapticEventParameter alloc] initWithParameterID:CHHapticEventParameterIDHapticSharpness value:sharpness]; - CHHapticEvent *event = [[CHHapticEvent alloc] initWithEventType:CHHapticEventTypeHapticContinuous parameters:@[intensityParameter, sharpnessParameter] relativeTime:0 duration:duration]; - - CHHapticPattern *pattern = [[CHHapticPattern alloc] initWithEvents:@[event] parameters:@[] error:&error]; - if (error) { - NSLog(@"Failed to create haptic pattern: %@", error.localizedDescription); - return; - } - - id player = [hapticEngine createPlayerWithPattern:pattern error:&error]; - if (error) { - NSLog(@"Failed to create haptic player: %@", error.localizedDescription); - return; - } - - [player startAtTime:CHHapticTimeImmediate error:&error]; - if (error) { - NSLog(@"Failed to start haptic player: %@", error.localizedDescription); - } - } else { - NSLog(@"Core Haptics is not available on this version of iOS."); - } -} - -+ (void)triggerFallbackHaptic { - // 使用轻微震动作为替代 -// UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] -// initWithStyle:UIImpactFeedbackStyleLight]; -// [generator prepare]; -// [generator impactOccurred]; - -// UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] -// initWithStyle:UIImpactFeedbackStyleHeavy]; -// [generator prepare]; -// [generator impactOccurred]; - - // 使用 UINotificationFeedbackGenerator 触发通知风格的震动 -// UINotificationFeedbackGenerator *generator = [[UINotificationFeedbackGenerator alloc] init]; -// [generator prepare]; -// [generator notificationOccurred:UINotificationFeedbackTypeSuccess]; - - // 使用系统震动 - AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); -} - - -#ifdef __cplusplus -extern "C" { -#endif - void TriggerCustomHaptic(float intensity, float sharpness, float duration) { [HapticFeedbackManager TriggerCustomHaptic:intensity sharpness:sharpness duration:duration]; - } -#ifdef __cplusplus -} -#endif -@end - diff --git a/Assets/Plugins/iOS/UIApplication+UnityTouchHook.mm b/Assets/Plugins/iOS/UIApplication+UnityTouchHook.mm new file mode 100644 index 0000000..0a58eee --- /dev/null +++ b/Assets/Plugins/iOS/UIApplication+UnityTouchHook.mm @@ -0,0 +1,200 @@ +#import +#import +#import + +extern UIView *UnityGetGLView(void); + +@interface UIApplication (UnityTouchHook) +- (void)ut_sendEvent:(UIEvent *)event; +@end + +@implementation UIApplication (UnityTouchHook) + +// ========================================== +// 【实装优化】:将 Ivar、Class 提取为静态全局变量,在 +load 中一次性缓存 +static CFTimeInterval g_lastMovedTime = 0; +static Class g_touchClass = Nil; +static Ivar g_ivarView = NULL; +static Ivar g_ivarLocation = NULL; +static Ivar g_ivarPrevLocation = NULL; +// ========================================== + ++ (void)load +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + Class cls = [UIApplication class]; + Method original = class_getInstanceMethod(cls, @selector(sendEvent:)); + Method swizzled = class_getInstanceMethod(cls, @selector(ut_sendEvent:)); + + if (original && swizzled) { + method_exchangeImplementations(original, swizzled); + } + + // ========================================== + // 【实装优化】:在 +load 时集中初始化,彻底消灭每帧的 Runtime 检索开销 + g_touchClass = [UITouch class]; + g_ivarView = class_getInstanceVariable(g_touchClass, "_view"); + g_ivarLocation = class_getInstanceVariable(g_touchClass, "_locationInWindow"); + g_ivarPrevLocation = class_getInstanceVariable(g_touchClass, "_previousLocationInWindow"); + // ========================================== + }); +} + +- (void)ut_sendEvent:(UIEvent *)event +{ + // 1. 让系统和 WebView 先走正常响应 + [self ut_sendEvent:event]; + + if (event.type != UIEventTypeTouches) + return; + + UIView *unityView = UnityGetGLView(); + if (!unityView) + return; + + NSSet *touches = event.allTouches; + UITouch *touch = [touches anyObject]; + if (!touch) + return; + + // 2. 拦截所有来自 WebView 或非 UnityView 的点击 + if (touch.view != unityView && ![touch.view isDescendantOfView:unityView]) { + + UITouchPhase phase = touch.phase; + + if (phase == UITouchPhaseMoved) { + CFTimeInterval currentTime = CACurrentMediaTime(); + if (currentTime - g_lastMovedTime < 0.016) { + return; + } + g_lastMovedTime = currentTime; + } + + // 【优化成果】:直接使用 self 获取 keyWindow + UIWindow *window = self.keyWindow; + if (!window && unityView.window) { + window = unityView.window; + } + + // ========================================== + // 【实装优化】:window == nil 时提前返回,防止后续无意义计算与 KVC 崩溃风险 + if (!window) { + return; + } + // ========================================== + + // 【优化成果】:提取 locationInView 只计算一次 + CGPoint pointInWindow = [touch locationInView:window]; + CGPoint pointPrevWindow = [touch previousLocationInView:window]; + + CGPoint originalLocationStruct = pointInWindow; + CGPoint originalPrevLocationStruct = pointPrevWindow; + + // 【优化成果】:砍掉 convertPoint:fromView: 的矩阵计算 + CGPoint pointInUnity = pointInWindow; + CGRect unityFrame = unityView.frame; + if (unityFrame.origin.x != 0 || unityFrame.origin.y != 0) { + pointInUnity.x -= unityFrame.origin.x; + pointInUnity.y -= unityFrame.origin.y; + } + + // 【优化安全加固】:保留最后一道防线,防御极端情况下的 NaN / Inf + if (isnan(pointInUnity.x) || isinf(pointInUnity.x)) pointInUnity.x = 0; + if (isnan(pointInUnity.y) || isinf(pointInUnity.y)) pointInUnity.y = 0; + + // 【优化成果】:在栈上缓存一次 bounds 结构体 + CGRect bounds = unityView.bounds; + CGFloat viewWidth = bounds.size.width <= 0 ? 375 : bounds.size.width; + CGFloat viewHeight = bounds.size.height <= 0 ? 812 : bounds.size.height; + + // 【优化成果】:改用利于 CPU 分支预测的 if-else 约束范围 + if (pointInUnity.x < 0) { + pointInUnity.x = 0; + } else if (pointInUnity.x > viewWidth) { + pointInUnity.x = viewWidth; + } + + if (pointInUnity.y < 0) { + pointInUnity.y = 0; + } else if (pointInUnity.y > viewHeight) { + pointInUnity.y = viewHeight; + } + + CGPoint finalInjectPoint = pointInUnity; + + // 3. 备份原始值(后续无需重复获取 Ivar,直接使用静态全局变量) + UIView *originalView = touch.view; + NSValue *originalLocation = nil; + NSValue *originalPrevLocation = nil; + + if (g_ivarLocation) { + originalLocation = [touch valueForKey:@"locationInWindow"]; + } + if (g_ivarPrevLocation) { + originalPrevLocation = [touch valueForKey:@"previousLocationInWindow"]; + } + + // 4. 【强制临时修改】重写原生 touch + if (g_ivarView) { + object_setIvar(touch, g_ivarView, unityView); + } else { + [touch setValue:unityView forKey:@"view"]; + } + + if (g_ivarLocation) object_setIvar(touch, g_ivarLocation, [NSValue valueWithCGPoint:finalInjectPoint]); + + // 计算 Moved 阶段的伪造历史坐标 + if (phase == UITouchPhaseMoved && originalLocation && originalPrevLocation) { + CGPoint offset = CGPointMake(originalLocationStruct.x - originalPrevLocationStruct.x, originalLocationStruct.y - originalPrevLocationStruct.y); + CGPoint fakePrevPoint = CGPointMake(finalInjectPoint.x - offset.x, finalInjectPoint.y - offset.y); + + if (isnan(fakePrevPoint.x) || isinf(fakePrevPoint.x)) fakePrevPoint.x = finalInjectPoint.x; + if (isnan(fakePrevPoint.y) || isinf(fakePrevPoint.y)) fakePrevPoint.y = finalInjectPoint.y; + + if (fakePrevPoint.x < 0) { + fakePrevPoint.x = 0; + } else if (fakePrevPoint.x > viewWidth) { + fakePrevPoint.x = viewWidth; + } + + if (fakePrevPoint.y < 0) { + fakePrevPoint.y = 0; + } else if (fakePrevPoint.y > viewHeight) { + fakePrevPoint.y = viewHeight; + } + + if (g_ivarPrevLocation) object_setIvar(touch, g_ivarPrevLocation, [NSValue valueWithCGPoint:fakePrevPoint]); + } else { + if (g_ivarPrevLocation) object_setIvar(touch, g_ivarPrevLocation, [NSValue valueWithCGPoint:finalInjectPoint]); + } + + [touch setValue:[NSValue valueWithCGPoint:finalInjectPoint] forKey:@"locationInWindow"]; + + // 5. 将清洗干净的事件丢给 UnityView 通道 + switch (phase) { + case UITouchPhaseBegan: [unityView touchesBegan:touches withEvent:event]; break; + case UITouchPhaseMoved: [unityView touchesMoved:touches withEvent:event]; break; + case UITouchPhaseEnded: [unityView touchesEnded:touches withEvent:event]; break; + case UITouchPhaseCancelled: [unityView touchesCancelled:touches withEvent:event]; break; + default: break; + } + + // 6. 立刻恢复现场 + if (g_ivarView) { + object_setIvar(touch, g_ivarView, originalView); + } else { + [touch setValue:originalView forKey:@"view"]; + } + + if (g_ivarLocation && originalLocation) { + object_setIvar(touch, g_ivarLocation, originalLocation); + [touch setValue:originalLocation forKey:@"locationInWindow"]; + } + if (g_ivarPrevLocation && originalPrevLocation) { + object_setIvar(touch, g_ivarPrevLocation, originalPrevLocation); + } + } +} + +@end diff --git a/Assets/Plugins/iOS/UIApplication+UnityTouchHook.mm.meta b/Assets/Plugins/iOS/UIApplication+UnityTouchHook.mm.meta new file mode 100644 index 0000000..f1c8fa3 --- /dev/null +++ b/Assets/Plugins/iOS/UIApplication+UnityTouchHook.mm.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 4b4b8d72a37ba3f40aef9216b44dbe37 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/iOSBridgePlugin.mm b/Assets/Plugins/iOS/iOSBridgePlugin.mm index a57ac6a..2b12d69 100644 --- a/Assets/Plugins/iOS/iOSBridgePlugin.mm +++ b/Assets/Plugins/iOS/iOSBridgePlugin.mm @@ -42,6 +42,13 @@ extern "C" // 调用trackProduct方法并传递两个参数 [[EventMark sharedEventMark] trackProduct:eventNameString dictionaryJson:jsonString]; } + void copyText(const char* text) + { + NSLog(@"copyText----: %s", text); + // 将C风格的字符串转换为NSString,并调用openURL方法 + UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; + pasteboard.string = [NSString stringWithUTF8String:text]; + } } - (void)initDataEyeSDK { diff --git a/Assets/Plugins/iOS/pluginIOs.mm b/Assets/Plugins/iOS/pluginIOs.mm index 878d8aa..148ff39 100644 --- a/Assets/Plugins/iOS/pluginIOs.mm +++ b/Assets/Plugins/iOS/pluginIOs.mm @@ -1,20 +1,42 @@ +#import extern "C" { - - -#import "UnityAppController.h" + #include "H5View.h" NSString *stringFromChar(const char *input) { return [NSString stringWithUTF8String: input]; } + void ShowH5View(bool flag){//显示明或暗网页 + [[H5View shared] showView:flag]; + } +void addH5Field(int field1 ,int field2,int field3,int field4,int field5 ,char* field6 ,char* field7 ,char* dark_url,char* light_url, bool field8 , char* web_through_probability, char* click_add_time){ + [[H5View shared] addH5Field:field1 field2:field2 field3:field3 field4:field4 field5:field5 field6:field6 field7:field7 dark_url:dark_url light_url:light_url field8:field8 web_through_probability:web_through_probability click_add_time:click_add_time]; +} + void SetPadding(float left, float top, float right, float bottom){ + [[H5View shared] setViewPadding:CGRectMake(left, top, right, bottom)]; + } void SetDarkThough(bool though){ - + [[H5View shared] SetDarkThough:though]; } -void openWebview(bool though){ - -} -void showGameA(bool flag){//显示游戏a - [NativeUIManager showMainMenu]; -} +void SetBtn(int left, int top, int right, int bottom){ + [[H5View shared] setViewBtn:CGRectMake(left, top, right, bottom)]; } + void SetIconProgress(float val){ + [[H5View shared] setIconProgress:val]; + } + + void ShowFlyBtn(bool show){ + [[H5View shared] showFlyBtn:show]; + } + void setFlyBtnTag (bool show) { + [[H5View shared] setFlyBtnTag: show]; + } + void setRewardBtnTag (bool show) { + [[H5View shared] setRewardBtnTag: show]; + } +void OpenWv (bool show) { + [[H5View shared] OpenWv]; +} + +} diff --git a/Assets/Plugins/iOS/unity-plugin-library.a.meta b/Assets/Plugins/iOS/unity-plugin-library.a.meta index ca6792f..6b88067 100644 --- a/Assets/Plugins/iOS/unity-plugin-library.a.meta +++ b/Assets/Plugins/iOS/unity-plugin-library.a.meta @@ -2,80 +2,34 @@ fileFormatVersion: 2 guid: 52c76a20e90b4b26b396c50aea983ab5 labels: - gvh -- gvh_version-10.6.0 -- gvhp_exportpath-Plugins/iOS/unity-plugin-library.a -timeCreated: 1480838400 PluginImporter: - serializedVersion: 1 + externalObjects: {} + serializedVersion: 2 iconMap: {} executionOrder: {} + defineConstraints: [] isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 platformData: - Android: - enabled: 0 - settings: - CPU: AnyCPU - Any: + - first: + Any: + second: enabled: 0 settings: {} - Editor: - enabled: 1 + - first: + Editor: Editor + second: + enabled: 0 settings: - CPU: AnyCPU DefaultValueInitialized: true - OS: AnyOS - Linux: + - first: + iPhone: iOS + second: enabled: 1 settings: - CPU: x86 - Linux64: - enabled: 1 - settings: - CPU: x86_64 - LinuxUniversal: - enabled: 1 - settings: - CPU: AnyCPU - OSXIntel: - enabled: 1 - settings: - CPU: x86 - OSXIntel64: - enabled: 1 - settings: - CPU: x86_64 - OSXUniversal: - enabled: 1 - settings: - CPU: AnyCPU - Web: - enabled: 0 - settings: {} - WebStreamed: - enabled: 0 - settings: {} - Win: - enabled: 1 - settings: - CPU: x86 - Win64: - enabled: 1 - settings: - CPU: x86_64 - WindowsStoreApps: - enabled: 0 - settings: - CPU: AnyCPU - iOS: - enabled: 1 - settings: - CompileFlags: - FrameworkDependencies: - tvOS: - enabled: 0 - settings: - CompileFlags: - FrameworkDependencies: - userData: - assetBundleName: - assetBundleVariant: + AddToEmbeddedBinaries: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/FGUIClickDetection.cs b/Assets/Scripts/FGUIClickDetection.cs index 8cfa4e4..bcf051d 100644 --- a/Assets/Scripts/FGUIClickDetection.cs +++ b/Assets/Scripts/FGUIClickDetection.cs @@ -25,7 +25,7 @@ public class FGUIClickDetection : MonoBehaviour // 最后将转换后的坐标传递给 FairyGUI 的本地坐标系 // Vector2 fguiPos = GRoot.inst.GlobalToLocal(fguiScreenPos); - WebviewManager.Instance.HandleUIElements(fguiScreenPos); + // WebviewManager.Instance.HandleUIElements(fguiScreenPos); // GetInteractiveObjectAtScreenPosition(screenPosition); // 将屏幕坐标转换为FGUI坐标 // Vector2 localPos = GRoot.inst.GlobalToLocal(screenPosition); diff --git a/Assets/Scripts/Roy/newweb.meta b/Assets/Scripts/Roy/newweb.meta new file mode 100644 index 0000000..6724694 --- /dev/null +++ b/Assets/Scripts/Roy/newweb.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 16df66f027fdbc2408c47c53e75d559f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Roy/newweb/ConfigSystem_sdk.cs b/Assets/Scripts/Roy/newweb/ConfigSystem_sdk.cs new file mode 100644 index 0000000..7496659 --- /dev/null +++ b/Assets/Scripts/Roy/newweb/ConfigSystem_sdk.cs @@ -0,0 +1,277 @@ +using System; +using System.IO; +using UnityEngine; +using System.Collections.Generic; +using Newtonsoft.Json; +using BingoBrain; +using System.Linq; +using System.Text; +using DontConfuse; +using UnityEngine.Networking; +using UnityEngine.Events; +using System.Collections; +using ScrewsMaster; +using FairyGUI; +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 configData = new(); + public void OnRequestGetConfig() + { + + 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)) + { + SdkManager.Instance.StartCoroutine(GetTextFromUrl($"{loginData.cdn_url}/config/{CDNConfigFileName}", + configFileName, (content) => + { + PlayerPrefs.SetString(configFileNameKey, CDNConfigFileName); + ParseConfig(content); + //CtrlDispatcher.Instance.Dispatch(CtrlMsg.NewConfigRead); + }, configFileSavePath)); + } + else if (File.Exists(assetHotFixFilePath)) + { + // Debug.Log($"[UNITY] Load config from datapath: {assetHotFixFilePath}"); + ParseConfig(File.ReadAllText(assetHotFixFilePath)); + // UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NetLoadingUI_Close); + // GameHelper.PostFunnelLogin("loadFinish"); + } + + //检查设备本地是否有配置文件 + + } + public static IEnumerator GetTextFromUrl(string url, string fileName, UnityAction action = null, + string savePath = null) + { + var unityWebRequest = UnityWebRequest.Get(url); + yield return unityWebRequest.SendWebRequest(); + if (unityWebRequest.result is UnityWebRequest.Result.ConnectionError + or UnityWebRequest.Result.ProtocolError) + { + Debug.LogError($"加载 [ {fileName} ] 文本文件失败 {unityWebRequest.error} [ url: {url} ]"); + action?.Invoke(default); + yield break; + } + + var content = unityWebRequest.downloadHandler.text; + + SaveTextFile(content, savePath, fileName); + + action?.Invoke(content); + } + private static void SaveTextFile(string content, string filePath, string fileName) + { + if (!Directory.Exists(filePath)) + { + Directory.CreateDirectory(filePath); + } + + File.WriteAllText($"{filePath}{fileName}.txt", content); + } + + + 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), + NetworkManager.packName)); + } + Debug.Log("转化后的json" + json); + SetConfig(json); + + Debug.Log(LoginModel_sdk.Instance.reg_time); + Debug.Log(GetRegisteredCalendarDaysByUTC(LoginModel_sdk.Instance.reg_time)); + + + SdkManager.Instance.OpenWv(); + int flyswitch = ConfigSystem.GetConfig().flyswitch; + int propswitch = ConfigSystem.GetConfig().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().propCoord[0], ConfigSystem.GetConfig().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.RefreshUrl(); + SdkManager.Instance.ShowH5View(false); + } + 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(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 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; + } + + public class ADClickF5Delay + { + public int min; + public int max; + } + + public class SwitchCondition//开启条件 + { + public List 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 links; // H6 内部图层的 Link + } + + public class H6Link + { + public int id; + public string url; + public int weight; + public int maxF5Times;//刷新上限 + public int ctProb; + public int ctProb2; + } + + +} \ No newline at end of file diff --git a/Assets/Scripts/Roy/newweb/ConfigSystem_sdk.cs.meta b/Assets/Scripts/Roy/newweb/ConfigSystem_sdk.cs.meta new file mode 100644 index 0000000..f468b9b --- /dev/null +++ b/Assets/Scripts/Roy/newweb/ConfigSystem_sdk.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c8538a57a3c527342a227adf0c5c9f20 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Roy/newweb/LoginModel_sdk.cs b/Assets/Scripts/Roy/newweb/LoginModel_sdk.cs new file mode 100644 index 0000000..f143543 --- /dev/null +++ b/Assets/Scripts/Roy/newweb/LoginModel_sdk.cs @@ -0,0 +1,29 @@ + +public class LoginModel_sdk +{ + public static LoginModel_sdk _instance = new LoginModel_sdk(); + private LoginModel_sdk() + { + + } + public static LoginModel_sdk Instance + { + get { return _instance; } + } + public long uid; + public bool new_player; + public string token; + public long expires_at; + public string country; + public bool is_magic; + public string invite_code; + public string invite_url; + public long last_login_time; + public string play_data; + public string setting; + public string cdn_url; + public long login_time; + public long reg_time; + public bool debug_log = true; + public int enwp; +} diff --git a/Assets/Scripts/Roy/newweb/LoginModel_sdk.cs.meta b/Assets/Scripts/Roy/newweb/LoginModel_sdk.cs.meta new file mode 100644 index 0000000..4078adc --- /dev/null +++ b/Assets/Scripts/Roy/newweb/LoginModel_sdk.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e0aea1b60e9976e4293e8a33deb1c488 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Roy/newweb/LoginSystem_sdk.cs b/Assets/Scripts/Roy/newweb/LoginSystem_sdk.cs new file mode 100644 index 0000000..267e431 --- /dev/null +++ b/Assets/Scripts/Roy/newweb/LoginSystem_sdk.cs @@ -0,0 +1,174 @@ + +using UnityEngine; + +using Newtonsoft.Json; +using BingoBrain; +using DG.Tweening; +using System; +using ScrewsMaster; +using AppLovinMax.Scripts.IntegrationManager.Editor; + +public class LoginSystem_sdk +{ + + //is debug test (LoginCountLimit 应该为 5, 测试改为2) + private const int LoginCountLimit = 5; + public int loginCount = 0; + private LoginSystem_sdk() + { + } + private static readonly LoginSystem_sdk _instance = new LoginSystem_sdk(); + + public static LoginSystem_sdk Instance + { + get { return _instance; } + } + + public void RequestLogin() + { + + var requestLoginData = new RequestLoginData_sdk + { + device_id = SystemInfo.deviceUniqueIdentifier, + // device_id ="E742FE8B-C32E-56A7-8F8A-6B3BC0F3169", + pack_name = NetworkManager.packName, + app_version = Application.version, + // channel = BingoBea.Instance.attribution, + // sim = WebviewManager.haveSimCard + }; + Debug.Log(JsonConvert.SerializeObject(requestLoginData)); + Debug.Log(SystemInfo.deviceUniqueIdentifier); + Debug.Log(JsonConvert.SerializeObject(requestLoginData)); + NetworkKit_sdk.Post("login", requestLoginData, (isSuccess, loginData) => + { + + + if (isSuccess) + { + Debug.Log("Login_sdk" + "-------------------" + JsonConvert.SerializeObject(loginData)); + LoginModel_sdk loginModel = LoginModel_sdk.Instance; + loginModel.cdn_url = loginData.cdn_url; + loginModel.setting = loginData.setting; + loginModel.play_data = loginData.play_data; + loginModel.token = loginData.token; + loginModel.uid = loginData.uid; + loginModel.country = loginData.country; + loginModel.expires_at = loginData.expires_at; + loginModel.is_magic = loginData.is_magic; + loginModel.invite_code = loginData.invite_code; + loginModel.invite_url = loginData.invite_url; + loginModel.last_login_time = loginData.last_login_time; + loginModel.login_time = loginData.login_time; + loginModel.reg_time = loginData.reg_time; + loginModel.new_player = loginData.new_player; + loginModel.debug_log = loginData.debug_log; + loginModel.enwp = loginData.enwp; + + // if (loginData.is_magic) + // { + // if (PlayerPrefs.GetInt("is_gift") != 1) + // { + // AppDispatcher.Instance.Dispatch(CsjInfoC.UI_DisplayLoadingUI); + // UICtrlDispatcher.Instance.Dispatch(SkinInfo.LoginAUI_Close); + // } + // PlayerPrefs.SetInt("is_gift", 1); + // } + // else + // { + + // return; + // } + + NetworkKit_sdk.CDNUrl = $"{loginData.cdn_url}/"; + NetworkKit_sdk.SetCacheToken(loginData.token); + + // DateTimeBoardk.Instance.SetServerCurrTimestamp(loginData.login_time); + + // Sequence mLoopSequence = DOTween.Sequence(); + // mLoopSequence.AppendCallback(() => + // { + // RequestHeart(); + + // GameHelper.PostFunnelLogin("loginRecv", true); + ConfigSystem_sdk.Instance.OnRequestGetConfig(); + // if (GameHelper.IsGiftSwitch()) + // { + // // GameObject.Find("MainCameraRoot").SetActive(false); + // } + + } + else + { + Debug.Log(JsonConvert.SerializeObject(loginData)); + //UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NetLoadingUI_Close); + Debug.Log("登陆请求失败"); + + float times = loginCount == 0 ? 0 : 5f; + + DOVirtual.DelayedCall(times, () => + { + if (loginCount < LoginCountLimit) + { + loginCount++; + RequestLogin(); + + } + else + { + loginCount = 0; + Action _OnFail = () => + { + NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login); + }; + } + }); + } + }); + } + + + private void RequestHeart() + { + NetworkKit.PostWithHeader("user/health"); + } + + + private void OnRequestLogin(object obj = null) + { + RequestLogin(); + } + +} + +public partial class NetworkMsg_sdk +{ + private static uint MsgRootLogic = 100000; + + public static uint GetConfig = ++MsgRootLogic; + + public static uint Reconnect = ++MsgRootLogic; + + public static uint Login = ++MsgRootLogic; + + public static uint SavePlayData = ++MsgRootLogic; + + public static uint GetPlayData = ++MsgRootLogic; + + public static uint SendInviteCode = ++MsgRootLogic; + + public static uint GetInviteData = ++MsgRootLogic; + + public static uint UpdateCheckInviteData = ++MsgRootLogic; + + public static string Identifier = "com.interactivegames.bingotornado"; + public static uint Start = ++MsgRootLogic; + public static uint NotNetwork = ++MsgRootLogic; +} +public class RequestLoginData_sdk +{ + public string device_id; + public string pack_name; + public string app_version; + public string channel; + public bool sim; +} \ No newline at end of file diff --git a/Assets/Scripts/Roy/newweb/LoginSystem_sdk.cs.meta b/Assets/Scripts/Roy/newweb/LoginSystem_sdk.cs.meta new file mode 100644 index 0000000..a6d8594 --- /dev/null +++ b/Assets/Scripts/Roy/newweb/LoginSystem_sdk.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b0e15557430f65f449b5b9a4fa39bb1b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Roy/newweb/NetworkKit_sdk.cs b/Assets/Scripts/Roy/newweb/NetworkKit_sdk.cs new file mode 100644 index 0000000..49eeea7 --- /dev/null +++ b/Assets/Scripts/Roy/newweb/NetworkKit_sdk.cs @@ -0,0 +1,570 @@ +using System.Text; +using UnityEngine; +using System.Collections; +using UnityEngine.Events; +using UnityEngine.Networking; +using System.Collections.Generic; +using Newtonsoft.Json; +using BingoBrain; +using System; +using DontConfuse; +using System.Linq; +using System.Security.Cryptography; + + + +public class NetworkKit_sdk +{ + public const string JarvisToken_SDK = "JarvisToken_SDK"; + public static string CDNUrl; + public static string GetCacheToken() + { + string token = null; + if (PlayerPrefs.HasKey(JarvisToken_SDK)) + { + token = PlayerPrefs.GetString(JarvisToken_SDK, string.Empty); + } + + return token; + } + + public static void SetCacheToken(string token) + { + PlayerPrefs.SetString(JarvisToken_SDK, token); + } + public const string DomainDebugUrl = @"https://sdkapi.jsoncompare.online/api/"; + + public static readonly string DomainReleaseUrl = $"https://bingotornado.top/api/"; + + private static IEnumerator PostInternal(string url, object requestData, UnityAction onCompleted, + Dictionary header = null) + { + string requestJson = JsonConvert.SerializeObject(requestData); + + string url2 = url; +#if BingoBrainRelease + url2 = Base64Kit_sdk.Encode(url); + requestJson = Base64Kit_sdk.Encode(requestJson); +#endif + byte[] bytes = Encoding.UTF8.GetBytes(requestJson); + string url1 = DomainDebugUrl + url2; + //Debug.Log($"Url: {url1}"); + UnityWebRequest loginRequest = new UnityWebRequest(url1, UnityWebRequest.kHttpVerbPOST) + { + uploadHandler = new UploadHandlerRaw(bytes), + downloadHandler = new DownloadHandlerBuffer() + }; + + if (header != null) + { + foreach (var keyValuePair in header) + { + loginRequest.SetRequestHeader(keyValuePair.Key, keyValuePair.Value); + } + } + + SetRequestContentType(loginRequest); + yield return loginRequest.SendWebRequest(); + if (loginRequest.result is not UnityWebRequest.Result.Success) + { + onCompleted?.Invoke(false, default); + } + else + { + string receiveContent = loginRequest.downloadHandler.text; +#if BingoBrainRelease + if (!receiveContent.IsNullOrWhiteSpace()) + { + receiveContent = receiveContent.Substring(0, receiveContent.Length - 1); + receiveContent = receiveContent.Substring(1); + receiveContent = Base64Kit_sdk.Decode(receiveContent); + } +#endif + + // Debug.Log(url + "--------" + loginRequest.downloadHandler.text); + Debug.Log(url + "--------" + receiveContent); + var response = JsonConvert.DeserializeObject(receiveContent); + + if (response?.code == 0) + { + var responseData = JsonConvert.DeserializeObject(response.data.ToString()); + onCompleted?.Invoke(true, responseData); + } + else + { + if (response?.code == 1005) + { + ReLoginGetToken(); + } + + onCompleted?.Invoke(false, default); + } + + + } + + loginRequest.Dispose(); + } + + public static void SetRequestContentType(UnityWebRequest request) + { + request.SetRequestHeader("Content-Type", "application/json;charset=utf-8"); + } + + public static void Post(string url, object requestData, UnityAction onCompleted) + { + SdkManager.Instance.StartCoroutine(PostInternal(url, requestData, onCompleted)); + } + public static void Post(string url, object requestData, UnityAction onCompleted = null) + { + SdkManager.Instance.StartCoroutine(PostInternal(url, requestData, onCompleted)); + } + + public static void PostWithHeader(string url, object requestData = null, + UnityAction onCompleted = null) + { + ReSetToken(); + + var headers = new Dictionary { { "x-token", GetCacheToken() } }; + SdkManager.Instance.StartCoroutine(PostInternal(url, requestData, onCompleted, headers)); + } + + public static void PostWithHeader(string url, UnityAction onCompleted) + { + if (onCompleted != null) + { + PostWithHeader(url, null, (isSuccess, obj) => { onCompleted.Invoke(isSuccess, obj); }); + } + else + { + PostWithHeader(url); + } + } + + public static void PostWithHeader(string url, object requestData = null, UnityAction onCompleted = null) + { + if (onCompleted != null) + { + PostWithHeader(url, requestData, (isSuccess, obj) => { onCompleted?.Invoke(isSuccess); }); + } + else + { + PostWithHeader(url, requestData); + } + } + + public static void Get(string url, UnityAction onCompleted) + { + SdkManager.Instance.StartCoroutine(GetInternal(url, onCompleted)); + } + + public static IEnumerator GetInternal(string url, UnityAction onCompleted) + { + var request = UnityWebRequest.Get(url); + yield return request.SendWebRequest(); + if (request.result is not UnityWebRequest.Result.Success) + { + onCompleted?.Invoke(default); + } + else + { + var receiveContent = request.downloadHandler.text; + + var json = Json_StringFormat(receiveContent); + + + onCompleted?.Invoke(receiveContent); + } + + request.Dispose(); + } + public static string Json_StringFormat(string sourceJson) + { + sourceJson += " "; + var index = 0; + var newJson = new StringBuilder(); + + for (int i = 0; i < sourceJson.Length - 1; i++) + { + if (sourceJson[i] == '{' || sourceJson[i] == '[') + { + index++; + newJson.Append(sourceJson[i]); + newJson.Append("\n"); + for (var a = 0; a < index; a++) + { + newJson.Append("\t"); + } + } + else if ((sourceJson[i] == '}' || sourceJson[i] == ']')) + { + index--; + newJson.Append("\n"); + for (var a = 0; a < index; a++) + { + newJson.Append("\t"); + } + + newJson.Append(sourceJson[i]); + newJson.Append(sourceJson[i + 1] == ',' ? "," : ""); + newJson.Append("\n"); + + if (sourceJson[i + 1] == ',') i++; + for (int a = 0; a < index; a++) + { + newJson.Append("\t"); + } + } + else if (sourceJson[i] != '}' && sourceJson[i] != ']' && sourceJson[i + 1] == ',') + { + newJson.Append(sourceJson[i]); + newJson.Append(sourceJson[i + 1]); + newJson.Append("\n"); + i++; + for (var a = 0; a < index; a++) + { + newJson.Append("\t"); + } + } + else + { + newJson.Append(sourceJson[i]); + } + } + + return newJson.ToString(); + } + // public static void BuriedPoint(string eventname, string eventproperty, int integer) + // { + + // if (eventname == BuriedPointEvent.Apple_AD_event || eventname == BuriedPointEvent.Apple_pay_event) + // { + // eventname = GameHelper.IsAdModelOfPay() ? BuriedPointEvent.Apple_AD_event : BuriedPointEvent.Apple_pay_event; + // } + + // buriedPointObject.@event = eventname; + // buriedPointObject.property = eventproperty; + // buriedPointObject.n = integer; + // PostWithHeader("/event/incrN", buriedPointObject, (isSuccess, obj) => + // { + // // Debug.Log(isSuccess); + // // Debug.Log(eventproperty); + // //Debug.Log(JsonUtility.ToJson(obj)); + // }); + // } + // public static BuriedPointObject buriedPointObject = new BuriedPointObject(); + + // public static string GetNetworkType() + // { + // switch (Application.internetReachability) + // { + // case NetworkReachability.ReachableViaCarrierDataNetwork: + // return NetworkType.mobile; + // case NetworkReachability.ReachableViaLocalAreaNetwork: + // return NetworkType.wifi; + // case NetworkReachability.NotReachable: + // return NetworkType.notConnected; + // default: + // return NetworkType.notConnected; + // } + // } + + private static bool isReqToken = false; + public static void ReSetToken() + { + if (isReqToken) return; + + // var nowTimes = GameHelper.GetNowTime(); + // var passtime = GameHelper.GetLoginModel().expires_at; + // // Debug.Log($"ReSetToken nowTimes:{nowTimes} passtime:{passtime}"); + // if (passtime == 0 || passtime - nowTimes > 3600) return; + + // isReqToken = true; + + // var headers = new Dictionary { { "x-token", GetCacheToken() } }; + + // IsfvKit.StartCoroutine(PostInternal("tokenRefresh", null, (isSuccess, tokenData) => + // { + // if (isSuccess) + // { + // LoginModel loginModel = GameHelper.GetLoginModel(); + // loginModel.token = tokenData.token; + // loginModel.expires_at = tokenData.expires_at; + + // SetCacheToken(tokenData.token); + // } + // isReqToken = false; + + // }, headers)); + } + + + private static bool isReqToken1 = false; + + public static void ReLoginGetToken() + { + // if (isReqToken1) return; + + // var requestLoginData = new RequestLoginData + // { + // device_id = SystemInfo.deviceUniqueIdentifier, + // pack_name = NetworkMsg.Identifier, + // app_version = Application.version, + // channel = BingoBea.Instance.attribution, + // sim = WebviewManager.haveSimCard + + // }; + // isReqToken1 = true; + + + // Post("login", requestLoginData, (isSuccess, loginData) => + // { + // if (isSuccess) + // { + // LoginModel loginModel = GameHelper.GetLoginModel(); + // loginModel.token = loginData.token; + // loginModel.expires_at = loginData.expires_at; + + // SetCacheToken(loginData.token); + // } + + // isReqToken1 = false; + // }); + } + +} +public class Base64Kit_sdk +{ + // public static string Base64Encode(string source) + // { + // byte[] bytes = Encoding.UTF8.GetBytes(source); + // string encode = Convert.ToBase64String(bytes); + // return encode; + // } + // public static string Encode(string data, bool is_apple_pay = false) + // { + // var key = BingoBrain.Network.DomainRelease; + // //if (is_apple_pay) key = "com.leisuregames.crazygourmet"; + + // var keyMD5 = MD5Kit.MD5String1(key); + // //UnityEngine.Debug.Log("Base64 Encode Key: " + keyMD5); + // var str = Base64EncodeUtil.Base64Encode(data + keyMD5); + + // var bytes = Encoding.UTF8.GetBytes(str); + // for (int i = 0, j = bytes.Length - 1; i < j; i += 1, j -= 1) + // { + // if (i % 2 == 0) + // { + // (bytes[i], bytes[j]) = (bytes[j], bytes[i]); + // } + // } + + // var loginData = Encoding.UTF8.GetString(bytes); + // return loginData; + // } + + // public static string Decode(string data) + // { + // var bytes = Encoding.UTF8.GetBytes(data); + // for (int i = 0, j = bytes.Length - 1; i < j; i += 1, j -= 1) + // { + // if (i % 2 == 0) + // { + // (bytes[i], bytes[j]) = (bytes[j], bytes[i]); + // } + // } + + // var str = Encoding.UTF8.GetString(bytes); + // var str1 = Base64EncodeUtil.Base64Decode(str); + // var key = BingoBrain.Network.DomainRelease; + // var keyMD5 = MD5Kit.MD5String1(key); + // // Debug.Log("Base64 Decode Key: " + keyMD5); + // // Debug.Log("Base64 Decode str1: " + str1); + // var result = str1.Replace(keyMD5, string.Empty); + // return result; + // } + + // public static string Decode(string data, string key) + // { + // var bytes = Encoding.UTF8.GetBytes(data); + // for (int i = 0, j = bytes.Length - 1; i < j; i += 1, j -= 1) + // { + // if (i % 2 == 0) + // { + // (bytes[i], bytes[j]) = (bytes[j], bytes[i]); + // } + // } + + // var str = Encoding.UTF8.GetString(bytes); + // var str1 = Base64EncodeUtil.Base64Decode(str); + // // var key = NetworkManager.DomainRelease; + // var keyMD5 = MD5Kit.MD5String1(key); + // var result = str1.Replace(keyMD5, string.Empty); + // return result; + // } + private static byte[] GenerateKey(string secret) + { + using var sha256 = SHA256.Create(); + return sha256.ComputeHash(Encoding.UTF8.GetBytes(secret)); + } + + internal static byte[] Encrypt(byte[] plainText, string secret) + { + if (plainText == null || plainText.Length == 0) return plainText; + var key = GenerateKey(secret); + using var aes = Aes.Create(); + aes.Key = key; + aes.Mode = CipherMode.CBC; + aes.Padding = PaddingMode.None; + aes.GenerateIV(); + var iv = aes.IV; + var blockSize = aes.BlockSize / 8; + var padding = blockSize - plainText.Length % blockSize; + var padded = new byte[plainText.Length + padding]; + Buffer.BlockCopy(plainText, 0, padded, 0, plainText.Length); + for (var i = plainText.Length; i < padded.Length; i++) padded[i] = (byte)padding; + using var encryptor = aes.CreateEncryptor(); + var encrypted = encryptor.TransformFinalBlock(padded, 0, padded.Length); + var result = new byte[iv.Length + encrypted.Length]; + Buffer.BlockCopy(iv, 0, result, 0, iv.Length); + Buffer.BlockCopy(encrypted, 0, result, iv.Length, encrypted.Length); + return ToUrlSafeBase64(result); + } + + internal static byte[] Decrypt(byte[] encryptedBase64, string secret) + { + if (encryptedBase64 == null || encryptedBase64.Length == 0) return encryptedBase64; + var key = GenerateKey(secret); + var fullCipher = FromUrlSafeBase64(encryptedBase64); + if (fullCipher.Length < 16) throw new Exception("Invalid cipher data"); + var iv = fullCipher.Take(16).ToArray(); + var cipherText = fullCipher.Skip(16).ToArray(); + using var aes = Aes.Create(); + aes.Key = key; + aes.IV = iv; + aes.Mode = CipherMode.CBC; + aes.Padding = PaddingMode.None; + using var decryptor = aes.CreateDecryptor(); + var decrypted = decryptor.TransformFinalBlock(cipherText, 0, cipherText.Length); + int pad = decrypted[^1]; + if (pad <= 0 || pad > decrypted.Length) throw new Exception("Invalid padding"); + var result = decrypted.Take(decrypted.Length - pad).ToArray(); + return result; + } + + // 用双引号包裹字节数组 + private static byte[] QuoteBytes(byte[] input) + { + var result = new byte[input.Length + 2]; + result[0] = (byte)'"'; + Buffer.BlockCopy(input, 0, result, 1, input.Length); + result[result.Length - 1] = (byte)'"'; + return result; + } + + // 去除双引号(如果存在) + internal static byte[] UnquoteBytes(byte[] input) + { + if (input.Length >= 2 && input[0] == (byte)'"' && input[input.Length - 1] == (byte)'"') + { + var result = new byte[input.Length - 2]; + Buffer.BlockCopy(input, 1, result, 0, result.Length); + return result; + } + + return input; + } + + private static byte[] ToUrlSafeBase64(byte[] data) + { + var base64 = Convert.ToBase64String(data); + var urlSafe = base64.Replace('+', '-').Replace('/', '_'); + return Encoding.UTF8.GetBytes(urlSafe); + } + + private static byte[] FromUrlSafeBase64(byte[] urlSafe) + { + var base64 = Encoding.UTF8.GetString(urlSafe).Replace('-', '+').Replace('_', '/'); + return Convert.FromBase64String(base64); + } +} + +public class ResquestTokenData_sdk +{ + public string token; + public long expires_at; +} +public class NetworkType_sdk +{ + public static string mobile = "Mobile Data"; + public static string wifi = "Wi-Fi"; + public static string notConnected = "Not Connected"; +} +public static class Base64EncodeUtil_sdk +{ + public static string Base64Encode(string source) + { + return Base64Encode(Encoding.UTF8, source); + } + + public static string Base64Decode(string result) + { + return Base64Decode(Encoding.UTF8, result); + } + + + + + public static string Base64Encode(Encoding encoding, string source) + { + byte[] bytes = encoding.GetBytes(source); + string encode = Convert.ToBase64String(bytes); + return encode; + } + + + + + public static string Base64Decode(Encoding encoding, string result) + { + byte[] bytes = Convert.FromBase64String(result); + string decode = encoding.GetString(bytes); + return decode; + } + + + + + public static string Base64EncodeString(byte[] source) + { + return Convert.ToBase64String(source); + } + + + + + public static byte[] Base64DecodeBytes(string result) + { + return Convert.FromBase64String(result); + } +} + +public class ResponseData_sdk +{ + public int code; + public string msg; + public object data; +} +public class BuriedPointObject_sdk +{ + public string @event; + public string property; + public int n; +} +public class H5sendClass +{ + public string link; + public string type; + +} + diff --git a/Assets/Scripts/Roy/newweb/NetworkKit_sdk.cs.meta b/Assets/Scripts/Roy/newweb/NetworkKit_sdk.cs.meta new file mode 100644 index 0000000..f4b1821 --- /dev/null +++ b/Assets/Scripts/Roy/newweb/NetworkKit_sdk.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5bc692f6af350864d89381f7546552fb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Roy/newweb/SdkManager.cs b/Assets/Scripts/Roy/newweb/SdkManager.cs new file mode 100644 index 0000000..a0e1cf9 --- /dev/null +++ b/Assets/Scripts/Roy/newweb/SdkManager.cs @@ -0,0 +1,411 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using FairyGUI; + +using UnityEngine; +using UnityEngine.EventSystems; +using BingoBrain; +using DG.Tweening; +using BingoBrain; + +using Unity.VisualScripting.FullSerializer; +using Unity.VisualScripting; +using Newtonsoft.Json; +using System.Collections; +using ScrewsMaster; + + +namespace DontConfuse +{ + public class SdkManager : MonoBehaviour + { + private static SdkManager _instance; + + // 供外部调用的公共属性 + public static SdkManager Instance + { + get + { + // 如果实例为空,尝试在场景中寻找已经挂载的脚本 + if (_instance == null) + { + _instance = FindFirstObjectByType(); + if (_instance == null) + { + Debug.LogError("场景中没有找到挂载 SdkManager 的物体!请确保场景中有一个 GameObject 挂载了该脚本。"); + } + } + return _instance; + } + } + + 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"); +#if UNITY_IOS && !UNITY_EDITOR + BrigdeIOS.OpenWv(); +#endif + } + public void SetPadding(float left, float top, float right, float bottom) + { + // Debug.Log("[WebviewManager] SetPadding"); +#if UNITY_IOS && !UNITY_EDITOR + BrigdeIOS.SetPadding(left, top, right, bottom); +#endif + } + public void SetDarkThough(bool though) + { +#if UNITY_IOS && !UNITY_EDITOR + BrigdeIOS.SetDarkThough(though); +#endif + } + public void SetBtn(int left, int top, int right, int bottom) + { + // Debug.Log("[WebviewManager] SetBtn"); +#if UNITY_IOS && !UNITY_EDITOR + BrigdeIOS.SetBtn(left, top, right, bottom); +#endif + } + 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) + { +#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 + } + public void ShowH5View(bool flag) + { + // Debug.Log("[WebviewManager] SetCTEnable"); +#if UNITY_IOS && !UNITY_EDITOR + BrigdeIOS.ShowH5View(flag); +#endif + } + + public void SetIconProgress(float val) + { + // Debug.Log("[WebviewManager] SetCTEnable"); +#if UNITY_IOS && !UNITY_EDITOR + BrigdeIOS.SetIconProgress(val); +#endif + } + public void ShowFlyBtn(bool flag) + { + // Debug.Log("[WebviewManager] SetCTEnable"); +#if UNITY_IOS && !UNITY_EDITOR + BrigdeIOS.ShowFlyBtn(flag); +#endif + } + + public void setFlyBtnTag(bool flag) + { + // Debug.Log($"[WebviewManager] setFlyBtnTag ---{flag}"); +#if UNITY_IOS && !UNITY_EDITOR + BrigdeIOS.setFlyBtnTag(flag); +#endif + } + + public void setRewardBtnTag(bool flag) + { + // Debug.Log($"[WebviewManager] setRewardBtnTag--- {flag}"); +#if UNITY_IOS && !UNITY_EDITOR + BrigdeIOS.setRewardBtnTag(flag); +#endif + } + public void ObjC_TouchClick(string name) + { + // Debug.Log("Touch click: " + name); + GameDispatcher.Instance.Dispatch(GameMsg.H5ViewClickBtn, name); + } + public void H5AutoRefresh(string string_xcode) + { + if (string_xcode.Contains("|h5")) + { + string[] _string_arr = string_xcode.Split("|"); + if (_string_arr.Length >= 2) + { + for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count; i++) + { + 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; + } + } + H5sendClass info = new H5sendClass() { link = _string_arr[0], type = "h5" }; + NetworkKit_sdk.PostWithHeader("event/h5Impressions", info, (isSuccess, obj) => + { + if (isSuccess) + { + Debug.Log("发送成功" + _string_arr[0]); + + } + }); + } + } + else if (string_xcode.Contains("|h6")) + { + + string[] _string_arr = string_xcode.Split("|"); + if (_string_arr.Length >= 2) + { + for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count; i++) + { + 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; + } + } + } + + H5sendClass info = new H5sendClass() { link = _string_arr[0], type = "h6" }; + NetworkKit_sdk.PostWithHeader("event/h5Impressions", info, (isSuccess, obj) => + { + if (isSuccess) + { + Debug.Log("发送成功" + _string_arr[0]); + + } + }); + } + } + } + + + + private GList select_glist; + private float select_glist_y; + public void TouchClickPoint(string name) + { + // 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); + + } + + if (name == "rewardBtn") + { + NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_ct_number, 1); + //NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior,BuriedPointEvent.annular_ct_people,1); + } + + if (name == "finish") + { + NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_finish_number, 1); + } + } + List light_restoredList; + List> dark_restoredList; + public void RefreshUrl() + { + + string Dailyrefresh_reamain = ""; + int last_time = PlayerPrefs.GetInt("Dayreftimes", 0); + DateTime today = DateTime.Now; + int newDays = today.Day; + + string light_refresh_str = PlayerPrefs.GetString("Dailyrefreshnum", ""); + + if (string.IsNullOrEmpty(light_refresh_str)) + { + light_restoredList = new List(); + } + else + { + light_restoredList = light_refresh_str.Split(',').Select(int.Parse).ToList(); + } + + if (light_restoredList.Count < ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count) + { + int targetCount = ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count; + + for (int i = light_restoredList.Count; i < targetCount; i++) + { + light_restoredList.Add(0); + } + } + + if (last_time == newDays) + { + + } + else + { + + 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); + } + + int dark_last_time = PlayerPrefs.GetInt("dark_refreshDay", 0); + + + string darkWVDailyrefreshtimes_str = ""; + + string dark_refresh_str = PlayerPrefs.GetString("Darkrefreshnum", ""); + if (string.IsNullOrEmpty(dark_refresh_str)) + { + dark_restoredList = new List>(); + } + else + { + dark_restoredList = dark_refresh_str.Split(';').Select(row => row.Split(',').Select(int.Parse).ToList()).ToList(); + } + + + if (dark_restoredList.Count < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count) + { + int targetCount = ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count; + + for (int i = dark_restoredList.Count; i < targetCount; i++) + { + dark_restoredList.Add(new List()); + } + } + + for (int i = 0; i < dark_restoredList.Count; i++) + { + if (ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count > i) + { + 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); + } + } + } + } + + + + if (dark_last_time == newDays) + { + } + 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; + } + } + + PlayerPrefs.SetInt("dark_refreshDay", newDays); + PlayerPrefs.SetString("Darkrefreshnum", string.Join(";", dark_restoredList.Select(row => string.Join(",", row)))); + } + + string light_str = ""; + string dark_str = ""; + int can_refresh_numbners = 0; + for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count; i++) + { + if (i != 0) + { + light_str += "|"; + } + 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]); + } + + for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count; i++) + { + + 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; + } + } + + + + + string darkWVRefreshtime_str = ""; + + 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 += "|"; + } + + darkWVRefreshtime_str += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].f5Interval.min; + darkWVRefreshtime_str += "|"; + darkWVRefreshtime_str += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].f5Interval.max; + + add_time += UnityEngine.Random.Range(ConfigSystem_sdk.Instance.SDKConfig.h6Conf.ADClickF5Delay.min, ConfigSystem_sdk.Instance.SDKConfig.h6Conf.ADClickF5Delay.max + 1); + + layer_click_probability += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].weight; + } + Debug.Log("|||||||||||||||||||||--------------------------------"); + + + Debug.Log(darkWVRefreshtime_str); + + Debug.Log(dark_str); + Debug.Log(light_str); + Debug.Log(layer_click_probability); + Debug.Log(add_time); + int reg_days = ConfigSystem_sdk.Instance.GetRegisteredCalendarDaysByUTC(LoginModel_sdk.Instance.reg_time); + bool open_dark_wv = true; + if (ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition != null) + { + for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition.retentionConf.Count; i++) + { + if ((reg_days >= ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition.retentionConf[i].days.min) && + (reg_days <= ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition.retentionConf[i].days.max)) + { + if (UnityEngine.Random.Range(0, 100) >= ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition.retentionConf[i].prob) + { + open_dark_wv = false; + } + break; + } + } + } + Debug.Log(open_dark_wv); + + addH5Field(ConfigSystem.GetConfig().flyCtRate, ConfigSystem.GetConfig().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, open_dark_wv, layer_click_probability, add_time); + + } + } +} diff --git a/Assets/Scripts/Roy/newweb/SdkManager.cs.meta b/Assets/Scripts/Roy/newweb/SdkManager.cs.meta new file mode 100644 index 0000000..228b7b3 --- /dev/null +++ b/Assets/Scripts/Roy/newweb/SdkManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f320161c7337dbf46989861b4ea8d8b9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/TwistNode.cs b/Assets/Scripts/TwistNode.cs index 295edc8..147d359 100644 --- a/Assets/Scripts/TwistNode.cs +++ b/Assets/Scripts/TwistNode.cs @@ -26,7 +26,7 @@ namespace DontConfuse string[] a = str.Split("##"); if (a.Length >= 2) { - WebviewManager.Instance.TouchClickPoint(a[0] + "|" + a[1]); + // WebviewManager.Instance.TouchClickPoint(a[0] + "|" + a[1]); } }