Unityでブラウザゲームを作る設定、注意点です。
Unityでブラウザゲームを作る設定、注意点
インストール
そもそもWebGLに対応したバージョンがインストールされている必要があります。
Build
プロジェクトを作ったら、File>Build SettingからWebGLを選択します。
コンパイル
出力先フォルダをつくり「File>Build And Run」でフォルダを指定すると生成されます。
コンパイルが終わるとブラウザが起動してページが開きます。
ボタンを押すだけのものでトータル8MBぐらい?。
注意点
画面を縦長にする場合
縦長をメインにするなら「Game」タブで「Free Aspect」を変更。「720x1280」などにする。
またコンパイルすると解像度変更が反映されていないので、「Build Setting>PlayerSetting>Player>Resolution and Presentation」のResolutionを変更しておく必要があります。
【Unity】WebGLでゲームを公開するときにUIが変になったときの対処法 #Unity - Qiita
日本語フォントで日本語表示
日本語表示はやはり厳しいのでフォントを埋め込んだ形式のほうがよさそうです。
やり方はこちらを参照。
UnityのWebGLで日本語を表示する #Unity - Qiita
フォントはNoto sans japaneseとかがいいのかも。
Noto Sans Japanese - Google Fonts
Text(TMP)への埋め込みですが、「Window>TextMeshPro>Font Asset Creator」を起動。
NotoSansJでキャラクターセットを作って保存。
これでText(TMP)のインスペクタで、Font Assetへ割り当てできます。日本語表示がゲーム画面で確認できればOK。
フォント埋め込み版でシンプルなボタンのブラウザゲームを作ると17MBぐらいでした。
Unable to parse?
Build and Runでは動くのに、ネットにアップしたら動かないという場合です。
Unable to parse Build/WEBGL.framework.js.br! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header "Content-Encoding: br" present. Check browser Console and Devtools Network tab to debug.
Compression FormatをDisabledにします。
Content-type?
表示はされるが以下の警告が一度出るというものです。
HTTP Response Header "Content-Type" configured incorrectly on the server for file Build/WEBGL.wasm , should be "application/wasm". Startup time performance will suffer.
これはWasmのマイムタイプが指定されていないため。
ルートにある「.htaccess」で
AddType application/wasm wasm
を追加。
UnityのWebGLでwasmのMIMEに関して表示される警告を回避する #Unity - Qiita
またWebGL.loader.jsで以下の部分を消すと、警告メッセージ表示を消せます。
if (typeof message === 'string' && message.indexOf('wasm streaming compile failed') != -1) {
if (message.toLowerCase().indexOf('mime') != -1) {
// showBanner('HTTP Response Header "Content-Type" configured incorrectly on the server for file ' + Module.codeUrl + ' , should be "application/wasm". Startup time performance will suffer.', 'warning');
} else {
//showBanner('WebAssembly streaming compilation failed! This can happen for example if "Content-Encoding" HTTP header is incorrectly enabled on the server for file ' + Module.codeUrl + ', but the file is not pre-compressed on disk (or vice versa). Check the Network tab in browser Devtools to debug server header configuration.', 'warning');
}
}
Question - HTTP Response Header "Content-Type" configured incorrectly... - Unity Forum