1

我正在开发一个通过 Unity 扩展将 Vuforia 用于 AR/交互式内容的应用程序。我无法弄清楚如何将 Vuforia 集成到应用程序中(以及用于渲染的 Unity)。

我的目标是 Android 2.3.3(API 级别 10)及更高版本。

目前我的应用程序设置为有一个 SherlockFragmentActivity 启动几个后台任务并使用 ViewPager 和 FragmentPagerAdapter 在几个片段之间切换。这些片段之一是 Vuforia 片段。

到目前为止,我尝试的是实例化 UnityPlayer 并在片段的 onCreateView 中返回视图:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    UnityPlayer mPlayer = new UnityPlayer(this); // Put your activity object here
    int glesMode = mPlayer.getSettings().getInt("gles_mode", 1);
    boolean trueColor8888 = false;
    mPlayer.init(glesMode, trueColor8888);
        View view = mPlayer.getView();
        return view;
}

但是,当我这样做时,Vuforia 无法加载。Unity 确实加载了,但我得到一个黑屏并且没有来自相机的输出。日志猫:

07-02 14:59:25.695: D/Unity(18351): Creating OpenGL ES 2.0 context (RGBA32 8888 24/8)
07-02 14:59:25.900: D/Unity(18351): GL_EXT_debug_marker GL_OES_texture_npot     GL_OES_compressed_ETC1_RGB8_texture GL_OES_standard_derivatives GL_OES_EGL_image GL_OES_depth24 GL_ARM_rgba8 GL_ARM_mali_shader_binary GL_OES_depth_texture GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 GL_EXT_blend_minmax GL_OES_EGL_image_external GL_OES_EGL_sync GL_OES_rgb8_rgba8 GL_EXT_multisampled_render_to_texture GL_EXT_discard_framebuffer 
07-02 14:59:26.520: D/dalvikvm(18351): Trying to load lib /data/data/com.androchill.socialsquare.fingerprintdemo/lib/libQCARWrapper.so 0x41efb450
07-02 14:59:26.520: E/Unity(18351): Unable to find QCARWrapper
07-02 14:59:26.525: D/dalvikvm(18351): Trying to load lib /data/data/com.androchill.socialsquare.fingerprintdemo/lib/libQCARWrapper.so 0x41efb450
07-02 14:59:26.525: E/Unity(18351): Unable to find QCARWrapper
07-02 14:59:26.750: I/Unity(18351): DllNotFoundException: QCARWrapper
07-02 14:59:26.750: I/Unity(18351):   at (wrapper managed-to-native) QCARNativeWrapper:trackerManagerInitTracker (int)
07-02 14:59:26.750: I/Unity(18351):   at QCARNativeWrapper.TrackerManagerInitTracker (Int32 trackerType) [0x00000] in <filename unknown>:0 
07-02 14:59:26.750: I/Unity(18351):   at TrackerManagerImpl.InitTracker (Type trackerType) [0x00000] in <filename unknown>:0 
07-02 14:59:26.750: I/Unity(18351):   at DataSetLoadBehaviour.Awake () [0x00000] in <filename unknown>:0 
07-02 14:59:26.750: I/Unity(18351):  
07-02 14:59:26.750: I/Unity(18351): (Filename:  Line: -1)
07-02 14:59:26.815: I/Unity(18351): Trackable USC_campus_map lost
07-02 14:59:26.815: I/Unity(18351):  
07-02 14:59:26.815: I/Unity(18351): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 54)
07-02 14:59:26.815: D/dalvikvm(18351): Trying to load lib /data/data/com.androchill.socialsquare.fingerprintdemo/lib/libQCARWrapper.so 0x41efb450
07-02 14:59:26.815: E/Unity(18351): Unable to find QCARWrapper
07-02 14:59:26.815: D/dalvikvm(18351): Trying to load lib /data/data/com.androchill.socialsquare.fingerprintdemo/lib/libQCARWrapper.so 0x41efb450
07-02 14:59:26.815: E/Unity(18351): Unable to find QCARWrapper
07-02 14:59:26.820: I/Unity(18351): DllNotFoundException: QCARWrapper
07-02 14:59:26.820: I/Unity(18351):   at (wrapper managed-to-native) QCARNativeWrapper:getInitErrorCode ()
07-02 14:59:26.820: I/Unity(18351):   at QCARNativeWrapper.GetInitErrorCode () [0x00000] in <filename unknown>:0 
07-02 14:59:26.820: I/Unity(18351):   at QCARUnityImpl.CheckInitializationError () [0x00000] in <filename unknown>:0 
07-02 14:59:26.820: I/Unity(18351):   at QCARUnity.CheckInitializationError () [0x00000] in <filename unknown>:0 
07-02 14:59:26.820: I/Unity(18351):   at DefaultInitializationErrorHandler.Start () [0x00000] in <filename unknown>:0 
07-02 14:59:26.820: I/Unity(18351):  
07-02 14:59:26.820: I/Unity(18351): (Filename:  Line: -1)
07-02 14:59:26.820: I/Unity(18351): QCARWrapper.Start
07-02 14:59:26.820: I/Unity(18351):  
07-02 14:59:26.820: I/Unity(18351): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 54)
07-02 14:59:26.825: I/Unity(18351): DllNotFoundException: QCARWrapper
07-02 14:59:26.825: I/Unity(18351):   at (wrapper managed-to-native) QCARNativeWrapper:getInitErrorCode ()
07-02 14:59:26.825: I/Unity(18351):   at QCARNativeWrapper.GetInitErrorCode () [0x00000] in <filename unknown>:0 
07-02 14:59:26.825: I/Unity(18351):   at QCARUnityImpl.CheckInitializationError () [0x00000] in <filename unknown>:0 
07-02 14:59:26.825: I/Unity(18351):   at QCARUnity.CheckInitializationError () [0x00000] in <filename unknown>:0 
07-02 14:59:26.825: I/Unity(18351):   at QCARBehaviour.Start () [0x00000] in <filename unknown>:0 
07-02 14:59:26.825: I/Unity(18351):  
07-02 14:59:26.825: I/Unity(18351): (Filename:  Line: -1)
07-02 14:59:26.855: D/dalvikvm(18351): Trying to load lib /data/data/com.androchill.socialsquare.fingerprintdemo/lib/libQCARWrapper.so 0x41efb450
07-02 14:59:26.855: E/Unity(18351): Unable to find QCARWrapper
07-02 14:59:26.860: D/dalvikvm(18351): Trying to load lib /data/data/com.androchill.socialsquare.fingerprintdemo/lib/libQCARWrapper.so 0x41efb450
07-02 14:59:26.860: E/Unity(18351): Unable to find QCARWrapper
07-02 14:59:26.860: I/Unity(18351): DllNotFoundException: QCARWrapper
07-02 14:59:26.860: I/Unity(18351):   at (wrapper managed-to-native) QCARNativeWrapper:rendererRenderVideoBackground (int)
07-02 14:59:26.860: I/Unity(18351):   at QCARNativeWrapper.RendererRenderVideoBackground (Int32 bindVideoBackground) [0x00000] in <filename unknown>:0 
07-02 14:59:26.860: I/Unity(18351):   at QCARManagerImpl.RenderVideoBackgroundOrDrawIntoTextureInNative () [0x00000] in <filename unknown>:0 
07-02 14:59:26.860: I/Unity(18351):   at QCARManagerImpl.PrepareRendering () [0x00000] in <filename unknown>:0 
07-02 14:59:26.860: I/Unity(18351):   at QCARBehaviour.OnPreCull () [0x00000] in <filename unknown>:0 
07-02 14:59:26.860: I/Unity(18351):  
07-02 14:59:26.860: I/Unity(18351): (Filename:  Line: -1)
07-02 14:59:26.900: D/dalvikvm(18351): Trying to load lib /data/data/com.androchill.socialsquare.fingerprintdemo/lib/libQCARWrapper.so 0x41efb450
07-02 14:59:26.900: E/Unity(18351): Unable to find QCARWrapper
07-02 14:59:26.905: D/dalvikvm(18351): Trying to load lib /data/data/com.androchill.socialsquare.fingerprintdemo/lib/libQCARWrapper.so 0x41efb450
07-02 14:59:26.905: E/Unity(18351): Unable to find QCARWrapper
07-02 14:59:26.905: I/Unity(18351): DllNotFoundException: QCARWrapper
07-02 14:59:26.905: I/Unity(18351):   at (wrapper managed-to-native) QCARNativeWrapper:rendererEnd ()
07-02 14:59:26.905: I/Unity(18351):   at QCARNativeWrapper.RendererEnd () [0x00000] in <filename unknown>:0 
07-02 14:59:26.905: I/Unity(18351):   at QCARManagerImpl.FinishRendering () [0x00000] in <filename unknown>:0 
07-02 14:59:26.905: I/Unity(18351):   at QCARBehaviour.OnPostRender () [0x00000] in <filename unknown>:0 

