5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity PhotonServerV4構築からPUN2接続までの流れ

Last updated at Posted at 2019-06-25

自己紹介

こんにちはゆずです。@Yuzu_Unity
自分はUnityエンジニア・3DCGデザイナーの学生です。(軸はエンジニア 4年ほど…)

はじめに

PhotonServerを構築し、ゲームを動かしてみたのでそれについての記事です
image.png

環境

お金 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にてアカウントを作成後
無料ライセンスを発行し、保存します。

image.png
「メールアドレス.Photon-vX.free.100-ccu.license」
というライセンスファイルがダウンロードされます。後で使用します。
image.png

PhotonServer4を下記リンクにてexeをダウンロードします。

https://www.photonengine.com/ja-JP/sdks#server-sdkserverserver
image.png

exeファイルを開きインストール

インストールしたい場所に展開します。
今回はC直下に置きました。
aa.png

ライセンスファイルを配置

展開後「Photon-OnPremise-Server-SDK_(バージョン)」フォルダが作成されます。
Photon-OnPremise-Server-SDK_(バーション)\deploy\bin_Win64を開くと(64bit版使用)
image.png
このようになっています。
ここに先程ダウンロードしたライセンスファイルを配置します。

サーバーを起動

ライセンスファイルを配置したフォルダ内にある
PhotonControl.exeを起動します。
Lisence infoが下記のようになっていればライセンスが通っています。
image.png

次にサーバーをグローバルにするかローカルにするかの設定を行います
image.png
最後にStart as applicationでサーバーを開始します。
image.png

サーバー構築完了です。
ファイアーウォール等が設定されていなければ設定しましょう。
ローカルであれば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の赤丸部分をサーバーの設定に合わせ変更します。
dddd.png

以上で動くことができます。
テスト


上記ゲーム実行時(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#)

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?