解决!读我的回答.
我正在尝试在本机React应用程序中显示Unity视图.UnityPlayer使用Vuforia显示AR的摄像头源.我们需要在iOS和Android的React原生应用程序中包含此视图.
我跟着很多指南,但我在Android版本中有黑屏.如果我在react-native(而不是ReactActivity)生成的Android项目中运行UnityPlayerActivity(来自Unity导出的Android项目),我会正确看到我的UnityPlayer.所以我想我的项目包含所有必要的依赖项.
我的js代码的代码片段:
const UnityIosContainerView = requireNativeComponent("UnityContainerView",
null);
const UnityAndroidContainerView = requireNativeComponent("RCT3DView", null);
class ArPage extends React.Component {
render() {
return (
<View style={{ flex: 1, backgroundColor: "red" }}>
{Platform.OS === "ios" ? (
<UnityIosContainerView style={{ flex: 1 }} />
) : (
<UnityAndroidContainerView style={{ flex: 1 }} />
)}
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
按照本指南https://facebook.github.io/react-native/docs/native-components-android.html 我有一个自定义包
public class CustomReactPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return …Run Code Online (Sandbox Code Playgroud)