# Mirror Cloud Services
## Mirror List Server
Example has an API key which can be used as a demo.
To get an API key to use within your game you can subscribe on the [Mirror Networking Website](https://mirror-networking.com/list-server/)
### Key features
- The Cloud Service works via https so it is secure and can be used from any platform.
- It runs on Google Cloud so there is no worry about server downtime.
- It scales really well. Default quota is 1000 API requests per minute. If you have high demands, contact us and we can increase that limit.
## List Server Examples
An example for this can be found in [Mirror/Examples/Cloud/](https://github.com/vis2k/Mirror/tree/master/Assets/Mirror/Examples/Cloud)
*Note: you cannot connect to your own public IP address, you will need at least one other person to test this*
## How to use
Add `ApiConnector` component to an object in your game. It is probably best to put this on the same object as your NetworkManager. Once it has been added set the `ApiAddress` and `ApiKey` fields.
To use `ApiConnector` either directly reference it in an inspector field or get it when your script awakes
```cs
ApiConnector connector;
void Awake()
{
connector = FindObjectOfType<ApiConnector>();
}
```
The Api calls are grouped into objects. `connector.ListServer.ServerApi` has the Server Api calls like `AddServer`. `connector.ListServer.ClientApi` has the Client Api calls like `GetServerList`.
### Server Api Example
Example of how to add server
```cs
void AddServer(int playerCount)
{
Transport transport = Transport.activeTransport;
Uri uri = transport.ServerUri();
int port = uri.Port;
string protocol = uri.Scheme;
connector.ListServer.ServerApi.AddServer(new ServerJson
{
displayName = "Fun game!!!",
protocol = protocol,
port = port,
maxPlayerCount = NetworkManager.singleton.maxConnections,
playerCount = playerCount
});
}
```
### Client Api Example
Example of how to list servers
```cs
ApiConnector connector;
void Awake()
{
connector = FindObjectOfType<ApiConnector>();
// add listener to event that will update UI when Server list is refreshed
connector.ListServer.ClientApi.onServerListUpdated += onServerListUpdated;
// add listen to button so that player can refresh server list
refreshButton.onClick.AddListener(RefreshButtonHandler);
}
public void RefreshButtonHandler()
{
connector.ListServer.ClientApi.GetServerList();
}
void onServerListUpdated()
{
// Update UI here
}
```
## Debug
If something doesn't seem to be working then here are some tips to help solve the problem
### Check logs
Enable `showDebugMessages` on your NetworkManager or use the log level window to enable logging for the cloud scripts
Below are some example logs to look for to check things are working.
#### Add Server
The add request is sent to add a server to the list server
```
Request: POST servers {"protocol":"tcp4","port":7777,"playerCount":0,"maxPlayerCount":4,"displayName":"Tanks Game 521","address":"","customAddress":"","customData":[]}
```
```
Response: POST 200 /servers {"id":"BI6bQQ2TbNiqhdp1D7UB"}
```
#### Update Server
The object sent in update request maybe be empty, this is sent to keep the server record alive so it shows up.
The update request can also be used to change info. For example the player count when someone joins or leaves
```
Request: PATCH servers/BI6bQQ2TbNiqhdp1D7UB {}
```
```
Response: PATCH 204 /servers/BI6bQQ2TbNiqhdp1D7UB
```
#### Remove Server
The remove request is sent to remove a server from the list server. This is automatically called when the ApiConnection is destroyed.
```
Request: DELETE servers/BI6bQQ2TbNiqhdp1D7UB
```
```
Response: DELETE 204 /servers/BI6bQQ2TbNiqhdp1D7UB
```
#### Get Servers
The get request is sent in order to get the list of servers.
The example below shows an array of 2 servers, one with name `Tanks Game 521` and the other with name `Tanks Game 212`
```
Request: GET servers
```
```
Response: GET 200 /servers {"servers":[{"address":"tcp4://xx.xx.xx.xx:7777","displayName":"Tanks Game 521","port":7777,"protocol":"tcp4","playerCount":0,"maxPlayerCount":4,"customAddress":"","customData":[]},{"address":"tcp4://xx.xx.xx.xx:7777","displayName":"Tanks Game 212","port":7777,"protocol":"tcp4","playerCount":0,"maxPlayerCount":4,"customData":[]}]}
```
*xx.xx.xx.xx will be the IP address for the server*
### Use the QuickListServerDebug
The QuickListServerDebug script uses `OnGUI` to show the list of servers. This script can be used to check the server list without using Canvas UI.
没有合适的资源?快使用搜索试试~ 我知道了~
多人同时在线游戏Unity源码
共1255个文件
meta:690个
cs:370个
png:41个
需积分: 0 4 下载量 161 浏览量
2024-03-11
11:38:02
上传
评论
收藏 5.52MB ZIP 举报
温馨提示
这个小程序使用的是一个基于 Windows 的 Unity 应用程序作为游戏前端。 我们还将在 Unity 中创建一个服务器应用程序,它将侦听用于连接客户端的端口。PlayFab 托管此服务器并提供附加服务(例如身份验证),使开发更加容易。 我的目的是提供一个“尽可能简单”的示例,同时涵盖使用 PlayFab 和 Mirror 的端到端客户端-服务器多人游戏设置,
资源推荐
资源详情
资源评论
收起资源包目录
多人同时在线游戏Unity源码 (1255个子文件)
Mirror.Examples.Cloud.Pong.asmdef 393B
Mirror.asmdef 366B
Mirror.Editor.asmdef 366B
Mirror.Examples.Cloud.GUI.asmdef 355B
Mirror.Examples.asmdef 350B
Mirror.Weaver.asmdef 340B
Mirror.Examples.RigidbodyPhysics.asmdef 337B
PlayFabSdkEditor.asmdef 336B
Mirror.CompilerSymbols.asmdef 328B
Mirror.Authenticators.asmdef 327B
SimpleWebTransport.asmdef 324B
PlayFabEditorExtensions.asmdef 323B
Mirror.Components.asmdef 323B
Mirror.Cloud.asmdef 318B
PlayFab.asmdef 298B
Telepathy.asmdef 293B
kcp2k.asmdef 288B
ProjectSettings.asset 19KB
QualitySettings.asset 6KB
InputManager.asset 6KB
NavMesh.asset 5KB
GraphicsSettings.asset 2KB
Physics2DSettings.asset 2KB
NavMeshAreas.asset 1KB
DynamicsManager.asset 1KB
EditorSettings.asset 1KB
PackageManagerSettings.asset 1003B
UnityConnectSettings.asset 853B
PlayFabSharedSettings.asset 777B
PlayFabEditorPrefsSO.asset 627B
AudioManager.asset 416B
TagManager.asset 378B
VFXManager.asset 308B
TimeManager.asset 202B
VersionControlSettings.asset 188B
EditorBuildSettings.asset 160B
XRSettings.asset 158B
PresetManager.asset 146B
ClusterInputManager.asset 114B
Controller.controller 7KB
Tank.controller 4KB
PlayFabEvents.cs 609KB
PlayFabClientModels.cs 279KB
PlayFabServerModels.cs 241KB
PlayFabAdminModels.cs 239KB
PlayFabClientInstanceAPI.cs 160KB
PlayFabClientAPI.cs 158KB
PlayFabServerInstanceAPI.cs 135KB
PlayFabServerAPI.cs 134KB
PlayFabMultiplayerModels.cs 128KB
PlayFabAdminInstanceAPI.cs 114KB
PlayFabAdminAPI.cs 113KB
SimpleJson.cs 81KB
SimpleJson.cs 81KB
SimpleJson.cs 80KB
Deflate.cs 74KB
Inflate.cs 71KB
NetworkIdentity.cs 65KB
NetworkManager.cs 61KB
PlayFabMultiplayerInstanceAPI.cs 57KB
NetworkServer.cs 57KB
PlayFabMultiplayerAPI.cs 56KB
ParallelDeflateOutputStream.cs 55KB
ClientScene.cs 48KB
NetworkBehaviourProcessor.cs 46KB
GZipStream.cs 40KB
PlayFabGroupsModels.cs 36KB
Kcp.cs 33KB
PlayFabEvents.cs 32KB
PlayFabCloudScriptModels.cs 31KB
DeflateStream.cs 30KB
ZlibCodec.cs 30KB
NetworkBehaviour.cs 29KB
InfTree.cs 29KB
PlayFabEvents.cs 28KB
ZlibStream.cs 28KB
CRC32.cs 28KB
PlayFabErrors.cs 28KB
NetworkRoomManager.cs 27KB
PlayFabEvents.cs 24KB
PlayFabGroupsInstanceAPI.cs 23KB
NetworkAnimator.cs 23KB
PlayFabWebRequest.cs 23KB
PlayFabExperimentationModels.cs 22KB
PlayFabGroupsAPI.cs 22KB
ZlibBaseStream.cs 22KB
NetworkTransformBase.cs 21KB
Zlib.cs 21KB
NetworkTransformBase.cs 21KB
NetworkWriter.cs 21KB
PlayFabHTTP.cs 20KB
ZTree.cs 19KB
SyncVarProcessor.cs 18KB
PlayFabEditorSettings.cs 18KB
PlayFabEditorSDKTools.cs 18KB
NetworkClient.cs 17KB
NetworkReader.cs 17KB
PlayFabEditor.cs 16KB
PlayFabProfilesModels.cs 16KB
PlayFabEvents.cs 14KB
共 1255 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
前网易架构师-高司机
- 粉丝: 8366
- 资源: 213
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功