From 9f39e0cc62e8179efa54b8c1627f9f3ba48a792f Mon Sep 17 00:00:00 2001 From: edy Date: Mon, 13 Jul 2026 10:56:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9h5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Plugins/CustomView.m | 122 -------------- Assets/Scripts/Plugins/H5View.m | 236 +--------------------------- Assets/Scripts/Plugins/pluginIOs.mm | 2 +- 3 files changed, 3 insertions(+), 357 deletions(-) diff --git a/Assets/Scripts/Plugins/CustomView.m b/Assets/Scripts/Plugins/CustomView.m index bd4ac80..5f4249f 100644 --- a/Assets/Scripts/Plugins/CustomView.m +++ b/Assets/Scripts/Plugins/CustomView.m @@ -28,135 +28,13 @@ } -(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/Scripts/Plugins/H5View.m b/Assets/Scripts/Plugins/H5View.m index 203e1f3..b9d006a 100644 --- a/Assets/Scripts/Plugins/H5View.m +++ b/Assets/Scripts/Plugins/H5View.m @@ -6,7 +6,6 @@ // #import "H5View.h" -#import "CircularProgressBar.h" #import #import "CustomView.h" #import "UnityFramework.h" @@ -15,8 +14,7 @@ @implementation H5View{ NSMutableArray *webviews; - - CircularProgressBar* bar; //奖励按钮进度条 + //奖励按钮进度条 UIView * flyBtn; //飞行奖励按钮节点,也可以用UIButton但要屏蔽事件 UIImageView* flyBg; //飞行奖励闪光背景 UIImageView* rewardBtn; //奖励按钮节点 @@ -94,7 +92,6 @@ //初始化页面 -(void)initView{ if (inited)return; - [self initFlyBtn]; [self setHidden:YES]; //默认为隐藏状态 [self hideView]; canCheckTouch = true; @@ -280,7 +277,6 @@ [self showWebview:NullUrl]; //打开webview时url为上一次 [self ChangeViewRect:true]; - [self startFlyAnim]; //每一次显示时强行执行飞行按钮的动画 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { self .alpha=1; } @@ -289,7 +285,6 @@ //显示暗网页 -(void)hideView{ - [self stopUpdate]; if(!is_dark_mode){ @@ -622,124 +617,7 @@ UnitySendMessage("SdkManager", "UpdateNumbers",[[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; @@ -984,90 +857,7 @@ [self setHidden:!though]; } --(void)setViewBtn:(CGRect)rect{ - - - if(is_first_btn) return; - rewardBtn = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1"]]; - rewardBtn.frame = CGRectMake(self.bounds.size.width - rect.origin.x, rect.origin.y, 60, 60); - [self addSubview:rewardBtn]; - - //圈圈背景图 - UIImageView* fillBack = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"8"]]; - fillBack.frame = CGRectMake(0,0, rewardBtn.frame.size.width, rewardBtn.frame.size.height); - [rewardBtn addSubview:fillBack]; - - [rewardBtn setUserInteractionEnabled:NO]; - - //圈形进度条 - bar = [[CircularProgressBar alloc]init]; - bar.frame = CGRectMake(0,0, rewardBtn.frame.size.width, rewardBtn.frame.size.height); - bar.bounds = rewardBtn.bounds; - //bar.backgroundColor = UIColor.greenColor; - [bar updateUI]; - - [rewardBtn addSubview:bar]; - //[self setBackgroundColor:UIColor.orangeColor]; - - //icon图 - UIImageView* icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"30"]]; - icon.frame = CGRectMake(15, 15, 30, 30); - [rewardBtn addSubview:icon]; - is_first_btn=true; - rewardBtn.hidden=YES; - -} -//检测一个点是否在某个按钮里 --(void)checkPointInsideBtn:(CGPoint)point{ - //点是否在飞行按钮里 - //if(!self.isHidden) stopTouchTime=0; - if (!flyBtn.isHidden && CGRectContainsPoint(flyBtn.frame, point)){ - // NSLog(@"Inside flyBtn"); - //避免手指按下立马出发点击事件 - [self delayInvoke:0.2 cb:^(void){ - NSLog(@"Inside flyBtn"); - if(self->isShowFlyBtn) - { - 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{ @@ -1077,26 +867,6 @@ } //飞行按钮隐/藏 --(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{ @@ -1104,8 +874,6 @@ 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]; diff --git a/Assets/Scripts/Plugins/pluginIOs.mm b/Assets/Scripts/Plugins/pluginIOs.mm index 148ff39..55c0dbf 100644 --- a/Assets/Scripts/Plugins/pluginIOs.mm +++ b/Assets/Scripts/Plugins/pluginIOs.mm @@ -1,4 +1,4 @@ -#import + extern "C" { #include "H5View.h" NSString *stringFromChar(const char *input) {