Skip to content

Commit 2299112

Browse files
committed
updated binaries.
1 parent 0a1882c commit 2299112

14 files changed

+326
-8
lines changed
427 Bytes
Binary file not shown.

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

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
7575
}
7676
}
7777
}
78+
changed = (androidManifest.SetApplicationTheme("@style/UnityThemeSelector") || changed);
79+
changed = (androidManifest.SetActivityTheme("@style/UnityThemeSelector.Translucent") || changed);
7880
changed = (androidManifest.SetHardwareAccelerated(true) || changed);
7981
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
8082
changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
@@ -86,6 +88,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
8688
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
8789
changed = (androidManifest.AddMicrophone() || changed);
8890
#endif
91+
//#if UNITY_5_6_0 || UNITY_5_6_1
92+
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
93+
//#endif
8994
if (changed) {
9095
androidManifest.Save();
9196
Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
@@ -173,9 +178,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
173178
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
174179
changed = (androidManifest.AddMicrophone() || changed);
175180
#endif
176-
#if UNITY_5_6_0 || UNITY_5_6_1
181+
//#if UNITY_5_6_0 || UNITY_5_6_1
177182
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
178-
#endif
183+
//#endif
179184
if (changed) {
180185
androidManifest.Save();
181186
Debug.LogError("unitywebview: adjusted AndroidManifest.xml. Please rebuild the app.");
@@ -237,6 +242,111 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
237242
dst = (string)method.Invoke(proj, null);
238243
}
239244
File.WriteAllText(projPath, dst);
245+
246+
// Classes/UI/UnityView.h
247+
{
248+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.h").Split('\n');
249+
var lines = new List<string>();
250+
var phase = 0;
251+
foreach (var line in lines0) {
252+
switch (phase) {
253+
case 0:
254+
lines.Add(line);
255+
if (line.StartsWith("@interface UnityView : UnityRenderingView")) {
256+
phase++;
257+
}
258+
break;
259+
case 1:
260+
lines.Add(line);
261+
if (line.StartsWith("}")) {
262+
phase++;
263+
lines.Add("");
264+
lines.Add("- (void)clearMasks;");
265+
lines.Add("- (void)addMask:(CGRect)r;");
266+
}
267+
break;
268+
default:
269+
lines.Add(line);
270+
break;
271+
}
272+
}
273+
File.WriteAllText(path + "/Classes/UI/UnityView.h", string.Join("\n", lines));
274+
}
275+
// Classes/UI/UnityView.mm
276+
{
277+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.mm").Split('\n');
278+
var lines = new List<string>();
279+
var phase = 0;
280+
foreach (var line in lines0) {
281+
switch (phase) {
282+
case 0:
283+
lines.Add(line);
284+
if (line.StartsWith("@implementation UnityView")) {
285+
phase++;
286+
}
287+
break;
288+
case 1:
289+
if (line.StartsWith("}")) {
290+
phase++;
291+
lines.Add(" NSMutableArray<NSValue *> *_masks;");
292+
lines.Add(line);
293+
lines.Add(@"
294+
- (void)clearMasks
295+
{
296+
if (_masks == nil) {
297+
_masks = [[NSMutableArray<NSValue *> alloc] init];
298+
}
299+
[_masks removeAllObjects];
300+
}
301+
302+
- (void)addMask:(CGRect)r
303+
{
304+
if (_masks == nil) {
305+
_masks = [[NSMutableArray<NSValue *> alloc] init];
306+
}
307+
[_masks addObject:[NSValue valueWithCGRect:r]];
308+
}
309+
310+
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
311+
{
312+
//CGRect mask = CGRectMake(0, 0, 1334, 100);
313+
//return CGRectContainsPoint(mask, point);
314+
for (NSValue *v in _masks) {
315+
if (CGRectContainsPoint([v CGRectValue], point)) {
316+
return TRUE;
317+
}
318+
}
319+
return FALSE;
320+
}
321+
");
322+
} else {
323+
lines.Add(line);
324+
}
325+
break;
326+
default:
327+
lines.Add(line);
328+
break;
329+
}
330+
}
331+
lines.Add(@"
332+
extern ""C"" {
333+
UIView *UnityGetGLView();
334+
void CWebViewPlugin_ClearMasks();
335+
void CWebViewPlugin_AddMask(int x, int y, int w, int h);
336+
}
337+
338+
void CWebViewPlugin_ClearMasks()
339+
{
340+
[(UnityView *)UnityGetGLView() clearMasks];
341+
}
342+
343+
void CWebViewPlugin_AddMask(int x, int y, int w, int h)
344+
{
345+
[(UnityView *)UnityGetGLView() addMask:CGRectMake(x, y, x + w, y + h)];
346+
}
347+
");
348+
File.WriteAllText(path + "/Classes/UI/UnityView.mm", string.Join("\n", lines));
349+
}
240350
}
241351
}
242352
}
@@ -302,6 +412,25 @@ internal bool SetUsesCleartextTraffic(bool enabled) {
302412
return changed;
303413
}
304414

