浏览代码

Add multiverse integration guide in README

/main
Zhanxin Yang 2 年前
当前提交
f8ebd129
共有 14 个文件被更改,包括 6390 次插入88 次删除
  1. 4
      Assets/Prefabs/State/DSLobbyManagementState.prefab
  2. 16
      ProjectSettings/ProjectSettings.asset
  3. 224
      README.md
  4. 484
      Documentation/Images/AddMultiverseComponent.png
  5. 904
      Documentation/Images/DedicatedServerLinux.png
  6. 418
      Documentation/Images/MultiverseStep1.png
  7. 376
      Documentation/Images/MultiverseStep2.png
  8. 421
      Documentation/Images/MultiverseStep3.png
  9. 374
      Documentation/Images/MultiverseStep4.png
  10. 528
      Documentation/Images/MultiverseStep5.png
  11. 574
      Documentation/Images/MultiverseStep6.png
  12. 153
      Documentation/Images/MultiverseStep7.png
  13. 1001
      Documentation/Images/MultiverseStep8.png
  14. 1001
      Documentation/Images/MultiverseStep9.png

4
Assets/Prefabs/State/DSLobbyManagementState.prefab


m_Component:
- component: {fileID: 8317007143651163113}
- component: {fileID: 8885455575253120871}
- component: {fileID: 7423112830301567622}
- component: {fileID: 6837825294422450138}
m_Layer: 0
m_Name: DSLobbyManagementState
m_TagString: Untagged

TypeName: Unity.Multiplayer.Samples.BossRoom.Shared.ApplicationController
autoRun: 1
autoInjectGameObjects: []
--- !u!114 &7423112830301567622
--- !u!114 &6837825294422450138
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

16
ProjectSettings/ProjectSettings.asset


height: 1
m_SplashScreenLogos: []
m_VirtualRealitySplashScreen: {fileID: 0}
m_ShowUnitySplashAds: 0
m_AdsAndroidGameId:
m_AdsIosGameId:
m_ShowSplashAdsSlogan: 0
m_SloganImage: {fileID: 0}
m_SloganHeight: 150
m_HolographicTrackingLossScreen: {fileID: 0}
defaultScreenWidth: 1024
defaultScreenHeight: 768

hideHomeButton: 0
submitAnalytics: 1
usePlayerLog: 1
autoStreaming: 0
useAnimationStreaming: 0
useFontStreaming: 0
autoStreamingId:
instantGameAppId:
bakeCollisionMeshes: 0
forceSingleInstance: 0
useFlipModelSwapchain: 1

enable360StereoCapture: 0
isWsaHolographicRemotingEnabled: 0
enableFrameTimingStats: 0
enableOpenGLProfilerGPURecorders: 1
resetResolutionOnWindowResize: 0
androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1
applicationIdentifier:

ps4videoRecordingFeaturesUsed: 0
ps4contentSearchFeaturesUsed: 0
ps4CompatibilityPS5: 0
ps4AllowPS5Detection: 0
ps4GPU800MHz: 1
ps4attribEyeToEyeDistanceSettingVR: 0
ps4IncludedModules: []

m_VersionName:
apiCompatibilityLevel: 6
activeInputHandler: 0
cloudProjectId:
cloudProjectId: e7e562fb-7fec-4d0b-a960-f472ebcac66b
framebufferDepthMemorylessMode: 0
qualitySettingsNames: []
projectName:

224
README.md


