Skip to content

Commit a29fa36

Browse files
committed
updated binaries.
1 parent 99caa99 commit a29fa36

16 files changed

+368
-8
lines changed
Binary file not shown.
Binary file not shown.

dist/package-nofragment/Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs

Lines changed: 152 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
9393
}
9494
}
9595
changed = (androidManifest.SetExported(true) || changed);
96+
changed = (androidManifest.SetApplicationTheme("@style/UnityThemeSelector") || changed);
97+
changed = (androidManifest.SetActivityTheme("@style/UnityThemeSelector.Translucent") || changed);
9698
changed = (androidManifest.SetWindowSoftInputMode("adjustPan") || changed);
9799
changed = (androidManifest.SetHardwareAccelerated(true) || changed);
98100
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
@@ -105,6 +107,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
105107
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
106108
changed = (androidManifest.AddMicrophone() || changed);
107109
#endif
110+
//#if UNITY_5_6_0 || UNITY_5_6_1
111+
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
112+
//#endif
108113
if (changed) {
109114
androidManifest.Save();
110115
Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
@@ -205,9 +210,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
205210
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
206211
changed = (androidManifest.AddMicrophone() || changed);
207212
#endif
208-
#if UNITY_5_6_0 || UNITY_5_6_1
213+
//#if UNITY_5_6_0 || UNITY_5_6_1
209214
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
210-
#endif
215+
//#endif
211216
if (changed) {
212217
androidManifest.Save();
213218
Debug.LogError("unitywebview: adjusted AndroidManifest.xml and/or WebView.aar. Please rebuild the app.");
@@ -269,6 +274,132 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
269274
dst = (string)method.Invoke(proj, null);
270275
}
271276
File.WriteAllText(projPath, dst);
277+
278+
// Classes/UI/UnityAppController+ViewHandling.mm
279+
{
280+
var text = File.ReadAllText(path + "/Classes/UI/UnityAppController+ViewHandling.mm");
281+
text = text.Replace(
282+
@"
283+
_rootController.view = _rootView = _unityView;
284+
",
285+
@"
286+
UIView *view = [[UIView alloc] initWithFrame:controller.view.bounds];
287+
[view addSubview:_unityView];
288+
_rootController.view = _rootView = view;
289+
");
290+
File.WriteAllText(path + "/Classes/UI/UnityAppController+ViewHandling.mm", text);
291+
}
292+
// Classes/UI/UnityView.h
293+
{
294+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.h").Split('\n');
295+
var lines = new List<string>();
296+
var phase = 0;
297+
foreach (var line in lines0) {
298+
switch (phase) {
299+
case 0:
300+
lines.Add(line);
301+
if (line.StartsWith("@interface UnityView : UnityRenderingView")) {
302+
phase++;
303+
}
304+
break;
305+
case 1:
306+
lines.Add(line);
307+
if (line.StartsWith("}")) {
308+
phase++;
309+
lines.Add("");
310+
lines.Add("- (void)clearMasks;");
311+
lines.Add("- (void)addMask:(CGRect)r;");
312+
}
313+
break;
314+
default:
315+
lines.Add(line);
316+
break;
317+
}
318+
}
319+
File.WriteAllText(path + "/Classes/UI/UnityView.h", string.Join("\n", lines));
320+
}
321+
// Classes/UI/UnityView.mm
322+
{
323+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.mm").Split('\n');
324+
var lines = new List<string>();
325+
var phase = 0;
326+
foreach (var line in lines0) {
327+
switch (phase) {
328+
case 0:
329+
lines.Add(line);
330+
if (line.StartsWith("@implementation UnityView")) {
331+
phase++;
332+
}
333+
break;
334+
case 1:
335+
if (line.StartsWith("}")) {
336+
phase++;
337+
lines.Add(" NSMutableArray<NSValue *> *_masks;");
338+
lines.Add(line);
339+
lines.Add(@"
340+
- (void)clearMasks
341+
{
342+
if (_masks == nil) {
343+
_masks = [[NSMutableArray<NSValue *> alloc] init];
344+
}
345+
[_masks removeAllObjects];
346+
}
347+
348+
- (void)addMask:(CGRect)r
349+
{
350+
if (_masks == nil) {
351+
_masks = [[NSMutableArray<NSValue *> alloc] init];
352+
}
353+
[_masks addObject:[NSValue valueWithCGRect:r]];
354+
}
355+
356+
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
357+
{
358+
//CGRect mask = CGRectMake(0, 0, 1334, 100);
359+
//return CGRectContainsPoint(mask, point);
360+
for (NSValue *v in _masks) {
361+
if (CGRectContainsPoint([v CGRectValue], point)) {
362+
return TRUE;
363+
}
364+
}
365+
return FALSE;
366+
}
367+
");
368+
} else {
369+
lines.Add(line);
370+
}
371+
break;
372+
default:
373+
lines.Add(line);
374+
break;
375+
}
376+
}
377+
lines.Add(@"
378+
extern ""C"" {
379+
UIView *UnityGetGLView();
380+
void CWebViewPlugin_ClearMasks();
381+
void CWebViewPlugin_AddMask(int x, int y, int w, int h);
382+
}
383+
384+
void CWebViewPlugin_ClearMasks()
385+
{
386+
[(UnityView *)UnityGetGLView() clearMasks];
387+
}
388+
389+
void CWebViewPlugin_AddMask(int x, int y, int w, int h)
390+
{
391+
UIView *view = UnityGetGLViewController().view;
392+
CGFloat scale = 1.0f;
393+
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
394+
scale = view.window.screen.nativeScale;
395+
} else {
396+
scale = view.contentScaleFactor;
397+
}
398+
[(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)];
399+
}
400+
");
401+
File.WriteAllText(path + "/Classes/UI/UnityView.mm", string.Join("\n", lines));
402+
}
272403
}
273404
}
274405
}
@@ -345,6 +476,25 @@ internal bool SetExported(bool enabled) {
345476
return changed;
346477
}
347478

