-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Develop into main for MPPM 1.3 (#1302)
- Loading branch information
Showing
25 changed files
with
824 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
id: about | ||
title: About Multiplayer Play Mode | ||
description: Overview of Multiplayer Play Mode | ||
--- | ||
|
||
Use Multiplayer Play Mode to test multiplayer functionality within the Unity Editor. You can simulate up to four Players (the main Editor Player and three Virtual Players) simultaneously on the same development device while using the same source assets on disk. Multiplayer Play Mode can help you create multiplayer development workflows that reduce project build times, run it locally, and test the server-client relationship. | ||
|
||
## Compatibility | ||
|
||
Multiplayer Play Mode version 1.1.0 is compatible with Unity Editor versions 6000.0.3f1 or later. | ||
|
||
## Compatibility | ||
|
||
Multiplayer Play Mode version 1.1.0 is compatible with Unity Editor versions 6000.0.3f1 or later. | ||
|
||
## Multiplayer Play Mode terminology | ||
|
||
The following have specific meaning in relation to Multiplayer Play Mode: | ||
|
||
* main Editor Player: The original instance of the project in the Unity Editor. This is the only instance with full authoring capabilities. | ||
* Virtual Players: Simulated Players created with Multiplayer Play Mode. These Players open in a separate window with limited authoring capabilities when you enter [Play mode](https://docs.unity3d.com/Manual/GameView.html). | ||
* Players: All Player instances, including the main Editor Player and all Virtual Players. | ||
|
||
## Limitations | ||
|
||
Multiplayer Play Mode has some inherent technical limitations, specifically around [scale](#scale) and [authoring](#authoring). | ||
|
||
### Scale | ||
|
||
The Unity Editor and Virtual Players require a lot of system resources, so you shouldn't use Multiplayer Play Mode at scale. Multiplayer Play Mode is designed for small-scale, local testing environments that can only support up to four total Players (the main Editor Player and three Virtual Players). | ||
|
||
### Authoring | ||
You can't create or change the properties of GameObjects in a Virtual Player. Instead, use the main Editor Player to make changes and a Virtual Player to test multiplayer functionality. Any changes you make in Play Mode in the main Editor Player reset when you exit Play Mode. | ||
:::note | ||
You can't access any main Editor Player functionality from Virtual Players. | ||
::: | ||
|
||
## Performance impact | ||
|
||
To reduce the demand on system resources caused by each Virtual Player instance, Multiplayer Play Mode shares specific resources, such as the artifact database and imports between the main Editor Player and each Virtual Player. |
27 changes: 27 additions & 0 deletions
27
mppm_versioned_docs/version-1.2.0/dedicated-server/multiplayer-role.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
id: multiplayer-role | ||
title: Assign Virtual Players to a multiplayer role | ||
description: Learn how to use the dedicated server package to assign Virtual Players to a multiplayer role. | ||
--- | ||
|
||
Install the [Dedicated Server package](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) with Multiplayer Play Mode to switch Players between the server and client role without a script. | ||
|
||
::: Important | ||
To avoid errors, install the Dedicated Server package version that is the same as the Multiplayer Play mode version that exists in your project. | ||
::: | ||
|
||
## Set the main Editor Player multiplayer role | ||
|
||
To set the role of a the main Editor Player, do the following: | ||
|
||
1. Open the Multiplayer Play Mode inspector (**Multiplayer** > **Multiplayer Play Mode**). | ||
2. In the **main Editor Player** section, expand the **Multiplayer Role** dropdown. | ||
3. Select the [multiplayer role](https://docs.unity3d.com/Packages/[email protected]/manual/multiplayer-roles.html) you want the main Editor Player to use. | ||
|
||
## Set the multiplayer role of a Virtual Player | ||
|
||
To set the role of a [Virtual Player](../../virtual-players), do the following: | ||
|
||
1. Open the Multiplayer Play Mode inspector (**Multiplayer** > **Multiplayer Play Mode**). | ||
2. In the **Virtual Players** section, expand a Virtual Player's **Multiplayer Role** dropdown. | ||
3. Select the [multiplayer role](https://docs.unity3d.com/Packages/[email protected]/manual/multiplayer-roles.html) you want this Player to use. |
17 changes: 17 additions & 0 deletions
17
mppm_versioned_docs/version-1.2.0/dedicated-server/play-mode-dedicated-server.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
id: play-mode-dedicated-server | ||
title: Use Multiplayer Play mode with a Dedicated Server | ||
description: Use the dedicated server package with multiplayer play mode. | ||
--- | ||
|
||
The [Dedicated Server package](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) adds [multiplayer roles](https://docs.unity3d.com/Packages/[email protected]/manual/multiplayer-roles.html) to the [Dedicated Server build platform](https://docs.unity3d.com/Manual/dedicated-server-introduction.html). You can use multiplayer roles to assign virtual players to a client, server, or client and server multiplayer role. | ||
|
||
<!-- | ||
<div className="table-columns-plain" > | ||
| Page | Description | | ||
</div> | ||
--> | ||
|
||
|**Page** |**Description**| | ||
|-|-| | ||
|[Debug Multiplayer Play Mode](debug-mppm.md)| Learn how to use Unity Test Framework to test a project with Multiplayer Play Mode. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
id: install | ||
title: Install Multiplayer Play Mode | ||
description: How to install Multiplayer Play Mode | ||
--- | ||
|
||
You can use Multiplayer Play Mode version 1.1.0 in Unity Editor versions 6000.0.3f1 or later. Multiplayer Play mode versions 1.0.0 and earlier are compatible with Unity version 2023.1 or later. | ||
To install the Multiplayer Play Mode package, follow these steps: | ||
|
||
1. Open Unity Hub. | ||
2. Select a Project to open it. | ||
3. In the Editor's menu bar, navigate to **Window** > **Package Manager**. | ||
4. Select **Unity Registry**. | ||
5. Select the **Multiplayer Play Mode** package. | ||
6. Select **Install**. | ||
|
||
## Next steps | ||
|
||
You can now access and configure your [Virtual Players](../virtual-players) and their [tags](../player-tags). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
id: mtt-terms | ||
title: Multiplayer Networking Terminology | ||
--- | ||
|
||
The following are essential, high-level terms used in multiplayer networking and Netcode for GameObjects: | ||
|
||
import MTTterms from '/static/shared/_terminology.md'; | ||
|
||
<MTTterms/> |
16 changes: 16 additions & 0 deletions
16
mppm_versioned_docs/version-1.2.0/player-tags/player-tags-attach.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
id: player-tags-attach | ||
title: Attach tags to a Player | ||
description: Learn how to attach tags to a Player in Multiplayer Play Mode. | ||
--- | ||
|
||
To assign one or more [tags](../../player-tags) to any Player, do the following: | ||
|
||
1. Open the Multiplayer Play mode window (**Window** > **Multiplayer Play Mode**). | ||
2. Expand the **Tags** dropdown for a Player or the main Editor Player. | ||
3. Select **+ Create Tag**. | ||
4. In the Project Settings window that appears, select the **Add** (**+**) icon. | ||
5. In the New tag field that appears, type a name for your tag. | ||
6. Select **Save**. | ||
7. In the Multiplayer Play Mode window, expand the **Tags** dropdown. | ||
8. Select the tag you just created. |
16 changes: 16 additions & 0 deletions
16
mppm_versioned_docs/version-1.2.0/player-tags/player-tags-configure.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
id: player-tags-configure | ||
title: Configure tags | ||
description: Set up tags to use them to configure the player actions. | ||
--- | ||
|
||
Tags don't do anything until you configure them. To configure a tag, do the following: | ||
|
||
1. Use `CurrentPlayer.ReadOnlyTags()` to target the tag in a script. | ||
2. Attach the script to a [NetworkObject](https://docs-multiplayer.unity3d.com/netcode/current/basics/networkobject/), for example, the **Player**. | ||
|
||
Use the following tag examples as guides for your own scripts: | ||
|
||
- [For a **Player** to run as a server, client, or host](../target-instance) | ||
- [To automatically assign a **Player** to a team](../target-team) | ||
- [To simulate network conditions](../target-network) |
14 changes: 14 additions & 0 deletions
14
mppm_versioned_docs/version-1.2.0/player-tags/player-tags-create.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
id: player-tags-create | ||
title: Create a tag | ||
description: Use these steps to create tags to configure the player actions in Multiplayer Play Mode. | ||
--- | ||
|
||
To create a tag, perform the following actions: | ||
|
||
1. To open the Multiplayer Play mode window, navigate to **Window** > **Multiplayer Play Mode**. | ||
2. Expand the Tags dropdown for a Player or the main Editor Player. | ||
3. Select  Create Tag. | ||
4. Name the tag. | ||
5. Select **Save**. The new tag is automatically added to the local project directory in `...Projects\[example-project-name]\ProjectSettings\VirtualProjectsConfig.json`. | ||
6. The new tag also appears under the **Player Tags** section of the **Multiplayer Play Mode** window and in the dropdown menu for the **Tag** option of each **Player**. |
25 changes: 25 additions & 0 deletions
25
mppm_versioned_docs/version-1.2.0/player-tags/player-tags.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
id: player-tags | ||
title: Information about tags | ||
description: Learn how to use tags to configure Player actions in Multiplayer Play Mode. | ||
--- | ||
|
||
Tags are similar to launch arguments for Players (both the main Editor Player and Virtual Players) that you can use to configure Players to behave in a specific way. For example: | ||
|
||
- Run as a client, server, or host automatically | ||
- Automatically run as a member of a specific team (for example, “Red Team” or “Blue Team”) | ||
- Move faster or slower to simulate their network connection | ||
|
||
You can assign multiple tags to a Player. | ||
|
||
<!-- | ||
<div className="table-columns-plain" > | ||
| Page | Description | | ||
</div> | ||
--> | ||
|
||
|**Page** |**Description**| | ||
|-|-| | ||
|[Create tag](../player-tags/player-tags-create)| Learn how to create tags in code.| | ||
|[Configure tag](../player-tags/player-tags-configure)| Learn how to set up tags to work in your project| | ||
|[Attach a tag to a Player](../player-tags/player-tags-attach)| Learn how to assign tags to a specific Player.| |
50 changes: 50 additions & 0 deletions
50
mppm_versioned_docs/version-1.2.0/player-tags/target-instance.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
id: target-instance | ||
title: Use tags to run a player as a server, client, or host | ||
description: This example shows how you can use Netcode for GameObjects to run a Player as a server, client, or host in Multiplayer Play Mode. | ||
--- | ||
|
||
This example explains how to target tags in your game scripts with `CurrentPlayer.ReadOnlyTags()`. You can place these scripts where you want, but you must attach the scripts to a [NetworkObject](https://docs-multiplayer.unity3d.com/netcode/current/basics/networkobject/) (such as the **Player**). | ||
|
||
You can also use the dedicated server package to set a tag to server, client, or host. For more information, refer to [Use Multiplayer Play Mode with a Dedicated Server](../dedicated-server/play-mode-dedicated-server.md). | ||
|
||
## Set a tag to server, client, or host in a script | ||
|
||
The following script uses the Netcode for GameObjects [NetworkManager](https://docs-multiplayer.unity3d.com/netcode/current/components/networkmanager/) to automatically connect the Virtual Player as a server, client, or host based on their tag. A Player with the `Server` tag automatically runs as a server, and a Player with the `Client` tag automatically runs as a client. | ||
|
||
:::important | ||
This example uses the `Contains` method, which is case-sensitive by default. To make it case-insensitive, pass the `System.StringComparison.CurrentCultureIgnoreCase` method. | ||
::: | ||
|
||
:::note | ||
This example uses [Netcode for GameObjects](https://docs-multiplayer.unity3d.com/netcode/current/about/). | ||
::: | ||
|
||
```csharp | ||
using Unity.Netcode; | ||
using UnityEngine; | ||
using Unity.Multiplayer.Playmode; | ||
|
||
/// A MonoBehaviour to automatically start Netcode for GameObjects | ||
/// clients, hosts, and servers | ||
public class MppmConnect : MonoBehaviour | ||
{ | ||
void Start() | ||
{ | ||
var mppmTag = CurrentPlayer.ReadOnlyTags(); | ||
var networkManager = NetworkManager.Singleton; | ||
if (mppmTag.Contains("Server")) | ||
{ | ||
networkManager.StartServer(); | ||
} | ||
else if (mppmTag.Contains("Host")) | ||
{ | ||
networkManager.StartHost(); | ||
} | ||
else if (mppmTag.Contains("Client")) | ||
{ | ||
networkManager.StartClient(); | ||
} | ||
} | ||
} | ||
``` |
44 changes: 44 additions & 0 deletions
44
mppm_versioned_docs/version-1.2.0/player-tags/target-network.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
id: target-network | ||
title: Configure a Player to simulate different network connections example | ||
description: This example shows how you can use the Network Simulator and Players to test different network connections in Multiplayer Play Mode. | ||
--- | ||
|
||
The logic in the following example checks if the tag has a string rather than if it’s equal to a string to allow for more flexibility with the name of the tag. You can change this logic so that it checks for an exact match. | ||
|
||
## Simulate network conditions | ||
|
||
This example script uses the Network Simulation Presets from the [Multiplayer Tools package](https://docs-multiplayer.unity3d.com/tools/current/install-tools/) to automatically simulate a fast or slow network based on the tag. A Player with the `FastNetwork` tag simulates a common [Home Broadband](https://docs-multiplayer.unity3d.com/tools/current/tools-network-simulator/#home-broadband-connections) connection, and a Player with the `SlowNetwork` tag simulates a [Mobile 2.5G](https://docs-multiplayer.unity3d.com/tools/current/tools-network-simulator/#mobile-25g) connection. | ||
|
||
:::note | ||
This example uses the [Network Simulator](https://docs-multiplayer.unity3d.com/tools/current/tools-network-simulator/) tool from the `com.unity.multiplayer.tools` package. | ||
::: | ||
|
||
```csharp | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Unity.Multiplayer.Playmode; | ||
using Unity.Multiplayer.Tools.NetworkSimulator.Runtime; | ||
|
||
public class NetworkSimulation : MonoBehaviour | ||
{ | ||
void Start() | ||
{ | ||
var networkSimulator = GetComponent<NetworkSimulator>() ?? | ||
gameObject.AddComponent<NetworkSimulator>(); | ||
|
||
var connectionPreset = NetworkSimulatorPresets.None; | ||
if (CurrentPlayer.ReadOnlyTags() == "FastNetwork") | ||
{ | ||
connectionPreset = NetworkSimulatorPresets.HomeBroadband; | ||
} | ||
else if (CurrentPlayer.ReadOnlyTags() == "SlowNetwork") | ||
{ | ||
connectionPreset = NetworkSimulatorPresets.Mobile2_5G; | ||
} | ||
|
||
networkSimulator.ConnectionPreset = connectionPreset; | ||
} | ||
} | ||
``` |
50 changes: 50 additions & 0 deletions
50
mppm_versioned_docs/version-1.2.0/player-tags/target-team.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
id: target-team | ||
title: Use tags to assign a player to a team | ||
description: Automatically assign Players to different teams in Multiplayer Play Mode. | ||
--- | ||
|
||
The logic in the following example checks if the tag has a string rather than if it’s equal to a string to allow for more flexibility with the name of the tag. You can change this logic so that it checks for an exact match. | ||
|
||
:::important | ||
The following example uses the `Contains` method, which is case-sensitive by default. You can make it case-insensitive by passing the `System.StringComparison.CurrentCultureIgnoreCase` method. | ||
::: | ||
|
||
## Automatically assign a Player to a team | ||
|
||
The following script automatically sets a [NetworkVariable](https://docs-multiplayer.unity3d.com/netcode/current/basics/networkvariable/) called `Team` based on the tag. | ||
|
||
A Player with a `Red` tag automatically sets the `Team` NetworkVariable to `Red`. A Player with a `Blue` tag automatically sets the `Team` NetworkVariable to `Blue`. | ||
|
||
```csharp | ||
using Unity.Netcode; | ||
using UnityEngine; | ||
using Unity.Multiplayer.Playmode; | ||
|
||
public enum Team { Blue, Red, } | ||
|
||
/// A player with a team that is automatically assigned | ||
/// based on the tag of the client that owns them | ||
public class Player : NetworkBehaviour | ||
{ | ||
public NetworkVariable<Team> team = new (writePerm: NetworkVariableWritePermission.Owner); | ||
|
||
void Start() | ||
{ | ||
var localClientId = NetworkManager.Singleton.LocalClientId; | ||
if (!team.CanClientWrite(localClientId)) | ||
{ | ||
return; | ||
} | ||
var mppmTag = CurrentPlayer.ReadOnlyTags(); | ||
if (mppmTag.Contains("Blue")) | ||
{ | ||
team.Value = Team.Blue; | ||
} | ||
if (mppmTag.Contains("Red")) | ||
{ | ||
team.Value = Team.Red; | ||
} | ||
} | ||
} | ||
``` |
Oops, something went wrong.