然后我尝试实例化 QCARUnityPlayer 而不是 UnityPlayer,但随后我得到一个 UnsatisfiedLinkError:

07-02 15:04:26.830: I/QCAR(26661): onSurfaceCreated
07-02 15:04:26.830: W/dalvikvm(26661): No implementation found for native Lcom/qualcomm/QCAR/QCAR;.onSurfaceCreated:()V
07-02 15:04:26.860: W/dalvikvm(26661): threadid=14: thread exiting with uncaught exception (group=0x412522a0)
07-02 15:04:26.860: E/AndroidRuntime(26661): FATAL EXCEPTION: GLThread 1638
07-02 15:04:26.860: E/AndroidRuntime(26661): java.lang.Error: FATAL EXCEPTION [GLThread 1638]
07-02 15:04:26.860: E/AndroidRuntime(26661): Unity version     : 4.1.5f1
07-02 15:04:26.860: E/AndroidRuntime(26661): Device model      : samsung GT-N7100
07-02 15:04:26.860: E/AndroidRuntime(26661): Device fingerprint: samsung/t03gxx/t03g:4.1.2/JZO54K/N7100XXDMC3:user/release-keys
07-02 15:04:26.860: E/AndroidRuntime(26661): Caused by: java.lang.UnsatisfiedLinkError: Native method not found: com.qualcomm.QCAR.QCAR.onSurfaceCreated:()V
07-02 15:04:26.860: E/AndroidRuntime(26661):    at com.qualcomm.QCAR.QCAR.onSurfaceCreated(Native Method)
07-02 15:04:26.860: E/AndroidRuntime(26661):    at com.qualcomm.QCARUnityPlayer.QCARUnityPlayer.onSurfaceCreated(QCARUnityPlayer.java:39)
07-02 15:04:26.860: E/AndroidRuntime(26661):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
07-02 15:04:26.860: E/AndroidRuntime(26661):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