![Banner](Documentation/Images/Banner.png)
# Boss Room - Co-op multiplayer RPG built with Unity Netcode for GameObjects
| Solutions architects are available on [Discord](https://discord.gg/mNgM2XRDpb) and [forums](https://forum.unity.com/forums/multiplayer.26/) to help you work through issues you may encounter when using Boss Room. |
| -- |
Boss Room is a fully functional co-op multiplayer RPG made with Unity Netcode. It is built to serve as an educational sample that showcases certain typical gameplay [patterns](https://docs-multiplayer.unity3d.com/netcode/current/learn/bossroom-examples/bossroom-actions) that are frequently featured in similar networked games.
# Boss Room - 基于Unity Netcode for GameObjects开发的多人RPG游戏
You can use everything in this project as a starting point or as bits and pieces in your own Unity games. The project is licensed under the Unity Companion License. See [LICENSE.md](LICENSE.md) for more legal information.
Boss Room是一个基于Unity Netcode开发的多人协作RPG游戏。它是作为一个在网络游戏中的常见[游戏模式](https://docs-multiplayer.unity3d.com/netcode/current/learn/bossroom-examples/bossroom-actions)的示例游戏开发出来的。
See [ART_NOTES.md](Documentation/ART_NOTES.md) for more information on the art of Boss Room.
你可以在你自己的Unity游戏中使用这个项目中的任何素材和代码。该项目基于[Unity Companion License](LICENSE.md)开发。
> __IMPORTANT__:
> - Boss Room has been developed and tested on these Platforms (Windows, Mac, iOS, and Android).
> - Tested on iPhone 6 and Pixel 3.
> - Boss Room is compatible with the latest Unity LTS version.
> - Make sure to include standalone support for Windows/Mac in your installation.
> 重要提醒:
> - Boss Room目前已经支持在以下平台上开发和测试 (Windows, Mac, iOS, 和Android).
> - Boss Room目前支持最新的Unity LTS版本.
> - 在安装Unity Editor时请确保安装了Windows/Mac单独支持。如需要专用游戏服务器的支持,还需要安装Windows/Linux Dedicated Server支持。(Linux还需要安装IL2CPP和Mono的Build支持)
![](Documentation/Images/Players.png)
## Getting the project
- The pre-release version can be downloaded from the [Releases](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/releases) page.
- Alternatively: click the green `Code` button and then choose to download the zip archive. Remember, that you would download the branch that you are currently viewing in Github.
- For Windows users: Using Windows' built-in extracting tool may generate a "Error 0x80010135: Path too long" error window which can invalidate the extraction process. A workaround for this is to shorten the zip file to a single character (eg. "c.zip") and move it to the shortest path on your computer (most often right at C:\\) and retry. If that solution fails, another workaround is to extract the downloaded zip file using 7zip.
## Installing Git LFS to clone locally
![](Documentation/Images/Players.png)
This project uses Git Large Files Support (LFS), which ensures all large assets required locally are handled for the project. See [Git LFS installation options](https://github.com/git-lfs/git-lfs/wiki/Installation) for Windows and Mac instructions.
## 获取项目文件
## Registering the project with Unity Gaming Services (UGS)
This project leverages several services from UGS to facilitate connectivity between players. In order to use these services inside your project, one must first [create an organization](https://support.unity.com/hc/en-us/articles/208592876-How-do-I-create-a-new-Organization-) inside Unity Dashboard, and enable both the [Relay](https://docs.unity.com/relay/get-started.html) and [Lobby](https://docs.unity.com/lobby/game-lobby-sample.html) services. Otherwise, Boss Room can still be used without UGS.
- 该工程可以在[BossRoomDGS PlasticSCM](https://plastichub.unity.cn/unity-tech-cn/BossRoomDGS)中选择`Download Repository`在Unity Hub中下载。
## Opening the project for the first time
## 第一次打开项目文件
Once you have downloaded the project, the steps below should get you up and running:
- Make sure you have installed the version of Unity that is listed above in the prerequisites section.
- Make sure to include standalone support for Windows/Mac in your installation.
- Add the project in _Unity Hub_ by clicking on **Add** button and pointing it to the root folder of the downloaded project.
- The first time you open the project Unity will import all assets, which will take longer than usual - it is normal.
- Once the editor is ready, navigate to the _Project_ window and open the _Project/Startup_ scene.
下载好项目文件后,请按照一下步骤来打开和运行游戏:
- 确保安装了推荐版本`2021.3.6f1`或更新的Unity Editor。
- 确保安装了Windows/Mac单独支持。
- 确保安装了Windows/Linux Dedicated Server支持。
- 确保安装了Linux IL2CPP和Mono的Build支持。
- 第一次打开项目时Unity会导入所有的资源文件,这可能会花费较长的时间。
- 当Editor导入结束后,在 _Project_ 窗口中打开 _Project/Startup_ 场景
- From there you can click the **Play** button. You can host a new game or join an existing game using the in-game UI.
- 在此场景中可以点击 **Play** 来运行游戏。
## Testing multiplayer
## 测试多人游戏
In order to see the multiplayer functionality in action we can either run multiple instances of the game locally on your computer, using either ParrelSync or builds or choose to connect to a friend over the internet. See [how to test](https://docs-multiplayer.unity3d.com/netcode/current/tutorials/testing/testing_locally) for more info.
为了测试多人游戏联机功能我们可以在开发机上运行多个游戏实例,可以使用`ParrelSync`,也可以通过网络与朋友进行联机,详见[如何测试](https://docs-multiplayer.unity3d.com/netcode/current/tutorials/testing/testing_locally)
**Local multiplayer setup**
### 本地多人游戏配置
First we need to build an executable.
To build an executable, press _File/Build Settings_ in the menu bar, and then press **Build**.
首先我们需要编译出一个可执行程序,在菜单中找到 _File/Build Settings_ 然后点击 **Build**
Once the build has completed you can launch several instances of the built executable in order to both host and join a game.
编译完成后就可以在本地运行多个游戏实例来做主机和从机。
> Mac users: to run multiple instances of the same app, you need to use the command line.
> Run `open -n BossRoom.app`
> Mac用户要运行一个程序的多个实例需要在命令行下执行 `open -n BossRoom.app`
**Multiplayer over internet**
### 公网上的多人游戏配置
To play over internet, we need to build an executable that is shared between all players. See the previous section.
要在公网上实现多人联机,首先需要将可执行文件共享给所有玩家。参考上一部分。
It is possible to connect between multiple instances of the same executable OR between executables and the editor that produced said executable.
其次则需要有中转网络通信的手段,目前可以有两种选择:
* 使用一个Relay服务器来进行中转,目前Boss Room提供了[Unity Relay](https://docs-multiplayer.unity3d.com/netcode/current/relay/relay)的支持。
* 将Boss Room编译成Headless专用游戏服务器,使用[Multiverse](https://multiverse-test.scaling.unity.cn)来托管一个专用的游戏服务器进行中转。
Running the game over internet currently requires setting up a relay. Boss Room provides an integration with [Unity Relay](https://docs-multiplayer.unity3d.com/netcode/current/relay/relay).
---------------
### 专用游戏服务器
> Checkout our Unity Relay setup guide [here](https://docs-multiplayer.unity3d.com/netcode/current/relay/relay)
目前Boss Room支持专用游戏服务器模式,可以支持运行一个无玩家的Headless的服务器。请按照以下步骤进行编译:
1. 在菜单中找到 _File/Build Settings_ 并将编译目标切换成 **Dedicated Server**,目标平台选择 **Windows** 或者 **Linux**
![](Documentation/Images/DedicatedServerLinux.png)
2. 切换好编译目标后(第一次可能会花较长时间),点击 **Build**
3. 编译完成后,执行编译出的可执行文件(命令行支持`-port=`的参数来指定服务器监听的端口)。
4. 打开游戏可执行文件,在`Direct IP`模式下连接127.0.0.1的默认端口即可进行联机。
Alternatively you can use Port Forwarding. The https://portforward.com/ site has guides on how to enable port forwarding on a huge number of routers. Boss Room uses `UDP` and needs a `9998` external port to be open. Make sure your host's address listens on 0.0.0.0 (127.0.0.1 is for local development only).
编译出的专用游戏服务器可以上传至游戏服务器托管服务(如[Multiverse](https://multiverse-test.scaling.unity.cn))。
---------------
### Dedicated Server
## 与Multiverse进行集成
Boss Room has a dedicated server mode, allowing you to use it as a headless server with no player running on it. To run it:
Multiverse是一个基于Kubernetes的游戏服务器托管服务。游戏开发者可以将自己的游戏服务器打包成Docker镜像,方便地进行弹性的游戏服务器运行/销毁。
Local testing
1. Switch your editor to the **Dedicated Server** build target.
2. Hit play. Boss Room will bypass the main menu and enter directly the character select scene and wait for players.
3. On a clone or build, connect your client to 127.0.0.1 with default port.
> 重要提醒:
> 目前Multiverse只支持Linux的Docker镜像。
A build can be uploaded to a dedicated server hosting provider (for example [Multiplay](https://unity.com/products/multiplay)).
On Multiplay, please use these launch parameters: ```-port=$$port$$ -logFile $$server_log_dir$$/Engine.log```
以Boss Room游戏为例,请按照以下步骤来将你的游戏与Multiverse进行集成:
For more info on dedicated servers and why you'd want to use this, see our docs site!
<!--TODO link to DGS doc page -->
### 集成Multiverse SDK
------------------------------------------
**Multiverse SDK**是游戏服务器用来维护在Multiverse中的状态和生命周期的。
## Exploring the project
BossRoom is an eight-player co-op RPG game experience, where players collaborate to take down some minions, and then a boss. Players can select between classes that each have skills with didactically interesting networking characteristics. Control model is click-to-move, with skills triggered by mouse button or hotkey.
> 重要提醒:
> 目前Multiverse只提供了Unity的SDK(其他语言的SDK会陆续放出)。
One of the eight clients acts as the host/server. That client will use a compositional approach so that its entities have both server and client components.
1. 将Unity SDK的代码添加到Unity Project中。
2. 给专用游戏服务器的运行入口添加Multiverse SDK的依赖。修改`Assets/Scripts/Gameplay/Unity.BossRoom.Gameplay.asmdef`:
```json
"references": [
...
...
"Unity.BossRoom.ConnectionManagement",
"VContainer",
"Unity.Cn.Multiverse"
],
```
The game is server-authoritative, with latency-masking animations. Position updates are done through NetworkedVars that sync position, rotation and movement speed. NetworkedVars and Remote Procedure Calls (RPC) endpoints are isolated in a class that is shared between the server and client specialized logic components. All game logic runs in FixedUpdate at 30 Hz, matching our network update rate.
3. 在Unity Editor Project窗口,搜索`DSLobbyManagementState`, 给专用游戏服务器的运行入口`DSLobbyManagementState(Prefab Asset)`添加一个`Multiverse SDK`的组件。
![](Documentation/Images/AddMultiverseComponent.png)
Code is organized into three separate assemblies: **Client**, **Shared** and **Server** which reference each other when appropriate.
4. 修改`DSLobbyManagementState.cs`,添加MultiverseSDK的初始化代码。
```csharp
using VContainer;
using Unity.Cn.Multiverse;
...
...
public class DSLobbyManagementState : GameStateBehaviour
{
[Inject]
ConnectionManager m_ConnectionManager;
public override GameState ActiveState => GameState.DedicatedServerLobbyManagement;
private MultiverseSdk m_Multiverse = null;
...
...
IEnumerator StartServerCoroutine()
{
DedicatedServerUtilities.Log($"Starting Headless Server, listening on address {address}:{port}");
m_ConnectionManager.StartServerIP(address, port); // This will switch to the char select scene once the server started callback has been called
For an overview of the project's architecture please check out our [ARCHITECTURE.md](ARCHITECTURE.md).
// Start the multiverse SDK
StartMultiverse();
---------------
yield return new WaitForServerStarted(); // Less performant than just the callback, but way more readable than a callback hell.
For a deep dive in Unity Netcode and Boss Room, visit our [doc](https://docs-multiplayer.unity3d.com/) and [Unity Multiplayer Resources](https://docs-multiplayer.unity3d.com/netcode/current/learn/introduction) sections.
// TODO change scene to char select here and do other init. why is it handled by connection manager right now?
SceneLoaderWrapper.Instance.AddOnSceneEventCallback();
SceneLoaderWrapper.Instance.LoadScene(SceneNames.CharSelect, useNetworkSceneManager: true);
}
...
...
private async void StartMultiverse()
{
m_Multiverse = GetComponent<MultiverseSdk>();
bool ok = await m_Multiverse.Connect();
if (ok)
{
Debug.Log(("Server - Connected"));
}
else
{
Debug.Log(("Server - Failed to connect, exiting"));
Application.Quit(1);
}
## Bite-size Samples
This repository contains a collection of bitesize sample projects and games that showcase different sub-features of NGO. You can review these samples with documentation to understand APIs and features better.
- [Our various bitesize samples](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize)
ok = await m_Multiverse.Ready();
if (ok)
{
Debug.Log($"Server - Ready");
}
else
{
Debug.Log($"Server - Ready failed");
Application.Quit();
}
}
```
## Contributing
### 编译游戏服务器
The project uses the `git-flow` branching strategy, as such:
- `develop` branch contains all active development
- `main` branch contains release versions
1. 在菜单中找到 _File/Build Settings_ 并将编译目标切换成 **Dedicated Server**,目标平台选择 **Linux**
![](Documentation/Images/DedicatedServerLinux.png)
2. 切换好编译目标后(第一次可能会花较长时间),点击 **Build** ,并保存为`BossRoom.x86_64`。
3. 将编译出的目录打包成zip文件:`BossRoom.zip`(打包时请保持`BossRoom.x86_64`文件在zip包根目录)。
To get the project on your machine you need to clone the repository from GitHub using the following command-line command:
```
git clone https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop.git
```
### 创建Multiverse Game
> __IMPORTANT__:
> You should have [Git LFS](https://git-lfs.github.com/) installed on your local machine.
1. 在[Multiverse快速向导](https://multiverse-test.scaling.unity.cn/console/start)中开始Multiverse Game的创建。注意:由于docker镜像名字的限制,游戏名称暂时不可以包含大写字母。
![](Documentation/Images/MultiverseStep1.png)
2. 创建游戏档案。
![](Documentation/Images/MultiverseStep2.png)
3. 创建游戏镜像。注意:容器端口填游戏服务器的默认端口`9998`。可执行文件填`BossRoom.x86_64`,该参数指的是游戏服务器可执行文件在zip包中的相对路径。在选择游戏包中选择刚才打包好的`BossRoom.zip`。上传结束后,点击`创建游戏镜像`。创建结束后,点击`提交游戏镜像`来将该镜像用于正式游戏服务器托管。
![](Documentation/Images/MultiverseStep3.png)
4. 创建游戏地域。
![](Documentation/Images/MultiverseStep4.png)
5. 创建并启用游戏档案可用区。
![](Documentation/Images/MultiverseStep5.png)
Please check out [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on submitting issues and PRs to BossRoom!
### 在Multiverse中创建游戏服务器
For further discussion points and to connect with the team, join us on the Unity Multiplayer Networking Discord Server - Channel #dev-samples
1. 在Multiverse游戏服务器面板,点击 **分配游戏服务器** ,创建一个指定游戏档案的游戏服务器。
![](Documentation/Images/MultiverseStep6.png)
2. 刷新游戏服务器列表,获取刚刚建立的游戏服务器地址。
![](Documentation/Images/MultiverseStep7.png)
3. 打开Boss Room游戏客户端,在 **Join With IP** 面板,输入刚刚获得的地址。(可打开两个客户端一起游玩)。
![](Documentation/Images/MultiverseStep8.png)
4. 双方都加入后,即可联网进行游戏。
![](Documentation/Images/MultiverseStep9.png)
[![Discord](https://img.shields.io/discord/449263083769036810.svg?label=discord&logo=discord&color=informational)](https://discord.gg/FM8SE9E)
> 关于Multiverse的详细文档,请参见https://xxxx

484
Documentation/Images/AddMultiverseComponent.png

之前 之后
宽度: 854  |  高度: 1152  |  大小: 113 KiB

904
Documentation/Images/DedicatedServerLinux.png

之前 之后
宽度: 1286  |  高度: 1330  |  大小: 168 KiB

418
Documentation/Images/MultiverseStep1.png

之前 之后
宽度: 1490  |  高度: 1549  |  大小: 153 KiB

376
Documentation/Images/MultiverseStep2.png

之前 之后
宽度: 1297  |  高度: 1589  |  大小: 153 KiB

421
Documentation/Images/MultiverseStep3.png

之前 之后
宽度: 2828  |  高度: 1670  |  大小: 187 KiB

374
Documentation/Images/MultiverseStep4.png

之前 之后
宽度: 1348  |  高度: 1366  |  大小: 139 KiB

528
Documentation/Images/MultiverseStep5.png

之前 之后
宽度: 1553  |  高度: 1573  |  大小: 181 KiB

574
Documentation/Images/MultiverseStep6.png

之前 之后
宽度: 2901  |  高度: 1160  |  大小: 213 KiB

153
Documentation/Images/MultiverseStep7.png

之前 之后
宽度: 2370  |  高度: 281  |  大小: 51 KiB

1001
Documentation/Images/MultiverseStep8.png
文件差异内容过多而无法显示
查看文件

1001
Documentation/Images/MultiverseStep9.png
文件差异内容过多而无法显示
查看文件

正在加载...
取消
保存