Skip to content

Commit a9dfeb0

Browse files
committed
updated binaries.
1 parent a7339e4 commit a9dfeb0

16 files changed

Lines changed: 370 additions & 8 deletions
Binary file not shown.
Binary file not shown.

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

Lines changed: 153 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,133 @@ 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.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
288+
[view addSubview:_unityView];
289+
_rootController.view = _rootView = view;
290+
");
291+
File.WriteAllText(path + "/Classes/UI/UnityAppController+ViewHandling.mm", text);
292+
}
293+
// Classes/UI/UnityView.h
294+
{
295+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.h").Split('\n');
296+
var lines = new List<string>();
297+
var phase = 0;
298+
foreach (var line in lines0) {
299+
switch (phase) {
300+
case 0:
301+
lines.Add(line);
302+
if (line.StartsWith("@interface UnityView : UnityRenderingView")) {
303+
phase++;
304+
}
305+
break;
306+
case 1:
307+
lines.Add(line);
308+
if (line.StartsWith("}")) {
309+
phase++;
310+
lines.Add("");
311+
lines.Add("- (void)clearMasks;");
312+
lines.Add("- (void)addMask:(CGRect)r;");
313+
}
314+
break;
315+
default:
316+
lines.Add(line);
317+
break;
318+
}
319+
}
320+
File.WriteAllText(path + "/Classes/UI/UnityView.h", string.Join("\n", lines));
321+
}
322+
// Classes/UI/UnityView.mm
323+
{
324+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.mm").Split('\n');
325+
var lines = new List<string>();
326+
var phase = 0;
327+
foreach (var line in lines0) {
328+
switch (phase) {
329+
case 0:
330+
lines.Add(line);
331+
if (line.StartsWith("@implementation UnityView")) {
332+
phase++;
333+
}
334+
break;
335+
case 1:
336+
if (line.StartsWith("}")) {
337+
phase++;
338+
lines.Add(" NSMutableArray<NSValue *> *_masks;");
339+
lines.Add(line);
340+
lines.Add(@"
341+
- (void)clearMasks
342+
{
343+
if (_masks == nil) {
344+
_masks = [[NSMutableArray<NSValue *> alloc] init];
345+
}
346+
[_masks removeAllObjects];
347+
}
348+
349+
- (void)addMask:(CGRect)r
350+
{
351+
if (_masks == nil) {
352+
_masks = [[NSMutableArray<NSValue *> alloc] init];
353+
}
354+
[_masks addObject:[NSValue valueWithCGRect:r]];
355+
}
356+
357+
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
358+
{
359+
//CGRect mask = CGRectMake(0, 0, 1334, 100);
360+
//return CGRectContainsPoint(mask, point);
361+
for (NSValue *v in _masks) {
362+
if (CGRectContainsPoint([v CGRectValue], point)) {
363+
return TRUE;
364+
}
365+
}
366+
return FALSE;
367+
}
368+
");
369+
} else {
370+
lines.Add(line);
371+
}
372+
break;
373+
default:
374+
lines.Add(line);
375+
break;
376+
}
377+
}
378+
lines.Add(@"
379+
extern ""C"" {
380+
UIView *UnityGetGLView();
381+
void CWebViewPlugin_ClearMasks();
382+
void CWebViewPlugin_AddMask(int x, int y, int w, int h);
383+
}
384+
385+
void CWebViewPlugin_ClearMasks()
386+
{
387+
[(UnityView *)UnityGetGLView() clearMasks];
388+
}
389+
390+
void CWebViewPlugin_AddMask(int x, int y, int w, int h)
391+
{
392+
UIView *view = UnityGetGLViewController().view;
393+
CGFloat scale = 1.0f;
394+
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
395+
scale = view.window.screen.nativeScale;
396+
} else {
397+
scale = view.contentScaleFactor;
398+
}
399+
[(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)];
400+
}
401+
");
402+
File.WriteAllText(path + "/Classes/UI/UnityView.mm", string.Join("\n", lines));
403+
}
272404
}
273405
}
274406
}
@@ -345,6 +477,25 @@ internal bool SetExported(bool enabled) {
345477
return changed;
346478
}
347479

480+
internal bool SetApplicationTheme(string theme) {
481+
bool changed = false;
482+
if (ApplicationElement.GetAttribute("theme", AndroidXmlNamespace) != theme) {
483+
ApplicationElement.SetAttribute("theme", AndroidXmlNamespace, theme);
484+
changed = true;
485+
}
486+
return changed;
487+
}
488+
489+
internal bool SetActivityTheme(string theme) {
490+
bool changed = false;
491+
var activity = GetActivityWithLaunchIntent() as XmlElement;
492+
if (activity.GetAttribute("theme", AndroidXmlNamespace) != theme) {
493+
activity.SetAttribute("theme", AndroidXmlNamespace, theme);
494+
changed = true;
495+
}
496+
return changed;
497+
}
498+
348499
internal bool SetWindowSoftInputMode(string mode) {
349500
bool changed = false;
350501
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)