我已经按照本教程以及我能找到的几乎所有其他内容进行操作,但仍然无法弄清楚。

我的片段代码:

import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.actionbarsherlock.app.SherlockFragment;
import com.unity3d.player.UnityPlayer;

public class MyFragment extends SherlockFragment {

private UnityPlayer mUnityPlayer;

// UnityPlayer.init() should be called before attaching the view to a layout. 
// UnityPlayer.quit() should be the last thing called; it will terminate the process and not return.

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mUnityPlayer = new UnityPlayer(getActivity()); // Put your activity object here
    int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
    boolean trueColor8888 = false;
    mUnityPlayer.init(glesMode, trueColor8888);

    // Get the view - e.g. to return from the fragment method onCreateView:
    View view = mUnityPlayer.getView();
    return view;
}

public void onDestroy()
{
    super.onDestroy();
    mUnityPlayer.quit();
}

// onPause()/onResume() must be sent to UnityPlayer to enable pause and resource recreation on resume.
public void onPause()
{
    super.onPause();
    mUnityPlayer.pause();
    if (getActivity().isFinishing())
        mUnityPlayer.quit();
}
public void onResume()
{
    super.onResume();
    mUnityPlayer.resume();
}
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);
    mUnityPlayer.configurationChanged(newConfig);
}

// Pass any keys not handled by (unfocused) views straight to UnityPlayer
public boolean onKeyMultiple(int keyCode, int count, KeyEvent event)
{
    return mUnityPlayer.onKeyMultiple(keyCode, count, event);
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    return mUnityPlayer.onKeyDown(keyCode, event);
}
public boolean onKeyUp(int keyCode, KeyEvent event)
{
    return mUnityPlayer.onKeyUp(keyCode, event);
}
}

我的问题是,如何强制 Unity/Vuforia 在 SherlockFragment 中工作?

4

0 回答 0