python - Unity3d - 在 Google App Engine 上托管

标签 python google-app-engine unity-game-engine

我在 GAE 上托管我的 Unity3d Web 应用程序时遇到问题。 当应用程序加载并且网络播放器开始请求 ".unity3d"文件时,我使用以下 python 脚本进行 HTTP 响应:

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 网络播放器给我一个“文件长度错误”的错误。

谁能告诉我问题出在哪里? 我认为这与设置“内容类型”有关,但我不知道如何解决?

谢谢,

萨默萨米

最佳答案

首先,我假设您打算缩进以 path = 开头的 3 行。

其次,我猜您的意图是将 url“/”路由到 WebPlayer.unity3d。但是,您的两个正则表达式都将与/匹配,因为斜线后的所有内容都是可选的; MainHandler 将收到请求,因为它是第一个。

第三,看起来您不仅要通过动态处理程序而且还要通过模板引擎来提供静态文件。为什么?如果您只是想逐字提供静态文件,请使用 static handlers .

假设您已将 .unity3d 文件放在名为 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

关于python - Unity3d - 在 Google App Engine 上托管,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7390954/

相关文章:

java - Google App Engine - 需要在本地主机上使用 SSL 来开发 Canvas 应用程序

android - 具有列表或数组参数的端点 API 方法

python - Kivy:奇怪的 Button on_touch_down 行为?

python - conda install -c bioconda simlord |不满意错误

java - 尝试创建 Memcache 对象时 Google App Engine (Java) 中出现异常

c# - 认知服务。 Azure 端点不工作

android - 从点云生成深度图

python - 我正在使用 Pylons 并遇到 response.set_cookie 问题

python - 如何修复内部网格 - Matplotlib 子图

android - 集成到不同 Android 应用程序中的 Unity Android 在 Application.Quit() 上崩溃