Skip to content

Commit 1bf649e

Browse files
committed
updated binaries.
1 parent 37036ed commit 1bf649e

14 files changed

+340
-8
lines changed
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.SetHardwareAccelerated(true) || changed);
8082
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
8183
changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
@@ -87,6 +89,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
8789
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
8890
changed = (androidManifest.AddMicrophone() || changed);
8991
#endif
92+
//#if UNITY_5_6_0 || UNITY_5_6_1
93+
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
94+
//#endif
9095
if (changed) {
9196
androidManifest.Save();
9297
Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
@@ -174,9 +179,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
174179
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
175180
changed = (androidManifest.AddMicrophone() || changed);
176181
#endif
177-
#if UNITY_5_6_0 || UNITY_5_6_1
182+
//#if UNITY_5_6_0 || UNITY_5_6_1
178183
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
179-
#endif
184+
//#endif
180185
if (changed) {
181186
androidManifest.Save();
182187
Debug.LogError("unitywebview: adjusted AndroidManifest.xml. Please rebuild the app.");
@@ -238,6 +243,118 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
238243
dst = (string)method.Invoke(proj, null);
239244
}
240245
File.WriteAllText(projPath, dst);
246+
247+
// Classes/UI/UnityView.h
248+
{
249+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.h").Split('\n');
250+
var lines = new List<string>();
251+
var phase = 0;
252+
foreach (var line in lines0) {
253+
switch (phase) {
254+
case 0:
255+
lines.Add(line);
256+
if (line.StartsWith("@interface UnityView : UnityRenderingView")) {
257+
phase++;
258+
}
259+
break;
260+
case 1:
261+
lines.Add(line);
262+
if (line.StartsWith("}")) {
263+
phase++;
264+
lines.Add("");
265+
lines.Add("- (void)clearMasks;");
266+
lines.Add("- (void)addMask:(CGRect)r;");
267+
}
268+
break;
269+
default:
270+
lines.Add(line);
271+
break;
272+
}
273+
}
274+
File.WriteAllText(path + "/Classes/UI/UnityView.h", string.Join("\n", lines));
275+
}
276+
// Classes/UI/UnityView.mm
277+
{
278+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.mm").Split('\n');
279+
var lines = new List<string>();
280+
var phase = 0;
281+
foreach (var line in lines0) {
282+
switch (phase) {
283+
case 0:
284+
lines.Add(line);
285+
if (line.StartsWith("@implementation UnityView")) {
286+
phase++;
287+
}
288+
break;
289+
case 1:
290+
if (line.StartsWith("}")) {
291+
phase++;
292+
lines.Add(" NSMutableArray<NSValue *> *_masks;");
293+
lines.Add(line);
294+
lines.Add(@"
295+
- (void)clearMasks
296+
{
297+
if (_masks == nil) {
298+
_masks = [[NSMutableArray<NSValue *> alloc] init];
299+
}
300+
[_masks removeAllObjects];
301+
}
302+
303+
- (void)addMask:(CGRect)r
304+
{
305+
if (_masks == nil) {
306+
_masks = [[NSMutableArray<NSValue *> alloc] init];
307+
}
308+
[_masks addObject:[NSValue valueWithCGRect:r]];
309+
}
310+
311+
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
312+
{
313+
//CGRect mask = CGRectMake(0, 0, 1334, 100);
314+
//return CGRectContainsPoint(mask, point);
315+
for (NSValue *v in _masks) {
316+
if (CGRectContainsPoint([v CGRectValue], point)) {
317+
return TRUE;
318+
}
319+
}
320+
return FALSE;
321+
}
322+
");
323+
} else {
324+
lines.Add(line);
325+
}
326+
break;
327+
default:
328+
lines.Add(line);
329+
break;
330+
}
331+
}
332+
lines.Add(@"
333+
extern ""C"" {
334+
UIView *UnityGetGLView();
335+
void CWebViewPlugin_ClearMasks();
336+
void CWebViewPlugin_AddMask(int x, int y, int w, int h);
337+
}
338+
339+
void CWebViewPlugin_ClearMasks()
340+
{
341+
[(UnityView *)UnityGetGLView() clearMasks];
342+
}
343+
344+
void CWebViewPlugin_AddMask(int x, int y, int w, int h)
345+
{
346+
UIView *view = UnityGetGLViewController().view;
347+
CGFloat scale = 1.0f;
348+
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
349+
scale = view.window.screen.nativeScale;
350+
} else {
351+
scale = view.contentScaleFactor;
352+
}
353+
[(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)];
354+
}
355+
");
356+
File.WriteAllText(path + "/Classes/UI/UnityView.mm", string.Join("\n", lines));
357+
}
241358
}
242359
}
243360
}
@@ -314,6 +431,25 @@ internal bool SetExported(bool enabled) {
314431
return changed;
315432
}
316433

434+
internal bool SetApplicationTheme(string theme) {
435+
bool changed = false;
436+
if (ApplicationElement.GetAttribute("theme", AndroidXmlNamespace) != theme) {
437+
ApplicationElement.SetAttribute("theme", AndroidXmlNamespace, theme);
438+
changed = true;
439+
}
440+
return changed;
441+
}
442+
443+
internal bool SetActivityTheme(string theme) {
444+
bool changed = false;
445+
var activity = GetActivityWithLaunchIntent() as XmlElement;
446+
if (activity.GetAttribute("theme", AndroidXmlNamespace) != theme) {
447+
activity.SetAttribute("theme", AndroidXmlNamespace, theme);
448+
changed = true;
449+
}
450+
return changed;
451+
}
452+
317453
internal bool SetHardwareAccelerated(bool enabled) {
318454
bool changed = false;
319455
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
@@ -492,6 +492,10 @@ private static extern void _CWebViewPlugin_Reload(
492492
[DllImport("WebView")]
493493
private static extern string _CWebViewPlugin_GetMessage(IntPtr instance);
494494
#elif UNITY_IPHONE
495+
[DllImport("__Internal")]
496+
private static extern void CWebViewPlugin_ClearMasks();
497+
[DllImport("__Internal")]
498+
private static extern void CWebViewPlugin_AddMask(int x, int y, int w, int h);
495499
[DllImport("__Internal")]
496500
private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, bool zoom, string ua, bool enableWKWebView, int wkContentMode, bool wkAllowsLinkPreview, bool wkAllowsBackForwardNavigationGestures, int radius);
497501
[DllImport("__Internal")]
@@ -588,6 +592,32 @@ public static bool IsWebViewAvailable()
588592
#endif
589593
}
590594

595+
public static void ClearMasks()
596+
{
597+
#if !UNITY_EDITOR && UNITY_ANDROID
598+
using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
599+
{
600+
var activity = UnityClass.GetStatic<AndroidJavaObject>("currentActivity");
601+
activity.Call("clearMasks");
602+
}
603+
#elif !UNITY_EDITOR && UNITY_IPHONE
604+
CWebViewPlugin_ClearMasks();
605+
#endif
606+
}
607+
608+
public static void AddMask(int x, int y, int w, int h)
609+
{
610+
#if !UNITY_EDITOR && UNITY_ANDROID
611+
using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
612+
{
613+
var activity = UnityClass.GetStatic<AndroidJavaObject>("currentActivity");
614+
activity.Call("addMask", x, y, w, h);
615+
}
616+
#elif !UNITY_EDITOR && UNITY_IPHONE
617+
CWebViewPlugin_AddMask(x, y, w, h);
618+
#endif
619+
}
620+
591621
public void Init(
592622
Callback cb = null,
593623
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
}
Binary file not shown.

0 commit comments

Comments
 (0)