NetworkServer は基本的なネットワーク機能のために NetworkServerSimple を利用し、さらにゲームらしい機能を追加します。
NetworkServer は、NetworkServerSimple インスタンス経由で、リモートクライアントによるリモートの接続を処理します。また、NetworkServer にはローカルクライアントのためのローカルの接続もあります。
NetworkServer はシングルトンです。NetworkServer には NetworkServer.SendToAll() やNetworkServer.Spawn() のように自動的にシングルトンインスタンスを使う便利な静的関数があります。
NetworkManager は NetworkServer を利用しますが、NetworkManager なしで使用されることもあります。
生成されネットワークされたオブジェクトは、NetworkServer によって管理されます。オブジェクトは NetworkServer.Spawn() によってクライアント上で生成され、このセットに登録されます。生成されたオブジェクトが破棄されると、自動的にセットから削除されます。または、NetworkServer.UnSpawn() を呼び出すことによってセットから削除されます。この場合は、そのオブジェクトは破棄されせん。
NetworkServer によって使用される内部的なメッセージは多数あり、NetworkServer.Listen() が呼び出されると設定されます。
AddPlayerForConnection | AddPlayer メッセージハンドラーがプレイヤーからリクエストを受領すると、サーバーはこの関数を呼び出しプレイヤーオブジェクトと接続します。 |
BecomeHost | サーバーから切断されているクライアントが、新バージョンのゲームのホストになることを可能にします。 |
ReplacePlayerForConnection | これは別のプレイヤーオブジェクトで接続しているプレイヤーオブジェクトを置き換えます。古いプレイヤーオブジェクトは破棄されません。 |
SendBytesToReady | すべての準備ができているプレイヤーにバイト配列を送信します。 |
SendToAll | 指定されたタイプ番号で Message 構造体を接続されているすべてのクライアントに送信します。 |
SendToClient | 指定した接続 ID を持つクライアントに Message を送信します。 |
SendToClientOfPlayer | 与えられたプレイヤーオブジェクトのインスタンスを所有するクライアントにメッセージを送信します。 |
SendToReady | 指定された番号で Message 構造体を準備ができているクライアントだけに送信します。 |
SendUnreliableToAll | 指定した Message 構造体を Unreliable Message としてすべての接続されているクライアントに送信します。 |
SendUnreliableToReady | 指定した Message 構造体を Unreliable Message として準備できたクライアントにのみに送信します。 |
SendWriterToReady | 準備できているプレイヤーに NetworkWriter オブジェクトの内容を送信します。 |
Spawn | 準備できているすべてのクライアントで特定のゲームオブジェクトを生成します。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.