415+
internal bool SetApplicationTheme(string theme) {
416+
bool changed = false;
417+
if (ApplicationElement.GetAttribute("theme", AndroidXmlNamespace) != theme) {
418+
ApplicationElement.SetAttribute("theme", AndroidXmlNamespace, theme);
419+
changed = true;
420+
}
421+
return changed;
422+
}
423+
424+
internal bool SetActivityTheme(string theme) {
425+
bool changed = false;
426+
var activity = GetActivityWithLaunchIntent() as XmlElement;
427+
if (activity.GetAttribute("theme", AndroidXmlNamespace) != theme) {
428+
activity.SetAttribute("theme", AndroidXmlNamespace, theme);
429+
changed = true;
430+
}
431+
return changed;
432+
}
433+
305434
internal bool SetHardwareAccelerated(bool enabled) {
306435
bool changed = false;
307436
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
@@ -447,6 +447,10 @@ private static extern void _CWebViewPlugin_Reload(
447447
[DllImport("WebView")]
448448
private static extern string _CWebViewPlugin_GetMessage(IntPtr instance);
449449
#elif UNITY_IPHONE
450+
[DllImport("__Internal")]
451+
private static extern void CWebViewPlugin_ClearMasks();
452+
[DllImport("__Internal")]
453+
private static extern void CWebViewPlugin_AddMask(int x, int y, int w, int h);
450454
[DllImport("__Internal")]
451455
private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, bool zoom, string ua, bool enableWKWebView, int wkContentMode, bool wkAllowsLinkPreview, bool wkAllowsBackForwardNavigationGestures, int radius);
452456
[DllImport("__Internal")]
@@ -543,6 +547,32 @@ public static bool IsWebViewAvailable()
543547
#endif
544548
}
545549

