Загрузите Unity WebGL во Flask - PullRequest
1 голос
/ 10 мая 2019

Я абсолютный новичок в Сети и Единстве. Я пытаюсь запустить сборку Unity WebGL на моем сервере Flask.

Вот моя иерархия папок:

web\
    templates\
        Build\
            UnityLoader.js
            WebBuild.json
        TemplateData\
            style.css
            TemplateData.js
        index.html
    app.py

app.py имеет 3 корня, чтобы загрузить все мои js файлы, запрошенные index.html:

app = Flask(__name__, static_url_path='/templates')
APP_ROOT = os.path.dirname(os.path.abspath(__file__))

@app.route("/")
def index():
    return render_template("index.html")

@app.route('/templates/Build/<path:path>')
def send_Buildjs(path):
    return send_from_directory('templates/Build', path)

@app.route('/templates/TemplateData/<path:path>')
def send_Templatejs(path):
    return send_from_directory('templates/TemplateData', path)

if __name__ == "__main__":
    app.run(port=4555, debug=True)

index.html - это файл, сгенерированный по умолчанию приложением Unity для WebGL, с некоторыми небольшими изменениями:

<!DOCTYPE html>
<html lang="en-us">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Unity WebGL Player | VisualNN</title>

    <link rel="shortcut icon" href="{{ url_for('static', filename='TemplateData/favicon.ico') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='TemplateData/style.css') }}">
    <script src="{{ url_for('static', filename='TemplateData/UnityProgress.js') }}"></script>
    <script src="{{ url_for('static', filename='Build/UnityLoader.js') }}"></script>
    <script>
    var gameInstance = UnityLoader.instantiate("gameContainer", "{{ url_for('static', filename='Build/WebBuild.json') }}", {onProgress: UnityProgress});

    </script>
</head>
  <body>
    <div class="webgl-content">
      <div id="unityContainer" style="width: 960px; height: 600px"></div>
      <div class="footer">
        <div class="webgl-logo"></div>
            <div class="fullscreen" onclick="unityInstance.SetFullscreen(1)"></div>
        <div class="title">VisualNN</div>
      </div>
    </div>
  </body>
</html>

В моем браузере Firefox загружен значок, все файлы js также загружены. Я получаю 202 и 304 ответных сообщения для значков и js файлов. Но игра единства не загружается, ни одна коробка просто пуста. Ничего не отображается в консоли Firefox. Я предполагаю, что Build/WebBuild.json не загружается? Как у кого есть идеи в чем проблема?

EDIT

Дополнительная информация при загрузке страницы из консоли Flask Server:

127.0.0.1 - - [10/May/2019 18:34:55] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [10/May/2019 18:34:55] "GET /templates/TemplateData/style.css HTTP/1.1" 304 -
127.0.0.1 - - [10/May/2019 18:34:55] "GET /templates/TemplateData/UnityProgress.js HTTP/1.1" 304 -
127.0.0.1 - - [10/May/2019 18:34:55] "GET /templates/Build/UnityLoader.js HTTP/1.1" 304 -
127.0.0.1 - - [10/May/2019 18:34:55] "GET /templates/TemplateData/webgl-logo.png HTTP/1.1" 304 -
127.0.0.1 - - [10/May/2019 18:34:55] "GET /templates/TemplateData/fullscreen.png HTTP/1.1" 304 -

1 Ответ

0 голосов
/ 26 июня 2019

Я поделюсь своим ответом, найденным на Reddit:

https://www.reddit.com/r/flask/comments/ab7i9d/how_to_make_the_unity_webgl_build_work_with_flask/

...