seb*_*bbo 2 unity-game-engine oculus virtual-reality oculusgo
我目前正在尝试找到一种在 VR 应用程序中使用 Web 浏览器的方法。基本上目标是在面板中打开一个像https://stackoverflow.com这样的页面,并让它在 oculus go 控制器中滚动。
我已经做了插件实现这个像一些研究这个,但他们都不似乎对Oculus公司去工作。
更新:我更新了repo以支持视频,它是一个基于 GeckoView 浏览器引擎的全功能 3D 浏览器。它依赖于OVROverlayOculus 将 Android 插件中生成的帧渲染到 Unity3D 纹理上。
这是我制作的一个 repo,希望我们可以实现一个不错的游戏内浏览器。它有点马车/慢,但它有效(大部分时间)。
它使用一个 Java 插件,通过覆盖视图的方法将Android 渲染WebView为 a ,将其转换为 png 并将其传递给 unity 。有很多工作要做,请随时改进它!BitmapDrawRawImage
在回购,你可以找到该插件(unitylibrary-debug.aar),你需要进口的资产/插件/ Android的/,并BrowserView.cs和UnityThread.cs您可以使用在Android转换WebView到纹理统一的RawImage能显示。BrowserView.cs适当填写的公共字段。确保您的 API 级别在 Unity 的播放器设置中设置为 25。
这里覆盖了WebView的Draw方法来创建位图和 PNG,并初始化你需要的变量:
public class BitmapWebView extends WebView{
private void init(){
stream = new ByteArrayOutputStream();
array = new ReadData(new byte[]{});
bm = Bitmap.createBitmap(outputWindowWidth,
outputWindowHeight, Bitmap.Config.ARGB_8888);
bmCanvas = new Canvas(bm);
}
@Override
public void draw( Canvas ){
// draw onto a new canvas
super.draw(bmCanvas);
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
array.Buffer = stream.toByteArray();
UnityBitmapCallback.onFrameUpdate(array,
bm.getWidth(),
bm.getHeight(),
canGoBack,
canGoForward );
stream.reset();
}
}
// you need this class to communicate properly with unity
public class ReadData {
public byte[] Buffer;
public ReadData(byte[] buffer) {
Buffer=buffer;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我们将 png 传递给 unity RawImage。这是Unity接收端:
// class used for the callback with the texture
class AndroidBitmapPluginCallback : AndroidJavaProxy
{
public AndroidBitmapPluginCallback() : base("com.unityexport.ian.unitylibrary.PluginInterfaceBitmap") { }
public BrowserView BrowserView;
public void onFrameUpdate(AndroidJavaObject jo, int width, int height, bool canGoBack, bool canGoForward)
{
AndroidJavaObject bufferObject = jo.Get<AndroidJavaObject>("Buffer");
byte[] bytes = AndroidJNIHelper.ConvertFromJNIArray<byte[]>(bufferObject.GetRawObject());
if (bytes == null)
return;
if (BrowserView != null)
{
UnityThread.executeInUpdate(()=> BrowserView.SetTexture(bytes,width,height,canGoBack,canGoForward));
}
else
Debug.Log("TestAndroidPlugin is not set");
}
}
public class BrowserView : MonoBehaviour {
// Browser view needs a RawImage component to display webpages
void Start () {
_imageTexture2D = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false);
_rawImage = gameObject.GetComponent<RawImage>();
_rawImage.texture = _imageTexture2D;
#if !UNITY_EDITOR && UNITY_ANDROID
// Get your Java class and create a new instance
var tempAjc = new AndroidJavaClass("YOUR_LIBRARY.YOUR_CLASS")
_ajc = tempAjc.CallStatic<AndroidJavaObject>("CreateInstance");
// send the callback object to java to get frame updates
AndroidBitmapPluginCallback androidPluginCallback = new AndroidBitmapPluginCallback {BrowserView = this};
_ajc.Call("SetUnityBitmapCallback", androidPluginCallback);
#endif
}
// Android callback to change our browser view texture
public void SetTexture( byte[] bytes, int width, int height, bool canGoBack, bool canGoForward)
{
if (width != _imageTexture2D.width || height != _imageTexture2D.height)
_imageTexture2D = new Texture2D(width, height, TextureFormat.ARGB32, false);
_imageTexture2D.LoadImage(bytes);
_imageTexture2D.Apply();
_rawImage.texture = _imageTexture2D;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2921 次 |
| 最近记录: |