【问题标题】:Unable to type in input with Unity WebGL background div in React JS无法在 React JS 中使用 Unity WebGL 背景 div 输入输入
【发布时间】:2017-10-20 02:45:51
【问题描述】:
import React from 'react';
import ReactDOM from 'react-dom';
import {Unity} from 'react-unity-webgl';

var timerCount = 0;

export default class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = { nPageNum: 0};
  }

  componentDidMount() {
    this.startTimer(this);
  }

  render() {
    if (timerCount > 5) {
        return(
          <div style={{ width: '100%', height: '100%' }}>
            <div  style={{ position: 'absolute', width: '100%', height: '100%', zIndex: 0 }}>
              <Unity src="Libs/object_unity/Build/WebGL.json" />
            </div>
            <div  style={{ position: 'absolute', width: '100%', height: '100%', zIndex: 1 }}>
              <input style={{ marginLeft:60, marginTop:100, width: 600, height: 80, zIndex: 1 }} type="text" name="title" id="title" />
            </div>
          </div>
        )
    } else {
        return(
          <div>
            <div>
              <input style={{ marginLeft:60, marginTop:100, width: 600, height: 80, zIndex: 1 }} type="text" name="title" id="title" />
            </div>
          </div>
        )
    }

  }
    tick () {
      timerCount = timerCount + 1;
      if (timerCount > 10) {
            this.stopTimer(this);
      }

      this.setState({ nPageNum: 1 });
  }
  startTimer () {
    clearInterval(this.timer);
    this.timer = setInterval(this.tick.bind(this), 20);
  }

  stopTimer () {
    clearInterval(this.timer);
  }
}

我在 ReactJS 中为输入框制作了一个 div,它运行良好。但是在为 Unity WebGL 背景输入另一个 div 后,键盘事件不起作用。 Unity 集成有什么问题?

以下是控制台日志:

[HMR] 等待来自 WDS 的更新信号... bundle.js:5945 [HMR] 等待来自 WDS 的更新信号... UnityLoader.js:4 如果您将 Web 服务器配置为使用 gzip 压缩托管 .unityweb 文件,则可以减少启动时间。 bundle.js:9304 [WDS] 启用热模块更换。 blob:localhost:8000/e1696fb5-90a3-4d98-b184-aebb735ab198:2 初始化引擎版本:2017.2.0f3 (46dda1414e51)

UnityLoader.js:1 创建 WebGL 2.0 上下文。 blob:localhost:8000/e1696fb5-90a3-4d98-b184-aebb735ab198:2 渲染器:WebKit WebGL

blob:localhost:8000/e1696fb5-90a3-4d98-b184-aebb735ab198:2 供应商:WebKit

blob:localhost:8000/e1696fb5-90a3-4d98-b184-aebb735ab198:2 版本:OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium))

blob:localhost:8000/e1696fb5-90a3-4d98-b184-aebb735ab198:2 GLES: 3

团块:本地主机:8000 / e1696fb5-90a3-4d98-B184-aebb735ab198:2 EXT_color_buffer_float GL_EXT_color_buffer_float EXT_disjoint_timer_query_webgl2 GL_EXT_disjoint_timer_query_webgl2 EXT_texture_filter_anisotropic GL_EXT_texture_filter_anisotropic OES_texture_float_linear GL_OES_texture_float_linear WEBGL_compressed_texture_s3tc GL_WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb GL_WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info GL_WEBGL_debug_renderer_info WEBGL_debug_shaders GL_WEBGL_debug_shaders WEBGL_lose_context GL_WEBGL_lose_context P>

blob:localhost:8000/e1696fb5-90a3-4d98-b184-aebb735ab198:2 OPENGL LOG:创建 OpenGL ES 3.0 图形设备;上下文级别;上下文句柄 1

blob:localhost:8000/e1696fb5-90a3-4d98-b184-aebb735ab198:2 卸载时间:46.0​​55000 毫秒

2blob:localhost:8000/e1696fb5-90a3-4d98-b184-aebb735ab198:2 警告:2 FS.syncfs 操作同时进行,可能只是做额外的工作

【问题讨论】:

  • Unity 组件的代码是什么?
  • 这只是启动动画。没有任何功能。
  • 好的。那我就不知道了。

标签: javascript html reactjs unity-webgl


【解决方案1】:

我找到了这个问题的解决方案。

我从这个链接中找到了解决方案。 https://docs.unity3d.com/ScriptReference/WebGLInput-captureAllKeyboardInput.html

所以我在 Unity 项目中添加了一些代码,并重新构建了 Unity 项目。

这是 Unity 的代码。

#if !UNITY_EDITOR && UNITY_WEBGL
WebGLInput.captureAllKeyboardInput = false;
#endif

所以我在 MonoBehaviour 中添加了这段代码。

然后,它运行良好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-07
    • 2021-10-18
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多