550+
public void ClearMasks()
551+
{
552+
#if !UNITY_EDITOR && UNITY_ANDROID
553+
using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
554+
{
555+
var activity = UnityClass.GetStatic<AndroidJavaObject>("currentActivity");
556+
activity.Call("clearMasks");
557+
}
558+
#elif !UNITY_EDITOR && UNITY_IPHONE
559+
CWebViewPlugin_ClearMasks();
560+
#endif
561+
}
562+
563+
public void AddMask(int x, int y, int w, int h)
564+
{
565+
#if !UNITY_EDITOR && UNITY_ANDROID
566+
using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
567+
{
568+
var activity = UnityClass.GetStatic<AndroidJavaObject>("currentActivity");
569+
activity.Call("addMask", x, y, w, h);
570+
}
571+
#elif !UNITY_EDITOR && UNITY_IPHONE
572+
CWebViewPlugin_AddMask(x, y, w, h);
573+
#endif
574+
}
575+
546576
public void Init(
547577
Callback cb = null,
548578
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
}
423 Bytes
Binary file not shown.

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

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
7575
}
7676
}
7777
}
78+
changed = (androidManifest.SetApplicationTheme("@style/UnityThemeSelector") || changed);
79+
changed = (androidManifest.SetActivityTheme("@style/UnityThemeSelector.Translucent") || changed);
7880
changed = (androidManifest.SetHardwareAccelerated(true) || changed);
7981
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
8082
changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
@@ -86,6 +88,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
8688
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
8789
changed = (androidManifest.AddMicrophone() || changed);
8890
#endif
91+
//#if UNITY_5_6_0 || UNITY_5_6_1
92+
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
93+
//#endif
8994
if (changed) {
9095
androidManifest.Save();
9196
Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
@@ -173,9 +178,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
173178
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
174179
changed = (androidManifest.AddMicrophone() || changed);
175180
#endif
176-
#if UNITY_5_6_0 || UNITY_5_6_1
181+
//#if UNITY_5_6_0 || UNITY_5_6_1
177182
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
178-
#endif
183+
//#endif
179184
if (changed) {
180185
androidManifest.Save();
181186
Debug.LogError("unitywebview: adjusted AndroidManifest.xml. Please rebuild the app.");
@@ -237,6 +242,111 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
237242
dst = (string)method.Invoke(proj, null);
238243
}
239244
File.WriteAllText(projPath, dst);
245+
246+
// Classes/UI/UnityView.h
247+
{
248+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.h").Split('\n');
249+
var lines = new List<string>();
250+
var phase = 0;
251+
foreach (var line in lines0) {
252+
switch (phase) {
253+
case 0:
254+
lines.Add(line);
255+
if (line.StartsWith("@interface UnityView : UnityRenderingView")) {
256+
phase++;
257+
}
258+
break;
259+
case 1:
260+
lines.Add(line);
261+
if (line.StartsWith("}")) {
262+
phase++;
263+
lines.Add("");
264+
lines.Add("- (void)clearMasks;");
265+
lines.Add("- (void)addMask:(CGRect)r;");
266+
}
267+
break;
268+
default:
269+
lines.Add(line);
270+
break;
271+
}
272+
}
273+
File.WriteAllText(path + "/Classes/UI/UnityView.h", string.Join("\n", lines));
274+
}
275+
// Classes/UI/UnityView.mm
276+
{
277+
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.mm").Split('\n');
278+
var lines = new List<string>();
279+
var phase = 0;
280+
foreach (var line in lines0) {
281+
switch (phase) {
282+
case 0:
283+
lines.Add(line);
284+
if (line.StartsWith("@implementation UnityView")) {
285+
phase++;
286+
}
287+
break;
288+
case 1:
289+
if (line.StartsWith("}")) {
290+
phase++;
291+
lines.Add(" NSMutableArray<NSValue *> *_masks;");
292+
lines.Add(line);
293+
lines.Add(@"
294+
- (void)clearMasks
295+
{
296+
if (_masks == nil) {
297+
_masks = [[NSMutableArray<NSValue *> alloc] init];
298+
}
299+
[_masks removeAllObjects];
300+
}
301+
302+
- (void)addMask:(CGRect)r
303+
{
304+
if (_masks == nil) {
305+
_masks = [[NSMutableArray<NSValue *> alloc] init];
306+
}
307+
[_masks addObject:[NSValue valueWithCGRect:r]];
308+
}
309+
310+
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
311+
{
312+
//CGRect mask = CGRectMake(0, 0, 1334, 100);
313+
//return CGRectContainsPoint(mask, point);
314+
for (NSValue *v in _masks) {
315+
if (CGRectContainsPoint([v CGRectValue], point)) {
316+
return TRUE;
317+
}
318+
}
319+
return FALSE;
320+
}
321+
");
322+
} else {
323+
lines.Add(line);
324+
}
325+
break;
326+
default:
327+
lines.Add(line);
328+
break;
329+
}
330+
}
331+
lines.Add(@"
332+
extern ""C"" {
333+
UIView *UnityGetGLView();
334+
void CWebViewPlugin_ClearMasks();
335+
void CWebViewPlugin_AddMask(int x, int y, int w, int h);
336+
}
337+
338+
void CWebViewPlugin_ClearMasks()
339+
{
340+
[(UnityView *)UnityGetGLView() clearMasks];
341+
}
342+
343+
void CWebViewPlugin_AddMask(int x, int y, int w, int h)
344+
{
345+
[(UnityView *)UnityGetGLView() addMask:CGRectMake(x, y, x + w, y + h)];
346+
}
347+
");
348+
File.WriteAllText(path + "/Classes/UI/UnityView.mm", string.Join("\n", lines));
349+
}
240350
}
241351
}
242352
}
@@ -302,6 +412,25 @@ internal bool SetUsesCleartextTraffic(bool enabled) {
302412
return changed;
303413
}
304414

415+
internal bool SetApplicationTheme(string theme) {
416+
bool changed = false;
417+
if (ApplicationElement.GetAttribute("theme", AndroidXmlNamespace) != theme) {
418+
ApplicationElement.SetAttribute("theme", AndroidXmlNamespace, theme);
419+
changed = true;
420+
}
421+
return changed;
422+
}
423+
424+
internal bool SetActivityTheme(string theme) {
425+
bool changed = false;
426+
var activity = GetActivityWithLaunchIntent() as XmlElement;
427+
if (activity.GetAttribute("theme", AndroidXmlNamespace) != theme) {
428+
activity.SetAttribute("theme", AndroidXmlNamespace, theme);
429+
changed = true;
430+
}
431+
return changed;
432+
}
433+
305434
internal bool SetHardwareAccelerated(bool enabled) {
306435
bool changed = false;
307436
var activity = GetActivityWithLaunchIntent() as XmlElement;

0 commit comments

Comments
 (0)