Unity3d-在Google App Engine上托管 [英] Unity3d - Hosting on Google App Engine
问题描述
我在GAE上托管Unity3d Web应用程序时遇到问题. 当应用程序加载并且Web播放器开始请求.unity3d"文件时,我使用以下python脚本进行HTTP响应:
I have a problem with hosting my Unity3d web application on GAE. When the application loads and the web player starts to request the ".unity3d" file, i use the following python script to make the HTTP response:
class UnityHandler(webapp.RequestHandler):
def get (self, q):
if q is None:
q = 'WebPlayer.unity3d'
path = os.path.join (os.path.dirname (__file__), q)
self.response.headers ['Content-Type'] = 'text/html'
self.response.out.write (template.render (path, {}))
def main ():
application = webapp.WSGIApplication (
[('/(.*html)?', MainHandler),
('/(.*unity3d)?', UnityHandler)
], debug=True)
util.run_wsgi_app (application)
它不能很好地工作,它找到了文件,但是Unity网络播放器给我一个错误的文件长度"错误.
It doesn't work quite well, it finds the file but the Unity web player give me a "bad file length" error.
那么有人可以告诉我问题出在哪里吗? 我认为这与设置内容类型"有关,但我不知道如何解决?
So can anyone tell me where the problem is ? I think it has something to do with setting the "Content-type", but i don know how to fix it ?
谢谢
Samer Samy
Samer Samy
推荐答案
我首先假设您要缩进以path =
开头的3行.
I'm going to assume, first, that you meant to indent the 3 lines starting with path =
.
第二,我猜您的意图是将URL"/"路由到WebPlayer.unity3d.但是,您的两个正则表达式都将与/匹配,因为斜杠后的所有内容都是可选的; MainHandler自发出请求以来便会收到该请求.
Second, I'm guessing your intent was to route the url "/" to WebPlayer.unity3d. However, both of your regexes will match the / since everything after the slash is optional; MainHandler will receive the request since it's first.
第三,您似乎不仅试图通过动态处理程序而且还通过模板引擎来提供静态文件.为什么?如果您只是想按原样提供静态文件,请使用静态处理程序.
Third, it looks like you're trying to serve static files not only through a dynamic handler but also through a templating engine. Why? If you're just trying to serve static files verbatim, use static handlers.
假设您已将.unity3d文件放置在名为static的目录中
Assuming you have placed your .unity3d files in a directory named static:
# render WebPlayer.unity3d on /
- url: /
static_files: static/WebPlayer.unity3d
upload: static/WebPlayer.unity3d
# match other .unity3d files
- url: /(.*\.unity3d)
static_files: static/\1
upload: static/(.*\.unity3d)
# match *.html and anything else
- url: .*
script: main.py
这篇关于Unity3d-在Google App Engine上托管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!