如何将Unity WebGL放入我的React Native应用程序中?

问题描述 投票:10回答:2

我已经使用WebGL编写了一个简单的React Native应用程序。我使用了https://github.com/JilvanPinheiro/reactive-native-unity-webgl

import Unity from 'react-native-unity-webgl';
...
render() {
  return (
 <Unity 
       width="500px"
       height="350px"
       onProgress={ this.onProgress }
       src="http://192.168.1.101/Build/Ultimatum.json" 
       loader="http://192.168.1.101/Build/UnityLoader.js" />`
  );
}

但是我收到以下错误:

ReferenceError:  Can't find variable: document. This error is located at:
    in Unity (at App.js:9)
    in RCTView (at View.js:60)
    in View (at App.js:8)
    in App (at registerRootComponent.js:35)
    in RootErrorBoundary (at registerRootComponent.js:34)
    in ExpoRootComponent (at renderApplication.js:33)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:102)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:122)
    in AppContainer (at renderApplication.js:32)

是否有更简单的方法将Unity webGL放置在我的React Native应用程序中?

reactjs unity3d react-native unity-webgl
2个回答
0
投票

您必须从document导入React和react-native,尝试此操作将解决您的问题,并确保您下载与Unity版本匹配的发行版


0
投票

这是您的整个密码吗?还是剩下的?您必须添加react和其他一些东西才能使它起作用。如果您没有这些代码,我会为您编写以下代码:]

import React, {Component} from 'react';
import {
    View,
    documnet
} from 'react-native';

...

render () {
    return(
        <View>
             <Unity 
               width="500px"
               height="350px"
               onProgress={ this.onProgress }
               src="http://192.168.1.101/Build/Ultimatum.json" 
               loader="http://192.168.1.101/Build/UnityLoader.js"
             />
        </View>
    );
}
© www.soinside.com 2019 - 2024. All rights reserved.