479+
internal bool SetApplicationTheme(string theme) {
480+
bool changed = false;
481+
if (ApplicationElement.GetAttribute("theme", AndroidXmlNamespace) != theme) {
482+
ApplicationElement.SetAttribute("theme", AndroidXmlNamespace, theme);
483+
changed = true;
484+
}
485+
return changed;
486+
}
487+
488+
internal bool SetActivityTheme(string theme) {
489+
bool changed = false;
490+
var activity = GetActivityWithLaunchIntent() as XmlElement;
491+
if (activity.GetAttribute("theme", AndroidXmlNamespace) != theme) {
492+
activity.SetAttribute("theme", AndroidXmlNamespace, theme);
493+
changed = true;
494+
}
495+
return changed;
496+
}
497+
348498
internal bool SetWindowSoftInputMode(string mode) {
349499
bool changed = false;
350500
var activity = GetActivityWithLaunchIntent() as XmlElement;

dist/package-nofragment/Assets/Plugins/WebViewObject.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ private static extern void _CWebViewPlugin_Reload(
500500
[DllImport("WebView")]
501501
private static extern string _CWebViewPlugin_GetMessage(IntPtr instance);
502502
#elif UNITY_IPHONE
503+
[DllImport("__Internal")]
504+
private static extern void CWebViewPlugin_ClearMasks();
505+
[DllImport("__Internal")]
506+
private static extern void CWebViewPlugin_AddMask(int x, int y, int w, int h);
503507
[DllImport("__Internal")]
504508
private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, bool zoom, string ua, bool enableWKWebView, int wkContentMode, bool wkAllowsLinkPreview, bool wkAllowsBackForwardNavigationGestures, int radius);
505509
[DllImport("__Internal")]
@@ -599,6 +603,32 @@ public static bool IsWebViewAvailable()
599603
#endif
600604
}
601605

606+
public static void ClearMasks()
607+
{
608+
#if !UNITY_EDITOR && UNITY_ANDROID
609+
using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
610+
{
611+
var activity = UnityClass.GetStatic<AndroidJavaObject>("currentActivity");
612+
activity.Call("clearMasks");
613+
}
614+
#elif !UNITY_EDITOR && UNITY_IPHONE
615+
CWebViewPlugin_ClearMasks();
616+
#endif
617+
}
618+
619+
public static void AddMask(int x, int y, int w, int h)
620+
{
621+
#if !UNITY_EDITOR && UNITY_ANDROID
622+
using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
623+
{
624+
var activity = UnityClass.GetStatic<AndroidJavaObject>("currentActivity");
625+
activity.Call("addMask", x, y, w, h);
626+
}
627+
#elif !UNITY_EDITOR && UNITY_IPHONE
628+
CWebViewPlugin_AddMask(x, y, w, h);
629+
#endif
630+
}
631+
602632
public void Init(
603633
Callback cb = null,
604634
Callback err = null,

dist/package-nofragment/Assets/Plugins/iOS/WebView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra
260260

261261
[webView addObserver:self forKeyPath: @"loading" options: NSKeyValueObservingOptionNew context:nil];
262262

263-
[view addSubview:webView];
263+
[view insertSubview:webView atIndex:0];
264264

265265
return self;
266266
}

dist/package-nofragment/Assets/Plugins/iOS/WebViewWithUIWebView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra
320320

321321
[webView addObserver:self forKeyPath: @"loading" options: NSKeyValueObservingOptionNew context:nil];
322322

323-
[view addSubview:webView];
323+
[view insertSubview:webView atIndex:0];
324324

325325
return self;
326326
}
Binary file not shown.
952 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)