Skip to content

Commit

Permalink
updated binaries.
Browse files Browse the repository at this point in the history
  • Loading branch information
KojiNakamaru committed Nov 19, 2023
1 parent c51ee1e commit 481bf6d
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 8 deletions.
Binary file modified dist/package-nofragment/Assets/Plugins/Android/WebViewPlugin.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
}
}
changed = (androidManifest.SetExported(true) || changed);
changed = (androidManifest.SetApplicationTheme("@style/UnityThemeSelector") || changed);
changed = (androidManifest.SetActivityTheme("@style/UnityThemeSelector.Translucent") || changed);
changed = (androidManifest.SetWindowSoftInputMode("adjustPan") || changed);
changed = (androidManifest.SetHardwareAccelerated(true) || changed);
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
Expand All @@ -88,6 +90,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
changed = (androidManifest.AddMicrophone() || changed);
#endif
//#if UNITY_5_6_0 || UNITY_5_6_1
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
//#endif
if (changed) {
androidManifest.Save();
Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
Expand Down Expand Up @@ -176,9 +181,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
changed = (androidManifest.AddMicrophone() || changed);
#endif
#if UNITY_5_6_0 || UNITY_5_6_1
//#if UNITY_5_6_0 || UNITY_5_6_1
changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
#endif
//#endif
if (changed) {
androidManifest.Save();
Debug.LogError("unitywebview: adjusted AndroidManifest.xml. Please rebuild the app.");
Expand Down Expand Up @@ -240,6 +245,118 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
dst = (string)method.Invoke(proj, null);
}
File.WriteAllText(projPath, dst);

// Classes/UI/UnityView.h
{
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.h").Split('\n');
var lines = new List<string>();
var phase = 0;
foreach (var line in lines0) {
switch (phase) {
case 0:
lines.Add(line);
if (line.StartsWith("@interface UnityView : UnityRenderingView")) {
phase++;
}
break;
case 1:
lines.Add(line);
if (line.StartsWith("}")) {
phase++;
lines.Add("");
lines.Add("- (void)clearMasks;");
lines.Add("- (void)addMask:(CGRect)r;");
}
break;
default:
lines.Add(line);
break;
}
}
File.WriteAllText(path + "/Classes/UI/UnityView.h", string.Join("\n", lines));
}
// Classes/UI/UnityView.mm
{
var lines0 = File.ReadAllText(path + "/Classes/UI/UnityView.mm").Split('\n');
var lines = new List<string>();
var phase = 0;
foreach (var line in lines0) {
switch (phase) {
case 0:
lines.Add(line);
if (line.StartsWith("@implementation UnityView")) {
phase++;
}
break;
case 1:
if (line.StartsWith("}")) {
phase++;
lines.Add(" NSMutableArray<NSValue *> *_masks;");
lines.Add(line);
lines.Add(@"
- (void)clearMasks
{
if (_masks == nil) {
_masks = [[NSMutableArray<NSValue *> alloc] init];
}
[_masks removeAllObjects];
}
- (void)addMask:(CGRect)r
{
if (_masks == nil) {
_masks = [[NSMutableArray<NSValue *> alloc] init];
}
[_masks addObject:[NSValue valueWithCGRect:r]];
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
//CGRect mask = CGRectMake(0, 0, 1334, 100);
//return CGRectContainsPoint(mask, point);
for (NSValue *v in _masks) {
if (CGRectContainsPoint([v CGRectValue], point)) {
return TRUE;
}
}
return FALSE;
}
");
} else {
lines.Add(line);
}
break;
default:
lines.Add(line);
break;
}
}
lines.Add(@"
extern ""C"" {
UIView *UnityGetGLView();
void CWebViewPlugin_ClearMasks();
void CWebViewPlugin_AddMask(int x, int y, int w, int h);
}
void CWebViewPlugin_ClearMasks()
{
[(UnityView *)UnityGetGLView() clearMasks];
}
void CWebViewPlugin_AddMask(int x, int y, int w, int h)
{
UIView *view = UnityGetGLViewController().view;
CGFloat scale = 1.0f;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
scale = view.window.screen.nativeScale;
} else {
scale = view.contentScaleFactor;
}
[(UnityView *)UnityGetGLView() addMask:CGRectMake(x / scale, y / scale, w / scale, h / scale)];
}
");
File.WriteAllText(path + "/Classes/UI/UnityView.mm", string.Join("\n", lines));
}
}
}
}
Expand Down Expand Up @@ -316,6 +433,25 @@ internal bool SetExported(bool enabled) {
return changed;
}

internal bool SetApplicationTheme(string theme) {
bool changed = false;
if (ApplicationElement.GetAttribute("theme", AndroidXmlNamespace) != theme) {
ApplicationElement.SetAttribute("theme", AndroidXmlNamespace, theme);
changed = true;
}
return changed;
}

internal bool SetActivityTheme(string theme) {
bool changed = false;
var activity = GetActivityWithLaunchIntent() as XmlElement;
if (activity.GetAttribute("theme", AndroidXmlNamespace) != theme) {
activity.SetAttribute("theme", AndroidXmlNamespace, theme);
changed = true;
}
return changed;
}

internal bool SetWindowSoftInputMode(string mode) {
bool changed = false;
var activity = GetActivityWithLaunchIntent() as XmlElement;
Expand Down
30 changes: 30 additions & 0 deletions dist/package-nofragment/Assets/Plugins/WebViewObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ private static extern void _CWebViewPlugin_Reload(
[DllImport("WebView")]
private static extern string _CWebViewPlugin_GetMessage(IntPtr instance);
#elif UNITY_IPHONE
[DllImport("__Internal")]
private static extern void CWebViewPlugin_ClearMasks();
[DllImport("__Internal")]
private static extern void CWebViewPlugin_AddMask(int x, int y, int w, int h);
[DllImport("__Internal")]
private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, bool zoom, string ua, bool enableWKWebView, int wkContentMode, bool wkAllowsLinkPreview, bool wkAllowsBackForwardNavigationGestures, int radius);
[DllImport("__Internal")]
Expand Down Expand Up @@ -590,6 +594,32 @@ public static bool IsWebViewAvailable()
#endif
}

public static void ClearMasks()
{
#if !UNITY_EDITOR && UNITY_ANDROID
using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
var activity = UnityClass.GetStatic<AndroidJavaObject>("currentActivity");
activity.Call("clearMasks");
}
#elif !UNITY_EDITOR && UNITY_IPHONE
CWebViewPlugin_ClearMasks();
#endif
}

public static void AddMask(int x, int y, int w, int h)
{
#if !UNITY_EDITOR && UNITY_ANDROID
using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
var activity = UnityClass.GetStatic<AndroidJavaObject>("currentActivity");
activity.Call("addMask", x, y, w, h);
}
#elif !UNITY_EDITOR && UNITY_IPHONE
CWebViewPlugin_AddMask(x, y, w, h);
#endif
}

public void Init(
Callback cb = null,
Callback err = null,
Expand Down
2 changes: 1 addition & 1 deletion dist/package-nofragment/Assets/Plugins/iOS/WebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra

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

[view addSubview:webView];
[view.superview insertSubview:webView atIndex:0];

return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra

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

[view addSubview:webView];
[view.superview insertSubview:webView atIndex:0];

return self;
}
Expand Down
Binary file modified dist/package/Assets/Plugins/Android/WebViewPlugin.aar
Binary file not shown.
Loading

0 comments on commit 481bf6d

Please sign in to comment.