Unity에서 만든 WebGL 게임을 Rails와 Heroku로 공개하는 절차

7915 단어 경 6Railscloud9Unity
Tutorial의 3장의 내용을 근거로 Unity로 만든 것(일단 하늘 장면)을 표시할 수 있도록 한다

설정



일본어 버전과 영어 버전에 차이가 없을 것 같습니다.
rails app作成
$ cd ~/workspace
$ rails _5.1.2_ unitywebapp
$ cd unitywebapp/

Gemfile을 사경
source 'https://rubygems.org'

gem 'rails',        '5.1.2'
gem 'puma',         '3.9.1'
gem 'sass-rails',   '5.0.6'
gem 'uglifier',     '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks',   '5.0.1'
gem 'jbuilder',     '2.7.0'

group :development, :test do
  gem 'sqlite3', '1.3.13'
  gem 'byebug',  '9.0.6', platform: :mri
end

group :development do
  gem 'web-console',           '3.5.1'
  gem 'listen',                '3.0.8'
  gem 'spring',                '2.0.2'
  gem 'spring-watcher-listen', '2.0.1'
end

group :test do
  gem 'rails-controller-testing', '1.0.2'
  gem 'minitest-reporters',       '1.1.14'
  gem 'guard',                    '2.13.0'
  gem 'guard-minitest',           '2.4.4'
end

group :production do
  gem 'pg', '0.18.4'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

bundler 때때로 Gemfile의 설정을 반영
$ bundle update
$ bundle install --without production

Git을 초기화하고 여기까지 커밋
$ git init
$ git add -A
$ git commit -m "add: first commit."

bitbucket에 push
bitbucketにgit push
$ git remote add origin [email protected]:[ユーザー名]/unitywebapp.git
$ git push -u origin --all

우선 Hello, World! Heroku에서 확인할 수 있도록

app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  def hello
    render html: "hello, world!"
  end
end

config/routes.rb
Rails.application.routes.draw do
  root 'application#hello'
end

Git에게 여기까지 커밋하고 Heroku에게 push
$ git commit -am "add: display hello, world!"
$ git push
$ heroku create
$ git push heroku master

지난번 는 여기에서 집착했지만 이번에는 문제 없게 갔다.

다만 여기까지 몇 번이나 Heroku 앱을 만들어 버렸기 때문에 앱 제한 5개(무료 계정이므로...)에 걸렸기 때문에 불필요한 것을 삭제했다.

서버측 작성



여기에서 조금 튜토리얼에서 벗어난다.
$ rails generate controller Game index
$ git add -A
$ git commit -m "add: game controller."
$ git push -u origin master

우선 게임 화면만 있으면 좋을까라는 것으로 index만 작성

다음으로 게임 건설 예정지가되는 index.html 작성

/public/index.html
<html>
  <body>
  Hello,World!
  </body>
</html>

controller를 편집하여 index.html을 호출하는 함수 index를 추가하고 routes를 편집하여이 index를 표시합니다.

/app/controllers/game_controller.rb
class GameController < ApplicationController
  def index
    render file: 'public/index.html'
  end
end

/config/routes.rb
Rails.application.routes.draw do
  match '*all', to: 'game#index', via: [:get]
  root 'game#index'
end

미리보기에서 확인할 수 있다면 master와 heroku에게 push.
$ git push heroku master

클라이언트측 작성



여기에 일단 Bitbucket에서이 저장소를 복제합니다.
git clone [email protected]:[ユーザー名]/unitywebapp.git

※어쩌면 상기로 갈 수 있을 것. 갈 수 있는 것은 SourceTree 제휴해 HTTPS로 클론해 버렸기 때문.

※후술하지만, Windows 유저는 멀티바이트 문자열을 포함한 패스 이하로는 하지 않는 것이 좋을지도

그리고/app와 함께 새 단장에 unity 폴더를 만듭니다. 구성적으로는 다음과 같이 되어 있을 것.
  • unitywebapp(workspace)
  • app
  • controllers
    ...

  • public
  • unity
  • Assets



  • Unity를 시작할 때 New Project하여 위의 unity 폴더를 프로젝트 폴더로 만듭니다.

    우선 확인할 수 있는 화면을 만든다.



    이것을 File>Build Settings에서 webGL로 Switch Platform하고 나서 Buil&Run한다.

    이 때, Build 출력은 (workspace)/public로 한다



    Build&Run이 성공적으로 성공하면 webGL 버전의 게임 화면을 볼 수 있습니다.



    ※ Unity2017.2.0.f3에서 Windows의 멀티바이트를 포함한 경로에 두면 webGL 출력시에 에러가 되었다.

    이 시점에서의 구성은 다음과 같아야 한다.
    public 아래에 webGL 앱의 빌드 결과가 출력되고 index.html이 덮어쓰여져야 합니다.
  • unitywebapp(workspace)
  • app
  • controllers

  • ...
  • public
  • Build <-- New!
  • TemplateData <-- New!
  • index.html <-- update!
  • ...

  • unity
  • Assets



  • 여기까지 오면 나머지는 커밋하고 master에 push하고, cloud9에서 확인하고 heroku에 push하는 것만으로 ok가 된다.

    ※로컬로부터 직접 push해도 좋을까라고 생각했지만 일단 staging하는 기분으로 c9에 push했다.

    참고



    Rails Tutorial Capter3.(일본어판): 
    htps // // ls 1개 l. jp / cha p rs / s 들 c_ 퍼게 s?ゔぇ시온 = 5. 1 # 챠 s c_ 파게 s

    Cloud9 환경에서 Ruby on Rails, Heroku를 사용하여 UnityWebGL 작품을 게시하는 방법
    htps : // 이 m / 가나타 _ 미라이 /

    좋은 웹페이지 즐겨찾기