Skip to content

Commit 8b5f7f8

Browse files
authored
Merge pull request #155 from gree/feature/unity56
Feature/unity56
2 parents d778eee + 039c87e commit 8b5f7f8

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ rebuilt the apk. Although some old/buggy devices may not work well
8080
with `android:hardwareAccelerated="true"`, the WebView runs very
8181
smoothly with this setting.
8282

83+
For Unity 5.6 or newer, you also need to modify `android:name` from
84+
`com.unity3d.player.UnityPlayerActivity` to
85+
`net.gree.unitywebview.CUnityPlayerActivity`. This custom activity
86+
implementation will adjust Unity's SurfaceView z order. Please refer
87+
`plugins/Android/src/net/gree/unitywebview/CUnityPlayerActivity.java`
88+
and `plugins/Android/src/net/gree/unitywebview/CUnityPlayer.java` if
89+
you already have your own acitivity implementation.
90+
8391
### Web Player
8492

8593
The implementation utilizes IFRAME so please put both

dist/unity-webview.unitypackage

1.01 KB
Binary file not shown.

dist/unity-webview.zip

1.04 KB
Binary file not shown.

plugins/Android/Editor/UnityWebViewPostprocessBuild.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
3434
doc.Save(manifest);
3535
Debug.LogError("adjusted AndroidManifest.xml about android:hardwareAccelerated. Please rebuild the app.");
3636
}
37+
#if UNITY_5_6_OR_NEWER
38+
if (activity != null
39+
&& activity.GetAttribute("android:name") == "com.unity3d.player.UnityPlayerActivity") {
40+
activity.SetAttribute("name", "http://schemas.android.com/apk/res/android", "net.gree.unitywebview.CUnityPlayerActivity");
41+
doc.Save(manifest);
42+
Debug.LogError("adjusted AndroidManifest.xml about android:name. Please rebuild the app.");
43+
}
44+
#endif
3745
}
3846
}
3947

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package net.gree.unitywebview;
2+
3+
import com.unity3d.player.*;
4+
import android.content.ContextWrapper;
5+
import android.view.SurfaceView;
6+
import android.view.View;
7+
8+
public class CUnityPlayer
9+
extends UnityPlayer
10+
{
11+
public CUnityPlayer(ContextWrapper contextwrapper) {
12+
super(contextwrapper);
13+
}
14+
15+
public void addView(View child) {
16+
if (child instanceof SurfaceView) {
17+
((SurfaceView)child).setZOrderOnTop(false);
18+
}
19+
super.addView(child);
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.gree.unitywebview;
2+
3+
import com.unity3d.player.*;
4+
import android.os.Bundle;
5+
6+
public class CUnityPlayerActivity
7+
extends UnityPlayerActivity
8+
{
9+
@Override
10+
public void onCreate(Bundle bundle) {
11+
requestWindowFeature(1);
12+
super.onCreate(bundle);
13+
getWindow().setFormat(2);
14+
mUnityPlayer = new CUnityPlayer(this);
15+
setContentView(mUnityPlayer);
16+
mUnityPlayer.requestFocus();
17+
}
18+
}

0 commit comments

Comments
 (0)