Skip to content

Commit 72d5c14

Browse files
committed
updated binaries.
1 parent 494e8f1 commit 72d5c14

14 files changed

+340
-8
lines changed
927 Bytes
Binary file not shown.

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

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
7676
}
7777
}
7878
changed = (androidManifest.SetExported(true) || changed);
79+
changed = (androidManifest.SetApplicationTheme("@style/UnityThemeSelector") || changed);
80+
changed = (androidManifest.SetActivityTheme("@style/UnityThemeSelector.Translucent") || changed);
7981
changed = (androidManifest.SetWindowSoftInputMode("adjustPan") || changed);
8082
changed = (androidManifest.SetHardwareAccelerated(true) || changed);
8183
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
@@ -88,6 +90,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
8890
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
8991
changed = (androidManifest.AddMicrophone() || changed);
9092
#endif
93+
//#if UNITY_5_6_0 || UNITY_5_6_1
94+
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
95+
//#endif
9196
if (changed) {
9297
androidManifest.Save();
9398
Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
@@ -176,9 +181,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
176181
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
177182
changed = (androidManifest.AddMicrophone() || changed);
178183
#endif
179-
#if UNITY_5_6_0 || UNITY_5_6_1
184+
//#if UNITY_5_6_0 || UNITY_5_6_1
180185
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
181-
#endif
186+
//#endif
182187
if (changed) {
183188
androidManifest.Save();
184189
Debug.LogError("unitywebview: adjusted AndroidManifest.xml. Please rebuild the app.");
@@ -240,6 +245,118 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
240245
dst = (string)method.Invoke(proj, null);
241246
}
242247
File.WriteAllText(projPath, dst);
248+
249+
// Classes/UI/UnityView.h
250+
{
251+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.h").Split('\n');
252+
var lines = new List<string>();
253+
var phase = 0;
254+
foreach (var line in lines0) {
255+
switch (phase) {
256+
case 0:
257+
lines.Add(line);
258+
if (line.StartsWith("@interface UnityView : UnityRenderingView")) {
259+
phase++;
260+
}
261+
break;
262+
case 1:
263+
lines.Add(line);
264+
if (line.StartsWith("}")) {
265+
phase++;
266+
lines.Add("");
267+
lines.Add("- (void)clearMasks;");
268+
lines.Add("- (void)addMask:(CGRect)r;");
269+
}
270+
break;
271+
default:
272+
lines.Add(line);
273+
break;
274+
}
275+
}
276+
File.WriteAllText(path + "/Classes/UI/UnityView.h", string.Join("\n", lines));
277+
}
278+
// Classes/UI/UnityView.mm
279+
{
280+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.mm").Split('\n');
281+
var lines = new List<string>();
282+
var phase = 0;
283+
foreach (var line in lines0) {
284+
switch (phase) {
285+
case 0:
286+
lines.Add(line);
287+
if (line.StartsWith("@implementation UnityView")) {
288+
phase++;
289+
}
290+
break;
291+
case 1:
292+
if (line.StartsWith("}")) {
293+
phase++;
294+
lines.Add(" NSMutableArray<NSValue *> *_masks;");
295+
lines.Add(line);
296+
lines.Add(@"
297+
- (void)clearMasks
298+
{
299+
if (_masks == nil) {
300+
_masks = [[NSMutableArray<NSValue *> alloc] init];
301+
}
302+
[_masks removeAllObjects];
303+
}
304+
305+
- (void)addMask:(CGRect)r
306+
{
307+
if (_masks == nil) {
308+
_masks = [[NSMutableArray<NSValue *> alloc] init];
309+
}
310+
[_masks addObject:[NSValue valueWithCGRect:r]];
311+
}
312+
313+
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
314+
{
315+
//CGRect mask = CGRectMake(0, 0, 1334, 100);
316+
//return CGRectContainsPoint(mask, point);
317+
for (NSValue *v in _masks) {
318+
if (CGRectContainsPoint([v CGRectValue], point)) {
319+
return TRUE;
320+
}
321+
}
322+
return FALSE;
323+
}
324+
");
325+
} else {
326+
lines.Add(line);
327+
}
328+
break;
329+
default:
330+
lines.Add(line);
331+
break;
332+
}
333+
}
334+
lines.Add(@"
335+
extern ""C"" {
336+
UIView *UnityGetGLView();
337+
void CWebViewPlugin_ClearMasks();
338+
void CWebViewPlugin_AddMask(int x, int y, int w, int h);
339+
}
340+
341+
void CWebViewPlugin_ClearMasks()
342+
{
343+
[(UnityView *)UnityGetGLView() clearMasks];
344+
}
345+
346+
void CWebViewPlugin_AddMask(int x, int y, int w, int h)
347+
{
348+
UIView *view = UnityGetGLViewController().view;
349+
CGFloat scale = 1.0f;
350+
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
351+
scale = view.window.screen.nativeScale;
352+
} else {
353+
scale = view.contentScaleFactor;
354+
}
355+
[(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)];
356+
}
357+
");
358+
File.WriteAllText(path + "/Classes/UI/UnityView.mm", string.Join("\n", lines));
359+
}
243360
}
244361
}
245362
}
@@ -316,6 +433,25 @@ internal bool SetExported(bool enabled) {
316433
return changed;
317434
}
318435

436+
internal bool SetApplicationTheme(string theme) {
437+
bool changed = false;
438+
if (ApplicationElement.GetAttribute("theme", AndroidXmlNamespace) != theme) {
439+
ApplicationElement.SetAttribute("theme", AndroidXmlNamespace, theme);
440+
changed = true;
441+
}
442+
return changed;
443+
}
444+
445+
internal bool SetActivityTheme(string theme) {
446+
bool changed = false;
447+
var activity = GetActivityWithLaunchIntent() as XmlElement;
448+
if (activity.GetAttribute("theme", AndroidXmlNamespace) != theme) {
449+
activity.SetAttribute("theme", AndroidXmlNamespace, theme);
450+
changed = true;
451+
}
452+
return changed;
453+
}
454+
319455
internal bool SetWindowSoftInputMode(string mode) {
320456
bool changed = false;
321457
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.superview 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.superview insertSubview:webView atIndex:0];
324324

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

0 commit comments

Comments
 (0)