自己紹介
こんにちはゆずです。@Yuzu_Unity
自分はUnityエンジニア・3DCGデザイナーの学生です。(軸はエンジニア 4年ほど…)
はじめに
PhotonServerを構築し、ゲームを動かしてみたのでそれについての記事です
環境
お金 0円
電気代 ???円
サーバー(固定グローバルIP)
・OS WindowsServer2019
・MB B250m
・i5 7600
・DDR4 8GB
PhotonServer v4.0.29.11263
クライアント
Unity2019.1f1
PUN2
PhotonServer構築手順
ライセンスファイルダウンロード
https://www.photonengine.com/ja-JP/Server/pricing
Photonにてアカウントを作成後
無料ライセンスを発行し、保存します。
「メールアドレス.Photon-vX.free.100-ccu.license」
というライセンスファイルがダウンロードされます。後で使用します。
PhotonServer4を下記リンクにてexeをダウンロードします。
https://www.photonengine.com/ja-JP/sdks#server-sdkserverserver
exeファイルを開きインストール
インストールしたい場所に展開します。
今回はC直下に置きました。
ライセンスファイルを配置
展開後「Photon-OnPremise-Server-SDK_(バージョン)」フォルダが作成されます。
Photon-OnPremise-Server-SDK_(バーション)\deploy\bin_Win64を開くと(64bit版使用)
このようになっています。
ここに先程ダウンロードしたライセンスファイルを配置します。
サーバーを起動
ライセンスファイルを配置したフォルダ内にある
PhotonControl.exeを起動します。
Lisence infoが下記のようになっていればライセンスが通っています。
次にサーバーをグローバルにするかローカルにするかの設定を行います
最後にStart as applicationでサーバーを開始します。
サーバー構築完了です。
ファイアーウォール等が設定されていなければ設定しましょう。
ローカルであればLoadBalancingのRun Testclientでテスト実行できます。
connecting to (ip:port)が表示されれば成功です。
ポート開放
PhotonServerで使用されるポート番号は
PhotonServer.configファイルで定義されています。
UDP 5055/5056
TCP 4530/4531等…
クライアント側で使う接続方式のポートを変更、及び開放を行ってください。
クライアント側(Unity PUN2)
Unityにてプロジェクトを作成後、PUN2をダウンロードしインポートします。
https://assetstore.unity.com/packages/tools/network/pun-2-free-119922
PhotonServerSettingsの赤丸部分をサーバーの設定に合わせ変更します。
以上で動くことができます。
テスト
PhotonServer建てたのでテスト
— ゆず (@Yuzu_Unity) 2019年6月20日
RPCで弾同期
Unity2019.1
PUN2 pic.twitter.com/wq9f7YbjMG
上記ゲーム実行時(10接続)
CPU使用率3%ほど
メモリもほとんど食わない
ネットワークは500kbpsほど
参考サイト
https://qiita.com/pollenjp/items/38ae66aa1aac684b46ea
https://connect.unity.com/p/pun2deshi-meruonraingemukai-fa-ru-men-sono1
https://doc.photonengine.com/ja-jp/pun/v2/getting-started/pun-intro
最後に
ビルドなしで簡単に構築ができるのでとても良い…
MUNも試してみたがなぜかWin64ビルド通らない…(C#)