Documentation moved to https://mirror-networking.gitbook.io
@ -1,7 +1,7 @@
|
|||||||
![Mirror Logo](https://i.imgur.com/we6li1x.png)
|
![Mirror Logo](https://i.imgur.com/we6li1x.png)
|
||||||
|
|
||||||
[![Download](https://img.shields.io/badge/asset_store-brightgreen.svg)](https://assetstore.unity.com/packages/tools/network/mirror-129321)
|
[![Download](https://img.shields.io/badge/asset_store-brightgreen.svg)](https://assetstore.unity.com/packages/tools/network/mirror-129321)
|
||||||
[![Documentation](https://img.shields.io/badge/docs-brightgreen.svg)](https://mirror-networking.com/docs)
|
[![Documentation](https://img.shields.io/badge/docs-brightgreen.svg)](https://mirror-networking.gitbook.io/)
|
||||||
[![Showcase](https://img.shields.io/badge/showcase-brightgreen.svg)](https://mirror-networking.com/showcase/)
|
[![Showcase](https://img.shields.io/badge/showcase-brightgreen.svg)](https://mirror-networking.com/showcase/)
|
||||||
[![Video Tutorial](https://img.shields.io/badge/video_tutorial-brightgreen.svg)](https://www.youtube.com/playlist?list=PLkx8oFug638oBYF5EOwsSS-gOVBXj1dkP)
|
[![Video Tutorial](https://img.shields.io/badge/video_tutorial-brightgreen.svg)](https://www.youtube.com/playlist?list=PLkx8oFug638oBYF5EOwsSS-gOVBXj1dkP)
|
||||||
[![Forum](https://img.shields.io/badge/forum-brightgreen.svg)](https://forum.unity.com/threads/mirror-networking-for-unity-aka-hlapi-community-edition.425437/)
|
[![Forum](https://img.shields.io/badge/forum-brightgreen.svg)](https://forum.unity.com/threads/mirror-networking-for-unity-aka-hlapi-community-edition.425437/)
|
||||||
@ -47,9 +47,9 @@ _Note: Mirror is based on Unity's abandoned UNET Networking system. We fixed it
|
|||||||
## Getting Started
|
## Getting Started
|
||||||
Get **Unity 2018/2019 LTS**, download [Mirror on the Asset Store](https://assetstore.unity.com/packages/tools/network/mirror-129321), open one of the examples & press Play!
|
Get **Unity 2018/2019 LTS**, download [Mirror on the Asset Store](https://assetstore.unity.com/packages/tools/network/mirror-129321), open one of the examples & press Play!
|
||||||
|
|
||||||
Check out our [Documentation](https://mirror-networking.com/docs/) to learn how it all works.
|
Check out our [Documentation](https://mirror-networking.gitbook.io/) to learn how it all works.
|
||||||
|
|
||||||
If you are migrating from UNET, then please check out our [Migration Guide](https://mirror-networking.com/docs/Articles/General/Migration.html).
|
If you are migrating from UNET, then please check out our [Migration Guide](https://mirror-networking.gitbook.io/docs/general/migration-guide).
|
||||||
|
|
||||||
## Made with Mirror
|
## Made with Mirror
|
||||||
![Population: ONE](https://steamcdn-a.akamaihd.net/steam/apps/691260/header.jpg?t=1603846067)<br/>
|
![Population: ONE](https://steamcdn-a.akamaihd.net/steam/apps/691260/header.jpg?t=1603846067)<br/>
|
||||||
@ -68,7 +68,7 @@ If you are migrating from UNET, then please check out our [Migration Guide](http
|
|||||||
[Laurum Online](https://laurum.online/)<br/>
|
[Laurum Online](https://laurum.online/)<br/>
|
||||||
|
|
||||||
## Funding
|
## Funding
|
||||||
Mirror is free & open source software funded by Donations. If you love it, please consider supporting [Mirror on GitHub](https://github.com/sponsors/vis2k). As reward, you'll receive our [Network Profiler](https://mirror-networking.com/docs/Articles/Guides/Profiler.html?q=Profiler), priority support and more :)
|
Mirror is free & open source software funded by Donations. If you love it, please consider supporting [Mirror on GitHub](https://github.com/sponsors/vis2k). As reward, you'll receive our [Network Profiler](https://mirror-networking.gitbook.io/docs/guides/network-profiler), priority support and more :)
|
||||||
|
|
||||||
## Benchmarks
|
## Benchmarks
|
||||||
* [uMMORPG 480 CCU worst case test](https://youtu.be/mDCNff1S9ZU) (everyone broadcasting to everyone else)
|
* [uMMORPG 480 CCU worst case test](https://youtu.be/mDCNff1S9ZU) (everyone broadcasting to everyone else)
|
||||||
|
Before Width: | Height: | Size: 89 KiB |
Before Width: | Height: | Size: 203 KiB |
Before Width: | Height: | Size: 259 KiB |
Before Width: | Height: | Size: 403 KiB |
Before Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 110 KiB |
Before Width: | Height: | Size: 174 KiB |
Before Width: | Height: | Size: 170 KiB |
Before Width: | Height: | Size: 127 KiB |
Before Width: | Height: | Size: 234 KiB |
Before Width: | Height: | Size: 290 KiB |
Before Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 79 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 204 KiB |
Before Width: | Height: | Size: 172 KiB |
Before Width: | Height: | Size: 175 KiB |
Before Width: | Height: | Size: 148 KiB |
Before Width: | Height: | Size: 176 KiB |
Before Width: | Height: | Size: 143 KiB |
Before Width: | Height: | Size: 138 KiB |
Before Width: | Height: | Size: 135 KiB |
Before Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 148 KiB |
Before Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 95 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 104 KiB |
Before Width: | Height: | Size: 222 KiB |
Before Width: | Height: | Size: 137 KiB |
Before Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 226 KiB |
Before Width: | Height: | Size: 195 KiB |
@ -1,737 +0,0 @@
|
|||||||
# Mirror Quick Start Guide
|
|
||||||
Written by [StephenAllenGames.co.uk](http://stephenallengames.co.uk/) <br />
|
|
||||||
Edited by [James Frowen](https://github.com/James-Frowen)
|
|
||||||
***
|
|
||||||
This guide currently shows you:
|
|
||||||
- [Basic scene setup](#part-1)
|
|
||||||
- [Player movement](#part-4)
|
|
||||||
- [Names and colours](#part-8)
|
|
||||||
- [Scene script with canvas buttons](#part-11)
|
|
||||||
- [Weapon switching](#part-12)
|
|
||||||
- [Networked scene objects tweak](#part-15)
|
|
||||||
- [Menu and scene switching](#part-16)
|
|
||||||
- [Weapon firing](#part-20)
|
|
||||||
|
|
||||||
It is best to first make a mini practice game before converting your single player game, or creating your ideal brand new multiplayer.
|
|
||||||
|
|
||||||
The Pre-made Mirror examples are great for using as reference, it is recommend to use them regarding connection setup, with ports and firewalls. This can be a huge topic that changes from person to person, and is not covered in this guide, here we will use localHost (multiple games on same PC).
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 1
|
|
||||||
|
|
||||||
Blank Project, import Mirror from [Asset Store](https://assetstore.unity.com/packages/tools/network/mirror-129321).
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 2
|
|
||||||
|
|
||||||
- Create new scene, save it, and add it to build settings
|
|
||||||
- Create a new GameObject, name it NetworkManager in the scene, and add these 3 components
|
|
||||||
- NetworkManager
|
|
||||||
- TelepathyTransport
|
|
||||||
- NetworkManagerHUD
|
|
||||||
- On the NetworkManager component, drag your Offline and Online scene into the slots, we have only one scene
|
|
||||||
for now, so put your scene in both
|
|
||||||
- The scene must be in the build settings before dragging it to the field
|
|
||||||
|
|
||||||
![](./image--000.jpg)
|
|
||||||
|
|
||||||
![](./image--001.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 3
|
|
||||||
|
|
||||||
Setup the scene
|
|
||||||
- Add a simple Plane floor with:
|
|
||||||
- positions (0, -1, 0)
|
|
||||||
- scale (2, 2, 2)
|
|
||||||
- (optional) add a material to this, I added one called dirt that is used one of mirrors examples
|
|
||||||
- Next we add a GameObject, name does not matter
|
|
||||||
- Add `NetworkStartPosition` component to this GameObject
|
|
||||||
- Duplicate the GameObject a few times, and scatter around your scene floor so that you have multiple spawn points. I did 4, one near each corner
|
|
||||||
|
|
||||||
![](./image--002.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
## Part 4
|
|
||||||
|
|
||||||
Creating the player
|
|
||||||
- Create a capsule using the menus as shown in the image
|
|
||||||
- Attached a NetworkTransform component, this will auto add a Network Identity
|
|
||||||
- Tick Client Authority on the NetworkTransform
|
|
||||||
|
|
||||||
![](./image--003.jpg)
|
|
||||||
|
|
||||||
- Rename that object Player
|
|
||||||
- Add an empty PlayerScript
|
|
||||||
- Drag into Project to create a prefab
|
|
||||||
- Then delete Player from scene
|
|
||||||
|
|
||||||
![](./image--004.jpg)
|
|
||||||
|
|
||||||
- Drag your player prefab into Network manager,
|
|
||||||
- Set spawn method to Round Robin.
|
|
||||||
|
|
||||||
![](./image--005.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 5
|
|
||||||
|
|
||||||
Add the following to your PlayerScript.
|
|
||||||
```cs
|
|
||||||
using Mirror;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace QuickStart
|
|
||||||
{
|
|
||||||
public class PlayerScript : NetworkBehaviour
|
|
||||||
{
|
|
||||||
public override void OnStartLocalPlayer()
|
|
||||||
{
|
|
||||||
Camera.main.transform.SetParent(transform);
|
|
||||||
Camera.main.transform.localPosition = new Vector3(0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
if (!isLocalPlayer) { return; }
|
|
||||||
|
|
||||||
float moveX = Input.GetAxis("Horizontal") * Time.deltaTime * 110.0f;
|
|
||||||
float moveZ = Input.GetAxis("Vertical") * Time.deltaTime * 4f;
|
|
||||||
|
|
||||||
transform.Rotate(0, moveX, 0);
|
|
||||||
transform.Translate(0, 0, moveZ);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Part 6
|
|
||||||
|
|
||||||
Press play in Unity editor, and then Host (server + client) button in the game window. You should be able to move around with a first person view capsule.
|
|
||||||
|
|
||||||
![](./image--006.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 7
|
|
||||||
|
|
||||||
Build and run your scene, open it, host on one, and press the Client button on the other. Congrats you made a mini multiplayer game!
|
|
||||||
|
|
||||||
![](./image--007.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 8
|
|
||||||
|
|
||||||
Player name above heads
|
|
||||||
- Inside your player Prefab, create an empty GameObject
|
|
||||||
- name it something like `FloatingInfo`
|
|
||||||
- position Y to 1.5
|
|
||||||
- scale X to -1
|
|
||||||
- Inside that `FloatingInfo`, create a 3D text using Unity menu (GameObject - 3D Object - 3D Text),
|
|
||||||
- Set it up as shown in the picture below
|
|
||||||
|
|
||||||
![](./image--008.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 9
|
|
||||||
|
|
||||||
Update your PlayerScript.cs with this:
|
|
||||||
```cs
|
|
||||||
using Mirror;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace QuickStart
|
|
||||||
{
|
|
||||||
public class PlayerScript : NetworkBehaviour
|
|
||||||
{
|
|
||||||
public TextMesh playerNameText;
|
|
||||||
public GameObject floatingInfo;
|
|
||||||
|
|
||||||
private Material playerMaterialClone;
|
|
||||||
|
|
||||||
[SyncVar(hook = nameof(OnNameChanged))]
|
|
||||||
public string playerName;
|
|
||||||
|
|
||||||
[SyncVar(hook = nameof(OnColorChanged))]
|
|
||||||
public Color playerColor = Color.white;
|
|
||||||
|
|
||||||
void OnNameChanged(string _Old, string _New)
|
|
||||||
{
|
|
||||||
playerNameText.text = playerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnColorChanged(Color _Old, Color _New)
|
|
||||||
{
|
|
||||||
playerNameText.color = _New;
|
|
||||||
playerMaterialClone = new Material(GetComponent<Renderer>().material);
|
|
||||||
playerMaterialClone.color = _New;
|
|
||||||
GetComponent<Renderer>().material = playerMaterialClone;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnStartLocalPlayer()
|
|
||||||
{
|
|
||||||
Camera.main.transform.SetParent(transform);
|
|
||||||
Camera.main.transform.localPosition = new Vector3(0, 0, 0);
|
|
||||||
|
|
||||||
floatingInfo.transform.localPosition = new Vector3(0, -0.3f, 0.6f);
|
|
||||||
floatingInfo.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
|
|
||||||
|
|
||||||
string name = "Player" + Random.Range(100, 999);
|
|
||||||
Color color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f))
|
|
||||||
CmdSetupPlayer(name, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command]
|
|
||||||
public void CmdSetupPlayer(string _name, Color _col)
|
|
||||||
{
|
|
||||||
// player info sent to server, then server updates sync vars which handles it on all clients
|
|
||||||
playerName = _name;
|
|
||||||
playerColor = _col;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
if (!isLocalPlayer)
|
|
||||||
{
|
|
||||||
// make non-local players run this
|
|
||||||
floatingInfo.transform.LookAt(Camera.main.transform);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float moveX = Input.GetAxis("Horizontal") * Time.deltaTime * 110.0f;
|
|
||||||
float moveZ = Input.GetAxis("Vertical") * Time.deltaTime * 4f;
|
|
||||||
|
|
||||||
transform.Rotate(0, moveX, 0);
|
|
||||||
transform.Translate(0, 0, moveZ);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 10
|
|
||||||
|
|
||||||
Add the `PlayerNameText` and `FloatingInfo` objects into the script on the player prefab, as shown below.
|
|
||||||
|
|
||||||
![](./image--009.jpg)
|
|
||||||
|
|
||||||
Now if you build and run, host on one, join on the other, you will see player names and colors synced across the network!
|
|
||||||
|
|
||||||
Well done, 5 stars to you!
|
|
||||||
|
|
||||||
![](./image--010.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 11
|
|
||||||
|
|
||||||
A scene networked object all can access and adjust.
|
|
||||||
|
|
||||||
Create a SceneScript.cs, add it onto an empty GameObject in the scene called SceneScript.
|
|
||||||
|
|
||||||
Then create a Canvas with text and button, similar to below.
|
|
||||||
|
|
||||||
![](./image--011.jpg)
|
|
||||||
|
|
||||||
Add the sceneScript variable, Awake function, and CmdSendPlayerMessage to PlayerScript.cs
|
|
||||||
Also add the new playerName joined line to CmdSetupPlayer();
|
|
||||||
```cs
|
|
||||||
private SceneScript sceneScript;
|
|
||||||
|
|
||||||
void Awake()
|
|
||||||
{
|
|
||||||
//allow all players to run this
|
|
||||||
sceneScript = GameObject.FindObjectOfType<SceneScript>();
|
|
||||||
}
|
|
||||||
[Command]
|
|
||||||
public void CmdSendPlayerMessage()
|
|
||||||
{
|
|
||||||
if (sceneScript)
|
|
||||||
{
|
|
||||||
sceneScript.statusText = $"{playerName} says hello {Random.Range(10, 99)}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[Command]
|
|
||||||
public void CmdSetupPlayer(string _name, Color _col)
|
|
||||||
{
|
|
||||||
//player info sent to server, then server updates sync vars which handles it on all clients
|
|
||||||
playerName = _name;
|
|
||||||
playerColor = _col;
|
|
||||||
sceneScript.statusText = $"{playerName} joined.";
|
|
||||||
}
|
|
||||||
public override void OnStartLocalPlayer()
|
|
||||||
{
|
|
||||||
sceneScript.playerScript = this;
|
|
||||||
//. . . . ^ new line to add here
|
|
||||||
```
|
|
||||||
|
|
||||||
Add this code to SceneScript.cs
|
|
||||||
|
|
||||||
```cs
|
|
||||||
using Mirror;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace QuickStart
|
|
||||||
{
|
|
||||||
public class SceneScript : NetworkBehaviour
|
|
||||||
{
|
|
||||||
public Text canvasStatusText;
|
|
||||||
public PlayerScript playerScript;
|
|
||||||
|
|
||||||
[SyncVar(hook = nameof(OnStatusTextChanged))]
|
|
||||||
public string statusText;
|
|
||||||
|
|
||||||
void OnStatusTextChanged(string _Old, string _New)
|
|
||||||
{
|
|
||||||
//called from sync var hook, to update info on screen for all players
|
|
||||||
canvasStatusText.text = statusText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ButtonSendMessage()
|
|
||||||
{
|
|
||||||
if (playerScript != null)
|
|
||||||
{
|
|
||||||
playerScript.CmdSendPlayerMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
- Attach the ButtonSendMessage function to your Canvas Button.
|
|
||||||
- Attach Canvas Scene Text to SceneScript variable.
|
|
||||||
- ignore SceneScript’s, playerScript variable, it automatically sets this!
|
|
||||||
- Attach a NetworkIdentity component to the SceneScript gameobject, if it has not automatically done so.
|
|
||||||
|
|
||||||
![](./image--012.jpg)
|
|
||||||
![](./image--013.jpg)
|
|
||||||
|
|
||||||
Now if you build and run, host and join, you can send messages, and have a text log for actions!
|
|
||||||
|
|
||||||
Wahooo!
|
|
||||||
|
|
||||||
![](./image--014.jpg)
|
|
||||||
![](./image--015.jpg)
|
|
||||||
|
|
||||||
Experiment and adjust, have fun!
|
|
||||||
|
|
||||||
![](./image--016.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
## Part 12
|
|
||||||
|
|
||||||
Weapon switching! The code bits.
|
|
||||||
|
|
||||||
Add the following to your PlayerScript.cs
|
|
||||||
```cs
|
|
||||||
private int selectedWeaponLocal = 1;
|
|
||||||
public GameObject[] weaponArray;
|
|
||||||
|
|
||||||
[SyncVar(hook = nameof(OnWeaponChanged))]
|
|
||||||
public int activeWeaponSynced = 1;
|
|
||||||
|
|
||||||
void OnWeaponChanged(int _Old, int _New)
|
|
||||||
{
|
|
||||||
// disable old weapon
|
|
||||||
// in range and not null
|
|
||||||
if (0 < _Old && _Old < weaponArray.Length && weaponArray[_Old] != null)
|
|
||||||
{
|
|
||||||
weaponArray[_Old].SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable new weapon
|
|
||||||
// in range and not null
|
|
||||||
if (0 < _New && _New < weaponArray.Length && weaponArray[_New] != null)
|
|
||||||
{
|
|
||||||
weaponArray[_New].SetActive(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command]
|
|
||||||
public void CmdChangeActiveWeapon(int newIndex)
|
|
||||||
{
|
|
||||||
activeWeaponSynced = newIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Awake()
|
|
||||||
{
|
|
||||||
// disable all weapons
|
|
||||||
foreach (var item in weaponArray)
|
|
||||||
{
|
|
||||||
if (item != null)
|
|
||||||
{
|
|
||||||
item.SetActive(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
Add the weapon switch button in update. Only local player switches its own weapon, so it goes below the `!isLocalPlayer` check.
|
|
||||||
```cs
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
if (!isLocalPlayer)
|
|
||||||
{
|
|
||||||
// make non-local players run this
|
|
||||||
floatingInfo.transform.LookAt(Camera.main.transform);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float moveX = Input.GetAxis("Horizontal") * Time.deltaTime * 110.0f;
|
|
||||||
float moveZ = Input.GetAxis("Vertical") * Time.deltaTime * 4f;
|
|
||||||
|
|
||||||
transform.Rotate(0, moveX, 0);
|
|
||||||
transform.Translate(0, 0, moveZ);
|
|
||||||
|
|
||||||
if (Input.GetButtonDown("Fire2")) //Fire2 is mouse 2nd click and left alt
|
|
||||||
{
|
|
||||||
selectedWeaponLocal += 1;
|
|
||||||
|
|
||||||
if (selectedWeaponLocal > weaponArray.Length)
|
|
||||||
{
|
|
||||||
selectedWeaponLocal = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
CmdChangeActiveWeapon(selectedWeaponLocal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 13
|
|
||||||
|
|
||||||
Weapon models
|
|
||||||
|
|
||||||
Add the basic cube weapons first, change these later.
|
|
||||||
|
|
||||||
- Double click your player prefab to enter it
|
|
||||||
- Add a "WeaponsHolder" empty GameObject, with position and rotation at 0,0,0.
|
|
||||||
- Inside that GameObject, create a cube from unity menu, (GameObject, 3D object, cube)- Remove the box colliders.
|
|
||||||
- Rename this `Weapon1`, change position and scale to match the below pictures.
|
|
||||||
|
|
||||||
![](./image--017.jpg)
|
|
||||||
|
|
||||||
Duplicate weapon 1 for a Weapon 2, and change its scale and position, now you should have 2 different looking ‘weapons’!
|
|
||||||
|
|
||||||
![](./image--018.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
## Part 14
|
|
||||||
|
|
||||||
Weapon switch finale.
|
|
||||||
|
|
||||||
- Add these 2 GameObjects to your PlayerScript.cs weapons array.
|
|
||||||
- Disable weapon 2, so only weapon 1 shows when spawning.
|
|
||||||
|
|
||||||
![](./image--019.jpg)
|
|
||||||
|
|
||||||
Build and run!
|
|
||||||
|
|
||||||
You should see each player switching weapons, and whatever your player has equipped, will auto show on new joining players (sync var and hook magic!)
|
|
||||||
|
|
||||||
![](./image--020.jpg)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 15
|
|
||||||
|
|
||||||
Here we will make a small adjustment, as using a GameObject.Find() may not guarantee Network Identity scene objects are found.
|
|
||||||
In the image below you can see our NetworkIdentity scene object gets disabled, as they are disabled until a player is in ‘ready’ status (ready status is usually set when player spawns).
|
|
||||||
|
|
||||||
![](./image--021.jpg)
|
|
||||||
|
|
||||||
So our chosen workaround is to have our GameObject.Find() get the non-networked scene object, which will have those Network Identity scene object as pre-set variables.
|
|
||||||
|
|
||||||
Create a new script called SceneReference.cs, and add this one variable.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace QuickStart
|
|
||||||
{
|
|
||||||
public class SceneReference : MonoBehaviour
|
|
||||||
{
|
|
||||||
public SceneScript sceneScript;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Open up SceneScript.cs and add the following variable.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
public SceneReference sceneReference;
|
|
||||||
```
|
|
||||||
|
|
||||||
Now in your Unity scene create a gameobject, name it SceneReference, and add the new script.
|
|
||||||
On both Scene gameobjects, set the reference to each other.
|
|
||||||
So SceneReference can speak to SceneScript, and SceneScript to SceneReference.
|
|
||||||
|
|
||||||
![](./image--022.jpg)
|
|
||||||
|
|
||||||
Open up PlayerScript.cs and overwrite the Awake function to this:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
void Awake()
|
|
||||||
{
|
|
||||||
//allows all players to run this
|
|
||||||
sceneScript = GameObject.Find(“SceneReference”).GetComponent<SceneReference>().sceneScript;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 16
|
|
||||||
|
|
||||||
Menu and Scene switching, here we will go from an offline Menu, with a play button, to a Games List with a back button and the Host/Join HUD, to your online map, and then a second map for host to switch to.
|
|
||||||
|
|
||||||
Open up SceneScript.cs and add the following function.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
public void ButtonChangeScene()
|
|
||||||
{
|
|
||||||
if (isServer)
|
|
||||||
{
|
|
||||||
Scene scene = SceneManager.GetActiveScene();
|
|
||||||
if (scene.name == "MyScene") { NetworkManager.singleton.ServerChangeScene("MyOtherScene"); }
|
|
||||||
else { NetworkManager.singleton.ServerChangeScene("MyScene"); }
|
|
||||||
}
|
|
||||||
else { Debug.Log("You are not Host."); }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
![](./image--023.jpg)
|
|
||||||
|
|
||||||
Duplicate your previous Canvas button, rename it and reposition it, then setup the OnClick() to point to SceneScript.ButtonChangeScene, like in the image.
|
|
||||||
|
|
||||||
Then drag your NetworkManager into your Project, to make it a Prefab, this way any changes we make later will apply to them all.
|
|
||||||
If you haven’t already, you can sort out your project into folders, one for scripts, prefabs, scenes, textures etc. :)
|
|
||||||
|
|
||||||
![](./image--024.jpg)
|
|
||||||
|
|
||||||
## Part 17
|
|
||||||
|
|
||||||
Save, and then Duplicate your MyScene, rename to make a Menu, GamesList and MyOtherScene, then add them to the build settings, with Menu being first.
|
|
||||||
|
|
||||||
![](./image--025.jpg)
|
|
||||||
|
|
||||||
Open up the Menu scene, remove the spawn points, SceneScript, SceneReference, Network Manager and Plane, so it looks like the below.
|
|
||||||
Adjust the canvas button to say Play, centre it.
|
|
||||||
Here is where you could add the Scores scene, Contact section, News, etc
|
|
||||||
|
|
||||||
Create a Menu.cs script, add it onto a Menu gameObject.
|
|
||||||
|
|
||||||
![](./image--026.jpg)
|
|
||||||
|
|
||||||
Add the code to Menu.cs, then in the Button, drag the Menu gameobject into the On Click () and set it to Menu.LoadScene, like in the picture.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.SceneManagement;
|
|
||||||
|
|
||||||
namespace QuickStart
|
|
||||||
{
|
|
||||||
public class Menu : MonoBehaviour
|
|
||||||
{
|
|
||||||
public void LoadScene()
|
|
||||||
{
|
|
||||||
SceneManager.LoadScene("GamesList");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
![](./image--027.jpg)
|
|
||||||
|
|
||||||
## Part 18
|
|
||||||
|
|
||||||
Open up GamesList scene, do similar to Menu but KEEP NetworkManager prefab.
|
|
||||||
|
|
||||||
Create a GamesList.cs, add the code, and add it onto a GamesList gameobject in the scene.
|
|
||||||
Adjust a canvas button to say Menu (this is our back button). It should look like the image below.
|
|
||||||
|
|
||||||
- The games list is where you can add List server contents, or matchmaker, or just the host and join buttons, similar to the default NetworkManagerHud, for now leave this. :)
|
|
||||||
|
|
||||||
```cs
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.SceneManagement;
|
|
||||||
|
|
||||||
namespace QuickStart
|
|
||||||
{
|
|
||||||
public class GamesList : MonoBehaviour
|
|
||||||
{
|
|
||||||
public void LoadScene()
|
|
||||||
{
|
|
||||||
SceneManager.LoadScene("Menu");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
![](./image--028.jpg)
|
|
||||||
|
|
||||||
## Part 19
|
|
||||||
|
|
||||||
Open MyOtherScene, this is our second map.
|
|
||||||
Change the camera background colour and floor material (or anything, just so you can see both scenes are different.
|
|
||||||
To summarise, MyScene is map 1 and MyOtherScene is map 2.
|
|
||||||
|
|
||||||
![](./image--029.jpg)
|
|
||||||
|
|
||||||
In your NetworkManager prefab in PROJECT (not the one in scenes), add Menu to offline, and MyScene to Online variables. This should change all the NetworkManager prefabs to have these settings.
|
|
||||||
|
|
||||||
![](./image--030.jpg)
|
|
||||||
|
|
||||||
Build and Run, press Play on the Menu to go to GamesList, then click Host (for player 1).
|
|
||||||
For player 2, press Play on Menu, then client connect on GamesList.
|
|
||||||
|
|
||||||
Now the host can change scenes between map 1 and map 2, and if anyone disconnects or stops the game, Menu scene is load to start again.
|
|
||||||
This whole process can be tidied up, but should provide a good scene switch template to your Mirror game :)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Part 20
|
|
||||||
|
|
||||||
Here we will add basic weapon firing, using rigidbody prefabs.
|
|
||||||
Raycasts with a representation of the fired object is usually better to do this, and keep phycisal objects for things like Grenades and Cannon balls.
|
|
||||||
This section will also lack a lot of security and ant-cheat techniques in order to keep the guide simple, but anyway, here we go!
|
|
||||||
|
|
||||||
Double click the Player Prefab to open it, create empty gameobjects and line them up with the end of your weapon, add them as child to each weapon.
|
|
||||||
Some weapons may be short pistols, others long rifles, so the place where objects spawn will be different.
|
|
||||||
|
|
||||||
![](./image--031.jpg)
|
|
||||||
|
|
||||||
Create a Weapon.cs script, add it to the Weapon1 and Weapon 2 gameObjects inside the player prefab.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace QuickStart
|
|
||||||
{
|
|
||||||
public class Weapon : MonoBehaviour
|
|
||||||
{
|
|
||||||
public float weaponSpeed = 15.0f;
|
|
||||||
public float weaponLife = 3.0f;
|
|
||||||
public float weaponCooldown = 1.0f;
|
|
||||||
public int weaponAmmo = 15;
|
|
||||||
|
|
||||||
public GameObject weaponBullet;
|
|
||||||
public Transform weaponFirePosition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Part 21
|
|
||||||
|
|
||||||
Now back in your scene we shall make 2 bullets, in Unitys menu, go to GameObject, 3D Object, Sphere.
|
|
||||||
Add rigidbody to this sphere, make the scale 0.2, 0.2, 0.2, then save it as a Prefab in the Project.
Do the same with a cube, so you have two different looking bullets.
|
|
||||||
|
|
||||||
![](./image--032.jpg)
|
|
||||||
|
|
||||||
Inside your player prefab again, select a weapon, and set the variables on weapon script.
|
|
||||||
|
|
||||||
![](./image--033.jpg)
|
|
||||||
![](./image--034.jpg)
|
|
||||||
|
|
||||||
## Part 22
|
|
||||||
In SceneScript.cs, add this variable and function.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
public Text canvasAmmoText;
|
|
||||||
|
|
||||||
public void UIAmmo(int _value)
|
|
||||||
{
|
|
||||||
canvasAmmoText.text = "Ammo: " + _value;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Enter MyScene (map 1).
|
|
||||||
Duplicate the Canvas StatusText, rename to Ammo, then drag that Ammo text UI into SceneScript gameobject, canvasAmmoText variable.
|
|
||||||
Do this on BOTH MyScene (map 1) and MyOtherScene (map 2), as we have not yet linked or prefabbed our canvas and scene scripts to auto update changes on each map.
|
|
||||||
|
|
||||||
![](./image--035.jpg)
|
|
||||||
|
|
||||||
Open up PlayerScript.cs, add these two variables:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
private Weapon activeWeapon;
|
|
||||||
private float weaponCooldownTime;
|
|
||||||
```
|
|
||||||
|
|
||||||
In the ‘OnWeaponChanged’ function, update it with the new line, so it should look like this.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
void OnWeaponChanged(int _Old, int _New)
|
|
||||||
{
|
|
||||||
// disable old weapon
|
|
||||||
// in range and not null
|
|
||||||
if (0 < _Old && _Old < weaponArray.Length && weaponArray[_Old] != null)
|
|
||||||
{
|
|
||||||
weaponArray[_Old].SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable new weapon
|
|
||||||
// in range and not null
|
|
||||||
if (0 < _New && _New < weaponArray.Length && weaponArray[_New] != null)
|
|
||||||
{
|
|
||||||
weaponArray[_New].SetActive(true);
|
|
||||||
activeWeapon = weaponArray[activeWeaponSynced].GetComponent<Weapon>();
|
|
||||||
if( isLocalPlayer ) { sceneScript.UIAmmo(activeWeapon.weaponAmmo); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
In Awake(), add this at the end:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
if (selectedWeaponLocal < weaponArray.Length && weaponArray[selectedWeaponLocal] != null)
|
|
||||||
{ activeWeapon = weaponArray[selectedWeaponLocal].GetComponent<Weapon>(); sceneScript.UIAmmo(activeWeapon.weaponAmmo); }
|
|
||||||
```
|
|
||||||
|
|
||||||
In Update(), add this at the end:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
if (Input.GetButtonDown("Fire1") ) //Fire1 is mouse 1st click
|
|
||||||
{
|
|
||||||
if (activeWeapon && Time.time > weaponCooldownTime && activeWeapon.weaponAmmo > 0)
|
|
||||||
{
|
|
||||||
weaponCooldownTime = Time.time + activeWeapon.weaponCooldown;
|
|
||||||
activeWeapon.weaponAmmo -= 1;
|
|
||||||
sceneScript.UIAmmo(activeWeapon.weaponAmmo);
|
|
||||||
CmdShootRay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Add these two functions after the Update() {} function finishes.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
[Command]
|
|
||||||
void CmdShootRay()
|
|
||||||
{
|
|
||||||
RpcFireWeapon();
|
|
||||||
}
|
|
||||||
|
|
||||||
[ClientRpc]
|
|
||||||
void RpcFireWeapon()
|
|
||||||
{
|
|
||||||
//bulletAudio.Play(); muzzleflash etc
|
|
||||||
var bullet = (GameObject)Instantiate(activeWeapon.weaponBullet, activeWeapon.weaponFirePosition.position, activeWeapon.weaponFirePosition.rotation);
|
|
||||||
bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * activeWeapon.weaponSpeed;
|
|
||||||
if (bullet) { Destroy(bullet, activeWeapon.weaponLife); }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Build and Run, you should have firing, with different speeds and cooldowns on all players :)
|
|
||||||
|
|
||||||
![](./image--036.jpg)
|
|
@ -1,8 +0,0 @@
|
|||||||
# Community Guides
|
|
||||||
|
|
||||||
This section contains guides written by the community rather than by the developers themselves
|
|
||||||
|
|
||||||
- [Mirror Quick Start Guide](./MirrorQuickStartGuide/index.md) by [StephenAllenGames.co.uk](http://stephenallengames.co.uk/)
|
|
||||||
|
|
||||||
|
|
||||||
> If you want to submit a guide either create a [Pull request](https://github.com/vis2k/Mirror/pulls) or ask in the discord
|
|
@ -1,4 +0,0 @@
|
|||||||
- name: Overview
|
|
||||||
href: index.md
|
|
||||||
- name: Mirror Quick Start Guide
|
|
||||||
href: MirrorQuickStartGuide/index.md
|
|
@ -1,11 +0,0 @@
|
|||||||
# Basic Authenticator
|
|
||||||
|
|
||||||
Mirror includes a Basic Authenticator in the Mirror / Authenticators folder which just uses a simple username and password.
|
|
||||||
- Drag the Basic Authenticator script to the inspector of the object in your scene that has Network Manager
|
|
||||||
- The Basic Authenticator component will automatically be assigned to the Authenticator field in Network Manager
|
|
||||||
|
|
||||||
When you're done, it should look like this:
|
|
||||||
|
|
||||||
![Inspector showing Basic Authenticator component](Basic.png)
|
|
||||||
|
|
||||||
> **Note:** You don't need to assign anything to the event lists unless you want to subscribe to the events in your own code for your own purposes. Mirror has internal listeners for both events.
|
|
Before Width: | Height: | Size: 57 KiB |
@ -1,66 +0,0 @@
|
|||||||
# Authentication
|
|
||||||
|
|
||||||
When you have a multiplayer game, often you need to store information about your player for later games, keep game stats or communicate with your friends. For all these use cases, you often need a way to uniquely identify a user. Being able to tell users apart is called authentication. There are several methods available, some examples include:
|
|
||||||
- Ask the user for username and password
|
|
||||||
- Use a third party OAuth2 or OpenID identity provider, such as Facebook, Twitter, Google
|
|
||||||
- Use a third party service such as PlayFab, GameLift or Steam
|
|
||||||
- Use the device id, very popular method in mobile
|
|
||||||
- Use Google Play in Android
|
|
||||||
- Use Game Center in IOS
|
|
||||||
- Use a web service in your website
|
|
||||||
|
|
||||||
## Encryption Notice
|
|
||||||
|
|
||||||
By default Mirror uses Kcp Transport, which is not encrypted, so if you want to do authentication through Mirror, we highly recommend you use a transport that supports encryption.
|
|
||||||
|
|
||||||
## Basic Authenticator
|
|
||||||
|
|
||||||
- [Basic Authenticator](Basic.md)
|
|
||||||
Mirror includes a Basic Authenticator in the Mirror / Authenticators folder which just uses a simple username and password.
|
|
||||||
|
|
||||||
## Custom Authenticators
|
|
||||||
|
|
||||||
Authenticators are derived from an `Authenticator` abstract class that allows you to implement any authentication scheme you need.
|
|
||||||
|
|
||||||
From the Assets menu, click Create > Mirror > Network Authenticator to make your own custom Authenticator from our [Script Templates](../../General/ScriptTemplates.md),
|
|
||||||
and just fill in the messages and validation code to suit your needs.
|
|
||||||
When a client is successfully authenticated, call `ServerAccept(conn);` on the server and `ClientAccept(conn);` on the client.
|
|
||||||
To reject a client call `ServerReject(conn);` on the server and `ClientReject(conn);` on the client.
|
|
||||||
Mirror will responde to these method calls to proceed accordingly with completing the connection (or disconnecting) the client.
|
|
||||||
Subscribe to OnServerAuthenticated and OnClientAuthenticated events if you wish to perform additional steps after authentication.
|
|
||||||
|
|
||||||
## Message Registration
|
|
||||||
|
|
||||||
By default all messages registered to `NetworkServer` and `NetworkClient` require authentication unless explicitly indicated otherwise. To register messages to bypass authentication, you need to specify `false` for a bool parameter to the `RegisterMessage` method:
|
|
||||||
|
|
||||||
```
|
|
||||||
NetworkServer.RegisterHandler<AuthenticationRequest>(OnAuthRequestMessage, false);
|
|
||||||
```
|
|
||||||
|
|
||||||
Certain internal messages already have been set to bypass authentication:
|
|
||||||
|
|
||||||
- Server
|
|
||||||
- `ConnectMessage`
|
|
||||||
- `DisconnectMessage`
|
|
||||||
- `ErrorMessage`
|
|
||||||
- `NetworkPingMessage`
|
|
||||||
- Client
|
|
||||||
- `ConnectMessage`
|
|
||||||
- `DisconnectMessage`
|
|
||||||
- `ErrorMessage`
|
|
||||||
- `SceneMessage`
|
|
||||||
- `NetworkPongMessage`
|
|
||||||
|
|
||||||
### Tips
|
|
||||||
|
|
||||||
- Register handlers for messages in `OnStartServer` and `OnStartClient`. They're called from StartServer/StartHost, and StartClient, respectively.
|
|
||||||
- Send a message to the client if authentication fails, especially if there's some issue they can resolve.
|
|
||||||
- Call the `Disconnect()` method of the `NetworkConnection` on the server and client when authentication fails. If you want to give the user a few tries to get their credentials right, you certainly can, but Mirror will not do the disconnect for you.
|
|
||||||
- Remember to put a small delay on the Disconnect call on the server if you send a failure message so that it has a chance to be delivered before the connection is dropped.
|
|
||||||
- `NetworkConnection` has an `authenticationData` object where you can drop any data you need to persist on the server related to the authentication, such as account id's, tokens, character selection, etc.
|
|
||||||
|
|
||||||
Now that you have the foundation of a custom Authenticator component, the rest is up to you. You can exchange any number of custom messages between the server and client as necessary to complete your authentication process before approving the client.
|
|
||||||
|
|
||||||
Authentication can also be extended to character selection and customization, just by crafting additional messages and exchanging them with the client before completing the authentication process. This means this process takes place before the client player actually enters the game or changes to the Online scene.
|
|
||||||
|
|
||||||
If you write a good authenticator, consider sharing it with other users or donating it to the Mirror project.
|
|
@ -1,4 +0,0 @@
|
|||||||
- name: Overview
|
|
||||||
href: index.md
|
|
||||||
- name: Basic Authenticator
|
|
||||||
href: Basic.md
|
|
Before Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 38 KiB |
@ -1,26 +0,0 @@
|
|||||||
# Network Animator
|
|
||||||
|
|
||||||
The Network Animator component allows you to synchronize animation states for networked objects. It synchronizes state and parameters from an Animator Controller.
|
|
||||||
|
|
||||||
Note that if you create a Network Animator component on an empty game object, Mirror also creates a Network Identity component and an Animator component on that game object.
|
|
||||||
|
|
||||||
![The Network Animator component in the Inspector window](NetworkAnimatorComponent.png)
|
|
||||||
|
|
||||||
- **Client Authority**
|
|
||||||
Enable this to have changes to animation parameters sent from client to server.
|
|
||||||
|
|
||||||
- **Animator**
|
|
||||||
Use this field to define the Animator component you want the Network Animator to synchronize with.
|
|
||||||
|
|
||||||
Normally, changes are sent to all observers of the object this component is on. Setting **Sync Mode** to Owner Only makes the changes private between the server and the client owner of the object.
|
|
||||||
|
|
||||||
You can use the **Sync Interval** to specify how often it syncs (in seconds).
|
|
||||||
|
|
||||||
## Details
|
|
||||||
|
|
||||||
The Network Animator ensures the synchronization of game object animation across the network, meaning that all players see the animation happen at the same. There are two kinds of authority for networked animation (see documentation on [network authority](../Guides/Authority.md)):
|
|
||||||
|
|
||||||
> **NOTE:** Animator Triggers are not synced directly. Call `NetworkAnimator.SetTrigger` instead. A game object with authority can use the SetTrigger function to fire an animation trigger on other clients.
|
|
||||||
|
|
||||||
- If the game object has authority on the client, you should animate it locally on the client that owns the game object. That client sends the animation state information to the server, which broadcasts it to all the other clients. For example, this may be suitable for player characters with client authority.
|
|
||||||
- If the game object has authority on the server, then you should animate it on the server. The server then sends state information to all clients. This is common for animated game objects that are not related to a specific client, such as scene objects and non-player characters, or server-authoritative clients.
|
|
Before Width: | Height: | Size: 40 KiB |
@ -1,119 +0,0 @@
|
|||||||
# Network Discovery
|
|
||||||
|
|
||||||
Suppose your are next to a friend. He starts a game in host mode and you want to join him. How will your phone locate his? Finding out his IP address is not exactly intuitive or something kids can do.
|
|
||||||
|
|
||||||
To solve this problem you can use Network Discovery. When your game starts, it sends a message in your current network asking "Is there any server available?". Any server within the same network will reply and provide information about how to connect to it.
|
|
||||||
|
|
||||||
Mirror comes with a simple implementation of Network Discovery you can simply use in your game. It also provides a way for you to extend it so that you can pass additional data during the discovery phase.
|
|
||||||
|
|
||||||
![Inspector](NetworkDiscovery.png)
|
|
||||||
|
|
||||||
NetworkDiscovery and NetworkDiscoveryHUD components are included, or you can make your own from a [ScriptTemplate](../General/ScriptTemplates.md).
|
|
||||||
|
|
||||||
Network Discovery uses a UDP broadcast on the LAN enabling clients to find the running server and connect to it.
|
|
||||||
|
|
||||||
When a server is started, it listens on the UDP Broadcast Listen Port for requests from clients and returns a connection URI that clients apply to their transport.
|
|
||||||
|
|
||||||
You can adjust how often the clients send their requests out to find a server in seconds with the Active Discovery Interval.
|
|
||||||
|
|
||||||
The Server Found event must be assigned to a handler method, e.g. the OnDiscoveredServer method of NetworkDiscoveryHUD.
|
|
||||||
|
|
||||||
In the NetworkDiscoveryHUD, the NetworkDiscovery component should be assigned automatically.
|
|
||||||
|
|
||||||
## Quick Start
|
|
||||||
|
|
||||||
To use Network Discovery follow these steps:
|
|
||||||
|
|
||||||
1. Create a gameobject with a NetworkManager if you have not done so already
|
|
||||||
2. Do not add a NetworkManagerHUD. Discovery has a different UI component.
|
|
||||||
3. Add a NetworkDiscoveryHUD component to the NetworkManager gameobject.
|
|
||||||
A NetworkDiscovery component will be automatically added and wired up to your HUD.
|
|
||||||
4. Add a player to the NetworkManager if you have not done so.
|
|
||||||
5. Build and run a standalone version
|
|
||||||
6. Click on Start Host
|
|
||||||
7. Start play mode in the editor and click on Find Servers
|
|
||||||
8. The editor should find the standalone version and display a button
|
|
||||||
9. Click on the button to connect to it.
|
|
||||||
|
|
||||||
The NetworkDiscoveryHUD is provided as a simple and quick way to get started, but you will probably want to replace it with your own user interface.
|
|
||||||
|
|
||||||
## Custom Network Discovery
|
|
||||||
|
|
||||||
You can completely replace the user interface by adding your own interface (typically Unity UI based) instead of the default NetworkDiscoveryHUD. You do still need the NetworkDiscovery component to do the heavy lifting.
|
|
||||||
|
|
||||||
Sometimes you want to provide more information in the discovery messages. Some use cases could include:
|
|
||||||
|
|
||||||
- The client can show if the server is in PvP or PvE mode
|
|
||||||
- The client can show how full the servers are.
|
|
||||||
- The client can show the ping to each server so the player can chose the fastest server
|
|
||||||
- The client can show the language
|
|
||||||
- The client can show if the server is password protected
|
|
||||||
|
|
||||||
To do this, we've provided a [Template](../General/ScriptTemplates.md), so from the Assets menu, click Create > Mirror > Network Discovery.
|
|
||||||
|
|
||||||
This will create a script in your project with 2 empty message classes and a custom NetworkDiscovery class that inherits from NetworkDiscoveryBase and has all the override methods included and documented for you.
|
|
||||||
|
|
||||||
The message classes define what is sent between the client and server. As long as you keep your messages simple using the [data types](../Guides/DataTypes.md) that Mirror can serialize, you won't need to write custom serializers for them.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
public struct DiscoveryRequest : NetworkMessage
|
|
||||||
{
|
|
||||||
public string language;
|
|
||||||
|
|
||||||
// Add properties for whatever information you want sent by clients
|
|
||||||
// in their broadcast messages that servers will consume.
|
|
||||||
}
|
|
||||||
|
|
||||||
enum GameMode {PvP, PvE};
|
|
||||||
|
|
||||||
public struct DiscoveryResponse : NetworkMessage
|
|
||||||
{
|
|
||||||
// you probably want uri so clients know how to connect to the server
|
|
||||||
public Uri uri;
|
|
||||||
|
|
||||||
public GameMode GameMode;
|
|
||||||
public int TotalPlayers;
|
|
||||||
public int HostPlayerName;
|
|
||||||
|
|
||||||
// Add properties for whatever information you want the server to return to
|
|
||||||
// clients for them to display or consume for establishing a connection.
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The custom NetworkDiscovery class contains the overrides for handling the messages above.
|
|
||||||
|
|
||||||
You may want to refer to the NetworkDiscovery.cs script in the Components/Discovery folder to see how these should be implemented.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
public class NewNetworkDiscovery: NetworkDiscoveryBase<DiscoveryRequest, DiscoveryResponse>
|
|
||||||
{
|
|
||||||
#region Server
|
|
||||||
|
|
||||||
protected override void ProcessClientRequest(DiscoveryRequest request, IPEndPoint endpoint)
|
|
||||||
{
|
|
||||||
base.ProcessClientRequest(request, endpoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override DiscoveryResponse ProcessRequest(DiscoveryRequest request, IPEndPoint endpoint)
|
|
||||||
{
|
|
||||||
// TODO: Create your response and return it
|
|
||||||
return new DiscoveryResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Client
|
|
||||||
|
|
||||||
protected override DiscoveryRequest GetRequest()
|
|
||||||
{
|
|
||||||
return new DiscoveryRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ProcessResponse(DiscoveryResponse response, IPEndPoint endpoint)
|
|
||||||
{
|
|
||||||
// TODO: a server replied, do something with the response such as invoking a unityevent
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
```
|
|
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 218 KiB |
@ -1,9 +0,0 @@
|
|||||||
# Network Headless Logger
|
|
||||||
|
|
||||||
Network Headless Logger replaces the the default log handler with one that set `Console.ForegroundColor`.
|
|
||||||
|
|
||||||
Only replaces the handler when running in headless mode.
|
|
||||||
|
|
||||||
![Inspector](NetworkHeadlessLogger.png)
|
|
||||||
|
|
||||||
`showExceptionStackTrace` will log the stack trace of any exceptions sent to the handler.
|
|
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 12 KiB |
@ -1,31 +0,0 @@
|
|||||||
# Network Identity
|
|
||||||
|
|
||||||
**See also <xref:Mirror.NetworkIdentity> in the API Reference.**
|
|
||||||
|
|
||||||
The Network Identity component is at the heart of the Unity networking high-level API. It controls a game object’s unique identity on the network, and it uses that identity to make the networking system aware of the game object. It offers two different options for configuration and they are mutually exclusive, which means either one of the options or none can be checked.
|
|
||||||
- **Server Only**
|
|
||||||
Tick this checkbox to ensure that Unity only spawns the game object on the server, and not on clients.
|
|
||||||
|
|
||||||
![Inspector](NetworkIdentity.PNG)
|
|
||||||
|
|
||||||
## Instantiated Network Game Objects
|
|
||||||
|
|
||||||
With the Mirror’s server-authoritative networking system, the server must spawn networked game objects with network identities, using `NetworkServer.Spawn`. This automatically creates them on clients that are connected to the server, and assigns them a `netId`.
|
|
||||||
|
|
||||||
You must put a Network Identity component on any Prefabs that spawn at runtime for the network system to use them. See [Object Spawning](../Guides/GameObjects/SpawnObject.md) for more information.
|
|
||||||
|
|
||||||
## Scene-based Network Game Objects
|
|
||||||
|
|
||||||
You can also network game objects that are saved as part of your Scene (for example, environmental props). Networking game objects makes them behave slightly differently, because you need to have them spawn across the network.
|
|
||||||
|
|
||||||
When building your game, Unity disables all Scene-based game objects with Network Identity components. When a client connects to the server, the server sends spawn messages to tell the client which Scene game objects to enable and what their most up-to-date state information is. This ensures the client’s game does not contain game objects at incorrect locations when they start playing, or that Unity does not spawn and immediately destroy game objects on connection (for example, if an event removed the game object before that client connected). See [Networked Scene Game Objects](../Guides/GameObjects/SceneObjects.md) for more information.
|
|
||||||
|
|
||||||
## Preview Pane Information
|
|
||||||
|
|
||||||
This component contains network tracking information, and displays that information in the preview pane. For example, the scene ID, network ID and asset ID the object has been assigned. This allows you to inspect the information which can be useful for investigation and debugging.
|
|
||||||
|
|
||||||
![Preview](NetworkIdentityPreview.png)
|
|
||||||
|
|
||||||
At runtime there is more information to display here (a disabled NetworkBehaviour is displayed non-bold):
|
|
||||||
|
|
||||||
![Runtime Preview](NetworkIdentityPreviewRuntime.png)
|
|
Before Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 16 KiB |
@ -1,15 +0,0 @@
|
|||||||
# Network Lerp Rigidbody
|
|
||||||
|
|
||||||
> The Network Lerp Rigidbody classed as "Experimental" for now so please share any problems or bugs you find with it and use at your own risk if production builds.
|
|
||||||
|
|
||||||
The Network Lerp Rigidbody component synchronizes position and velocity of a rigidbody across the network. This component is useful when you have a non-kinematic rigidbody that have constant forces applied to them, like gravity, but also want to apply forces or change velocity to that rigidbody or server or client with authority. For example, objects that move and jump using rigidbody using gravity.
|
|
||||||
|
|
||||||
A game object with a Network Rigidbody component must also have a Network Identity component. When you add a Network Rigidbody component to a game object, Mirror also adds a Network Identity component on that game object if it does not already have one.
|
|
||||||
|
|
||||||
When using the Network Lerp Rigidbody you should NOT have NetworkTransform on the same object as the Network Lerp Rigidbody will handle syncing the position
|
|
||||||
|
|
||||||
By default, Network Lerp Rigidbody is server-authoritative unless you check the box for **Client Authority**. Client Authority applies to player objects as well as non-player objects that have been specifically assigned to a client, but only for this component. With this enabled, value changes are send from the client to the server.
|
|
||||||
|
|
||||||
Normally, changes are sent to all observers of the object this component is on. Setting **Sync Mode** to Owner Only makes the changes private between the server and the client owner of the object.
|
|
||||||
|
|
||||||
You can use the **Sync Interval** to specify how often it syncs (in seconds). This applies both to Client Authority and Server Authority.
|
|
@ -1,93 +0,0 @@
|
|||||||
# Network Manager
|
|
||||||
|
|
||||||
The Network Manager is a component for managing the networking aspects of a multiplayer game.
|
|
||||||
|
|
||||||
The Network Manager features include:
|
|
||||||
- Game state management
|
|
||||||
- Spawn management
|
|
||||||
- Scene management
|
|
||||||
- Debugging information
|
|
||||||
- Customization
|
|
||||||
|
|
||||||
**See also <xref:Mirror.NetworkManager> in the API Reference.**
|
|
||||||
|
|
||||||
## Getting Started with the Network Manager
|
|
||||||
|
|
||||||
The Network Manager is the core controlling component of a multiplayer game. To get started, create an empty game object in your starting Scene, and add the Network Manager component. The newly added Network Manager component looks like this:
|
|
||||||
|
|
||||||
![The Network Manager as seen in the inspector window](NetworkManagerInspector.png)
|
|
||||||
|
|
||||||
The Inspector for the Network Manager in the Editor allows you to configure and control many things related to networking.
|
|
||||||
|
|
||||||
**Note**: You can only ever have one active Network Manager in each scene because it's a singleton. Do not place the Network Manager component on a networked game object (one which has a Network Identity component), because Mirror disables these when the Scene loads.
|
|
||||||
|
|
||||||
If you are already familiar with multiplayer game development, you might find it useful to know that the Network Manager component is implemented entirely using the API, so everything it does is also available to you through scripting. For advanced users, if you find that you need to expand on the Network Manager component’s features, you can use scripting to derive your own class from Network Manager and customize its behavior by overriding any of the virtual function hooks that it provides. However, the Network Manager component wraps up a lot of useful functionality into a single place, and makes creating, running and debugging multiplayer games as simple as possible.
|
|
||||||
|
|
||||||
## Transports
|
|
||||||
|
|
||||||
Mirror uses a separate component (derived from the Transport class) to connect across the network. By default, it is Kcp Transport. This design choice of separating the transport into its own component allows game developers to choose the transport that best fits their game needs. Changing transports is as simple as swapping out the component on the Network Manager object and assigning it to the Transport field.
|
|
||||||
|
|
||||||
Transports are available for TCP, UDP, WebGL, and Steam. Additionally, there's a Multiplex transport that allows for using two transports together on the server, e.g. Telepathy and WebSockets, so that desktop and browser players can play together on the same server seamlessly. See [Transports](../Transports/index.md) for more information.
|
|
||||||
|
|
||||||
## Game State Management
|
|
||||||
|
|
||||||
A Networking multiplayer game can run in three modes - as a client, as a dedicated server, or as a host which is both a client and a server at the same time.
|
|
||||||
|
|
||||||
If you’re using the Network Manager HUD, it automatically tells the Network Manager which mode to start in, based on which button the player clicks. If you’re writing your own UI that allows the player to start the game, you’ll need to call these from your own code. These methods are:
|
|
||||||
- NetworkManager.StartClient
|
|
||||||
- NetworkManager.StartServer
|
|
||||||
- NetworkManager.StartHost
|
|
||||||
|
|
||||||
![The network address and port settings in the Network Manager and Telepathy components](NetworkAddressAndPortSettings.png)
|
|
||||||
|
|
||||||
Whichever mode the game starts in (client, server, or host), the Network Address and Transport Port properties are used.
|
|
||||||
- In client mode, the game attempts to connect to the address and port specified. A fully-qualified domain name (FQDN) can also be used for the Network Address, e.g. "game.example.com".
|
|
||||||
- In server or host mode, the game listens for incoming connections on the port specified, but does not bind to any specific IP address (it listens on all available).
|
|
||||||
|
|
||||||
## Spawn Management
|
|
||||||
|
|
||||||
Use the Network Manager to manage the spawning (networked instantiation) of networked game objects from Prefabs.
|
|
||||||
|
|
||||||
![The “Spawn Info” section of the Network Manager component](NetworkManagerSpawnInfo.png)
|
|
||||||
|
|
||||||
Most games have a Prefab which represents the player, so the Network Manager has a Player Prefab slot. You should assign this slot with your player Prefab. When you have a player Prefab set, a player game object is automatically spawned from that Prefab for each user in the game. This applies to the local player on a hosted server, and remote players on remote clients. You must attach a Network Identity component to the Player Prefab before assigning it to this field.
|
|
||||||
|
|
||||||
Once you have assigned a Player Prefab, you can start the game as a host and see the player game object spawn. Stopping the game destroys the player game object . If you build and run another copy of the game and connect it as a client to *localhost*, the Network Manager makes another player game object appear. When you stop that client, it destroys that player’s game object.
|
|
||||||
|
|
||||||
In addition to the Player Prefab, you must also register other prefabs that you want to dynamically spawn during game play with the Network Manager.
|
|
||||||
|
|
||||||
You can add prefabs to the list shown in the inspector labelled Registered Spawnable Prefabs. You can also register prefabs via code, with the `ClientScene.RegisterPrefab` method.
|
|
||||||
|
|
||||||
If you have one Network Manager that is persisted through scenes via Don't Destroy On Load (DDOL), you need to register all prefabs to it which might be spawned in any scene. If you have a separate Network Manager in each scene, you only need to register the prefabs relevant for that scene.
|
|
||||||
|
|
||||||
## Start Positions
|
|
||||||
|
|
||||||
The Network Manager will spawn Player Prefab at their defined transform position and rotation by default, however the Player Spawn Method property allows you to control how start positions are chosen in conjunction with [Network Start Position](NetworkStartPosition.md) components.
|
|
||||||
- Choose Random to spawn players at randomly chosen startPosition options.
|
|
||||||
- Choose Round Robin to cycle through startPosition options in a set list.
|
|
||||||
|
|
||||||
If the Random or Round Robin modes don’t suit your game, you can customize how the start positions are selected by using code. You can access the available Network Start Position components by the list `NetworkManager.startPositions`, and you can use the helper method `GetStartPosition` on the Network Manager that can be used in an implementation of `OnServerAddPlayer` to find a start position.
|
|
||||||
|
|
||||||
## Scene Management
|
|
||||||
|
|
||||||
Most games have more than one scene. At the very least, there is usually a title screen or starting menu scene in addition to the scene where the game is actually played. The Network Manager is designed to automatically manage scene state and scene transitions in a way that works for a multiplayer game.
|
|
||||||
|
|
||||||
There are two slots on the Network Manager inspector for scenes: the Offline Scene and the Online Scene. Dragging scene assets into these slots activates networked Scene Management.
|
|
||||||
|
|
||||||
When a server or host is started, the Online Scene is loaded. This then becomes the current network scene. Any clients that connect to that server are instructed to also load that scene. The name of this scene is stored in the `networkSceneName` property.
|
|
||||||
|
|
||||||
When the network is stopped, by stopping the server or host or by a client disconnecting, the offline Scene is loaded. This allows the game to automatically return to a menu scene when disconnected from a multiplayer game.
|
|
||||||
|
|
||||||
You can also change scenes while the game is active by calling `ServerChangeScene`. This makes all the currently connected clients change Scene too, and updates `networkSceneName` so that new clients also load the new Scene.
|
|
||||||
|
|
||||||
While networked Scene management is active, any calls to game state management functions such as `StartHost` or `StopClient` can cause scene changes. This applies to the runtime control UI. By setting up scenes and calling these methods, you can control the flow of your multiplayer game.
|
|
||||||
|
|
||||||
Note that scene change causes all the game objects in the previous scene to be destroyed.
|
|
||||||
|
|
||||||
You should normally make sure the Network Manager persists between Scenes, otherwise the network connection is broken upon a scene change. To do this, ensure the Don’t Destroy On Load checkbox is ticked in the inspector. However it is also possible to have a separate Network Manager in each scene with different settings, which may be helpful if you wish to control incremental prefab loading, or different scene transitions.
|
|
||||||
|
|
||||||
## Customization
|
|
||||||
|
|
||||||
There are virtual functions on the `NetworkManager` class that you can customize by creating your own derived class that inherits from `NetworkManager`. When implementing these functions, be sure to take care of the functionality that the default implementations provide. For example, in `OnServerAddPlayer`, the function `NetworkServer.AddPlayer` must be called to activate the player game object for the connection.
|
|
||||||
|
|
||||||
To make this easier, we've made a set of [Script Templates](../General/ScriptTemplates.md) that have all the overrides stubbed out for you.
|
|
@ -1,65 +0,0 @@
|
|||||||
# Network Manager HUD
|
|
||||||
|
|
||||||
The Network Manager HUD (“heads-up display”) is a quick-start tool to help you start building your multiplayer game straight away, without first having to build a user interface for game creation/connection/joining. It allows you to jump straight into your game play programming, and means you can build your own version of these controls later in your development schedule.
|
|
||||||
|
|
||||||
It is not, however, intended to be included in finished games. The idea is that these controls are useful to get you started, but you should create your own UI later on, to allow your players to find and join games in a way that suits your game. For example, you might want to stylize the design of the screens, buttons and list of available games to match the overall style of your game.
|
|
||||||
|
|
||||||
To start using the Network Manager HUD, either add the component to the same scene object that has the Network Manager component, or create an empty game object in your scene (menu: game object \> Create Empty) and add the Network Manager HUD component to the new game object.
|
|
||||||
|
|
||||||
![The Network Manager HUD component, as viewed in the inspector](NetworkManagerHUDComponent.png)
|
|
||||||
- **Show GUI**
|
|
||||||
Tick this checkbox to show the HUD GUI at run time. This allows you to reveal or hide it for quick debugging.
|
|
||||||
- **Offset X**
|
|
||||||
Set the horizontal **pixel** offset of the HUD GUI, measured from the left edge of the screen.
|
|
||||||
- **Offset Y**
|
|
||||||
Set the vertical pixel offset of the HUD GUI, measured from the top edge of the screen.
|
|
||||||
|
|
||||||
The Network Manager HUD provides the basic functions so that people playing your game can start hosting a networked game, or find and join an existing networked game. Unity displays the Network Manager HUD as a collection of simple UI buttons in the Game view.
|
|
||||||
|
|
||||||
![The Network Manager HUD GUI, as viewed in the Game view](NetworkManagerHUDUI.png)
|
|
||||||
|
|
||||||
## Using the HUD
|
|
||||||
|
|
||||||
The Network Manager HUD starts in Server + Client mode, and displays buttons relating to hosting and joining a multiplayer game.
|
|
||||||
|
|
||||||
### Host (Server + Client)
|
|
||||||
|
|
||||||
Click the Host (Server + Client) button to start a game as a host on the local network. This client is both the host *and* one of the players in the game. It uses the information from the Network Info section in the inspector to host the game.
|
|
||||||
|
|
||||||
When you click this button, the HUD switches to a simple display of network details, and a Stop button which allows you to stop hosting the game and return to the main HUD menu.
|
|
||||||
|
|
||||||
![The Network Manager HUD GUI when hosting a game.](NetworkManagerHUDHostingLAN.png)
|
|
||||||
|
|
||||||
When you have started a game as a host, other players of the game can then connect to the host to join the game.
|
|
||||||
|
|
||||||
Click the Stop button to disconnect from the host. Clicking Stop also returns to the main HUD menu.
|
|
||||||
|
|
||||||
### Client
|
|
||||||
|
|
||||||
To connect to a host on the internet use the text field to the right of the Client button to specify the address of the host. The default host address is “localhost”, which means the client looks on its own computer for the game host. In addition to *localhost*, you can specify an IPv4 address, and IPv6 address, or a fully-qualified domain name (FQDN), e.g. *game.example.com*, and the transport with resolve the name using DNS. Click Client to attempt to connect to the host address you have specified.
|
|
||||||
|
|
||||||
Use the default “localhost” in this field if you are running multiple instances of your game on one computer, to test multiplayer interactivity. To do this, you can create a standalone build of your game, and then launch it multiple times on your computer. This is a common way to quickly test that your networked game interactions are functioning as you expect, without you needing to deploy your game to multiple computers or devices.
|
|
||||||
|
|
||||||
![An example of three instances of a networked game running on the same desktop PC. This is useful for quick tests to ensure networked interactions are behaving as you intended. One is running as Host, and two are running as Client.](NetworkGame3Instances.jpg)
|
|
||||||
|
|
||||||
When you want to test your game on multiple machines you need to put the address of the computer acting as host into the address text field.
|
|
||||||
|
|
||||||
The computer acting as the host needs to tell their IP address to everyone running clients, so that you can type this into the box. For local clients on a LAN, that's the local IP address. For remote clients, that's the WAN IP address of the router of the host. Firewall rules and port-forwarding are generally required for a computer to act as host and accept connections from other computers, whether they're on the LAN or the internet.
|
|
||||||
|
|
||||||
Enter the IP address (or leave it as “localhost” if you are testing it on your own machine), then click Client to attempt to connect to the host.
|
|
||||||
|
|
||||||
When the client is attempting to connect, the HUD displays a Cancel Connection Attempt button. Click this if you want to stop trying to connect to the host.
|
|
||||||
|
|
||||||
![The HUD GUI while attempting a connection](NetworkManagerHUDConnectionAttempt.png)
|
|
||||||
|
|
||||||
If the connection is successful, the HUD displays the Stop button. Click this if you want to stop the game on the client and disconnect from the host:
|
|
||||||
|
|
||||||
![The HUD GUI after a successful connection](NetworkManagerHUDConnected.png)
|
|
||||||
|
|
||||||
### Server Only
|
|
||||||
|
|
||||||
Click Server Only to start a game which acts as a server that other clients can connect to, but which does not act as a client to the game itself. This type of game is often called a “dedicated server”. A user cannot play the game on this particular instance of your game. All players must connect as clients, and nobody plays on the instance that is running as the server.
|
|
||||||
|
|
||||||
A dedicated server results in better performance for all connected players, because the server doesn’t need to process a local player’s game play in addition to acting as server.
|
|
||||||
|
|
||||||
You might also choose this option if you want to host a game that can be played over the internet (rather than just within a local network), but want to maintain control of the server yourself - for example, to prevent cheating by one of the clients, because only the server has authority over the game. To do this, you would need to run the game in Server Only mode on a computer with a public IP address.
|
|
Before Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 7.9 KiB |
@ -1,13 +0,0 @@
|
|||||||
# Network Match Checker
|
|
||||||
|
|
||||||
The Network Match Checker component controls visibility of networked objects based on match id.
|
|
||||||
|
|
||||||
![Network Scene Checker component](NetworkMatchChecker.png)
|
|
||||||
|
|
||||||
Any object with this component on it will only be visible to other objects in the same match.
|
|
||||||
|
|
||||||
This would be used to isolate players to their respective matches within a single game server instance.
|
|
||||||
|
|
||||||
When you create a match, generate and store, in a List for example, a new match id with `System.Guid.NewGuid();` and assign the same match id to the Network Match Checker via `GetComponent<NetworkMatchChecker>().matchId`.
|
|
||||||
|
|
||||||
Mirror's built-in Observers system will isolate SyncVar's and ClientRpc's on networked objects to only send updates to clients with the same match id.
|
|
Before Width: | Height: | Size: 12 KiB |
@ -1,8 +0,0 @@
|
|||||||
# Network Owner Checker
|
|
||||||
|
|
||||||
The Network Owner Checker component controls visibility of networked objects based on owner client.
|
|
||||||
|
|
||||||
Any object with this component on it will only be visible to the client that has authority ownership of it.
|
|
||||||
|
|
||||||
This can be used when you want to spawn a network object with client authority and only have it appear for the owner, e.g. an interactive UI or NPC.
|
|
||||||
Since clients can call commands on objects they have authority over, such objects can have Network Behaviors with commands in them that can be called directly by the client.
|
|
@ -1,9 +0,0 @@
|
|||||||
# Network Ping Display
|
|
||||||
|
|
||||||
Network Ping Display shows the Ping time for clients using OnGUI.
|
|
||||||
|
|
||||||
The Ping time is the moving average of the (RTT) Round-trip delay time. RTT is calculated by the PingMessage/PongMessage between the client and server.
|
|
||||||
|
|
||||||
![Inspector](NetworkPingDisplay.png)
|
|
||||||
|
|
||||||
See [Clock Synchronization](../Guides/ClockSync.md) for more info.
|
|
Before Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 10 KiB |
@ -1,21 +0,0 @@
|
|||||||
# Network Proximity Checker
|
|
||||||
|
|
||||||
The Network Proximity Checker component controls the visibility of game objects for network clients, based on proximity to players.
|
|
||||||
|
|
||||||
![Network Proximity Checker component](NetworkProximityCheck.png)
|
|
||||||
- **Vis Range**
|
|
||||||
Define the range that the game object should be visible to observers.
|
|
||||||
- **Vis Update Interval**
|
|
||||||
Define how often (in seconds) the game object should check for observers entering its visible range.
|
|
||||||
- **Check Method**
|
|
||||||
Define which type of physics (2D or 3D) to use for proximity checking.
|
|
||||||
- **Force Hidden**
|
|
||||||
Tick this checkbox to hide this object from all players.
|
|
||||||
|
|
||||||
With the Network Proximity Checker, a game running on a client doesn’t have information about game objects that are not visible. This has two main benefits: it reduces the amount of data sent across the network, and it makes your game more secure against hacking.
|
|
||||||
|
|
||||||
This component relies on physics to calculate visibility, so observer game objects must also have a collider component on it.
|
|
||||||
|
|
||||||
A game object with a Network Proximity Checker component must also have a Network Identity component. When you create a Network Proximity Checker component on a game object, Mirror also creates a Network Identity component on that game object if it does not already have one.
|
|
||||||
|
|
||||||
Scene objects with a Network Proximity Checker component are disabled when they're out of range, and spawned objects are destroyed when they're out of range.
|
|
@ -1,21 +0,0 @@
|
|||||||
# Network Rigidbody
|
|
||||||
|
|
||||||
> The Network Rigidbody classed as "Experimental" for now so please share any problems or bugs you find with it and use at your own risk if production builds.
|
|
||||||
|
|
||||||
The Network Rigidbody component synchronizes velocity and other properties of a rigidbody across the network. This component is useful when you have a non-kinematic rigidbody that have constant forces applied to them, like gravity, but also want to apply forces or change velocity to that rigidbody or server or client with authority. For example, objects that move and jump using rigidbody using gravity.
|
|
||||||
|
|
||||||
A game object with a Network Rigidbody component must also have a Network Identity component. When you add a Network Rigidbody component to a game object, Mirror also adds a Network Identity component on that game object if it does not already have one.
|
|
||||||
|
|
||||||
Network Rigidbody works best when there is also a NetworkTransform for the object to keep position as well as velocity in sync.
|
|
||||||
|
|
||||||
![Network Rigidbody inspector](NetworkRigidbody.png)
|
|
||||||
|
|
||||||
By default, Network Rigidbody is server-authoritative unless you check the box for **Client Authority**. Client Authority applies to player objects as well as non-player objects that have been specifically assigned to a client, but only for this component. With this enabled, value changes are send from the client to the server.
|
|
||||||
|
|
||||||
The **Sensitivity** options allow you to set a minimum thresholds before values are send over network. This helps minimize network traffic for very small changes.
|
|
||||||
|
|
||||||
For some object you may not want them to rotate but don't need to sync the Angular Velocity. The **Clear Angular Velocity** will set the Angular Velocity to zero each frame causing the minimizing when objects rotation. If **Sync Angular Velocity** is enabled then clear is ignored. The same can apply to **Clear Velocity**.
|
|
||||||
|
|
||||||
Normally, changes are sent to all observers of the object this component is on. Setting **Sync Mode** to Owner Only makes the changes private between the server and the client owner of the object.
|
|
||||||
|
|
||||||
You can use the **Sync Interval** to specify how often it syncs (in seconds). This applies both to Client Authority and Server Authority.
|
|
Before Width: | Height: | Size: 37 KiB |
@ -1,103 +0,0 @@
|
|||||||
# Network Room Manager
|
|
||||||
|
|
||||||
\*\*Please see the Room example in the Examples folder in your Mirror folder
|
|
||||||
|
|
||||||
The Network Room Manager is a specialized type of [Network Manager](NetworkManager.md) that provides a multiplayer room before entering the main play scene of the game. It allows you to set up a network with:
|
|
||||||
- A maximum player limit
|
|
||||||
- Automatic start when all players are ready
|
|
||||||
- Option to prevent players from joining a game in progress
|
|
||||||
- Customizable ways for players to choose options while in room
|
|
||||||
|
|
||||||
There are two types of player objects with the Network Room Manager:
|
|
||||||
|
|
||||||
**Room Player Prefab**
|
|
||||||
- One for each player
|
|
||||||
- Created when client connects, or player is added
|
|
||||||
- Persists until client disconnects
|
|
||||||
- Holds ready flag and configuration data
|
|
||||||
- Handles commands in the room
|
|
||||||
- Must use the [Network Room Player](NetworkRoomPlayer.md) component
|
|
||||||
|
|
||||||
**Player Prefab**
|
|
||||||
- One for each player
|
|
||||||
- Created when game scene is started
|
|
||||||
- Destroyed when leaving game scene
|
|
||||||
- Handles commands in the game
|
|
||||||
|
|
||||||
![Network Room Manager](NetworkRoomManager.png)
|
|
||||||
|
|
||||||
## Properties
|
|
||||||
- **Show Room GUI**
|
|
||||||
Show the default OnGUI controls for the room.
|
|
||||||
- **Min Players**
|
|
||||||
Minimum number of players needed to start a game.
|
|
||||||
- **Room Player Prefab**
|
|
||||||
The prefab to create for players when they enter the room (requires Network Room Player component).
|
|
||||||
- **Room Scene**
|
|
||||||
The scene to use for the room.
|
|
||||||
- **Gameplay Scene**
|
|
||||||
The scene to use for main game play.
|
|
||||||
- **pendingPlayers**
|
|
||||||
List\<PendingPlayer\> that holds players that are ready to start playing.
|
|
||||||
- **roomSlots**
|
|
||||||
List\<NetworkRoomPlayer\> that manages the slots for connected clients in the room.
|
|
||||||
- **allPlayersReady**
|
|
||||||
Bool indicating if all players are ready to start playing. This value changes as players invoke `CmdChangeReadyState` indicating true or false, and will be set false when a new client connects.
|
|
||||||
|
|
||||||
## Methods
|
|
||||||
|
|
||||||
### Server Virtual Methods
|
|
||||||
|
|
||||||
```cs
|
|
||||||
public virtual void OnRoomStartHost() {}
|
|
||||||
|
|
||||||
public virtual void OnRoomStopHost() {}
|
|
||||||
|
|
||||||
public virtual void OnRoomStartServer() {}
|
|
||||||
|
|
||||||
public virtual void OnRoomServerConnect(NetworkConnection conn) {}
|
|
||||||
|
|
||||||
public virtual void OnRoomServerDisconnect(NetworkConnection conn) {}
|
|
||||||
|
|
||||||
public virtual void OnRoomServerSceneChanged(string sceneName) {}
|
|
||||||
|
|
||||||
public virtual GameObject OnRoomServerCreateRoomPlayer(NetworkConnection conn)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual GameObject OnRoomServerCreateGamePlayer(NetworkConnection conn)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool OnRoomServerSceneLoadedForPlayer(GameObject roomPlayer, GameObject gamePlayer)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnRoomServerPlayersReady()
|
|
||||||
{
|
|
||||||
ServerChangeScene(GameplayScene);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Client Virtual Methods
|
|
||||||
|
|
||||||
```cs
|
|
||||||
public virtual void OnRoomClientEnter() {}
|
|
||||||
|
|
||||||
public virtual void OnRoomClientExit() {}
|
|
||||||
|
|
||||||
public virtual void OnRoomClientConnect(NetworkConnection conn) {}
|
|
||||||
|
|
||||||
public virtual void OnRoomClientDisconnect(NetworkConnection conn) {}
|
|
||||||
|
|
||||||
public virtual void OnRoomStartClient() {}
|
|
||||||
|
|
||||||
public virtual void OnRoomStopClient() {}
|
|
||||||
|
|
||||||
public virtual void OnRoomClientSceneChanged(NetworkConnection conn) {}
|
|
||||||
|
|
||||||
public virtual void OnRoomClientAddPlayerFailed() {}
|
|
||||||
```
|
|
Before Width: | Height: | Size: 71 KiB |
@ -1,27 +0,0 @@
|
|||||||
# Network Room Player
|
|
||||||
|
|
||||||
The Network Room Player stores per-player state for the [Network Room Manager](NetworkRoomManager.md) while in the room. When using this component, you need to write a script which allows players to indicate they are ready to begin playing, which sets the ReadyToBegin property.
|
|
||||||
|
|
||||||
A game object with a Network Room Player component must also have a Network Identity component. When you create a Network Room Player component on a game object, Unity also creates a Network Identity component on that game object if it does not already have one.
|
|
||||||
|
|
||||||
![Network Room Player](NetworkRoomPlayer.png)
|
|
||||||
- **Show Room GUI**
|
|
||||||
Enable this to show the developer GUI for players in the room. This UI is only intended to be used for ease of development. This is enabled by default.
|
|
||||||
- **Ready To Begin**
|
|
||||||
Diagnostic indicator that a player is Ready.
|
|
||||||
- **Index**
|
|
||||||
Diagnostic index of the player, e.g. Player 1, Player 2, etc.
|
|
||||||
- **Network Sync Interval**
|
|
||||||
The rate at which information is sent from the Network Room Player to the server.
|
|
||||||
|
|
||||||
## Methods
|
|
||||||
|
|
||||||
### Client Virtual Methods
|
|
||||||
|
|
||||||
```cs
|
|
||||||
public virtual void OnClientEnterRoom() {}
|
|
||||||
|
|
||||||
public virtual void OnClientExitRoom() {}
|
|
||||||
|
|
||||||
public virtual void OnClientReady(bool readyState) {}
|
|
||||||
```
|
|
Before Width: | Height: | Size: 24 KiB |
@ -1,55 +0,0 @@
|
|||||||
# Network Scene Checker
|
|
||||||
|
|
||||||
The Network Scene Checker component controls the visibility of game objects for network clients, based on which scene they're in.
|
|
||||||
|
|
||||||
![Network Scene Checker component](NetworkSceneChecker.png)
|
|
||||||
|
|
||||||
- **Force Hidden**
|
|
||||||
Tick this checkbox to hide this object from all players.
|
|
||||||
|
|
||||||
With the Network Scene Checker, a game running on a client doesn’t have information about game objects that are not visible. This has two main benefits: it reduces the amount of data sent across the network, and it makes your game more secure against hacking.
|
|
||||||
|
|
||||||
This component would typically be used when the server has several subscenes loaded and needs to isolate networked objects to the subscene they're in.
|
|
||||||
|
|
||||||
A game object with a Network Scene Checker component must also have a Network Identity component. When you create a Network Scene Checker component on a game object, Mirror also creates a Network Identity component on that game object if it does not already have one.
|
|
||||||
|
|
||||||
Scene objects with a Network Scene Checker component are disabled when they're not in the same scene, and spawned objects are destroyed when they're not in the same scene.
|
|
||||||
|
|
||||||
## Use with Additive Scenes
|
|
||||||
|
|
||||||
In Mirror, the Server and connected Clients are always on the same main scene, however the server and clients can have various combinations of smaller subscenes loaded additively. The server may load all subscenes at start, or it may dynamically load and unload subscenes where players or other activity is going on as needed.
|
|
||||||
|
|
||||||
All player objects are always first spawned in the main scene, which may or may not have visual content, networked objects, etc. With this component attached to all networked objects, whenever the player object is moved to a subscene (from the main or from another subscene), the observers lists for objects in both the new scene and the prior scene are updated accordingly.
|
|
||||||
|
|
||||||
Loading the subscene(s) on the server is through the normal process with `SceneManager`:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
SceneManager.LoadSceneAsync(subScene, LoadSceneMode.Additive);
|
|
||||||
```
|
|
||||||
|
|
||||||
Next, you will send a `SceneMessage` to the client telling it to load a subscene additively:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
SceneMessage msg = new SceneMessage
|
|
||||||
{
|
|
||||||
sceneName = subScene,
|
|
||||||
sceneOperation = SceneOperation.LoadAdditive
|
|
||||||
};
|
|
||||||
|
|
||||||
connectionToClient.Send(msg);
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, on the server only, you just move the player object to the subscene:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
// Position the player object in world space first
|
|
||||||
// This assumes it has a NetworkTransform component that will update clients
|
|
||||||
player.transform.position = new Vector3(100, 1, 100);
|
|
||||||
|
|
||||||
// Then move the player object to the subscene
|
|
||||||
SceneManager.MoveGameObjectToScene(player, subScene);
|
|
||||||
```
|
|
||||||
|
|
||||||
Optionally you can send another `SceneMessage` to the client with `SceneOperation.UnloadAdditive` to remove any previous additive scene the client no longer needs. This would apply to a game that has levels after a level change. A short delay may be necessary before removal to allow the client to get fully synced.
|
|
||||||
|
|
||||||
Depending on the complexity of your game, you may find it helpful when switching a player between subscenes to move the player object to the main scene first, yield 100 ms, re-position it, and finally move it to the new subscene.
|
|
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 50 KiB |
@ -1,11 +0,0 @@
|
|||||||
# Network Start Position
|
|
||||||
|
|
||||||
To control where players are spawned, you can use the Network Start Position component.
|
|
||||||
|
|
||||||
To use these, attach a Network Start Position component to a game object in the scene, and position the game object where you would like one of the players to start. You can add as many start positions to your Scene as you like. The Network Manager detects all start positions in your Scene, and when it spawns each player instance, it uses the position and orientation of one of them.
|
|
||||||
|
|
||||||
The Network Manager will spawn players at (0, 0, 0) by default. Adding this component to a game object will automatically register/unregister its game object's transform to the Network Manager as an available spawning position.
|
|
||||||
|
|
||||||
Depending on the Network Manager Player Spawn Method setting the spawning is either Random (possible that the same spawn position will be used by two or more players) or Round Robin (use every available position, until there are more clients than spawn points).
|
|
||||||
|
|
||||||
![Inspector](NetworkStartPosition.PNG)
|
|
@ -1,15 +0,0 @@
|
|||||||
# Network Transform
|
|
||||||
|
|
||||||
The Network Transform component synchronizes the position, rotation, and scale of networked game objects across the network.
|
|
||||||
|
|
||||||
A game object with a Network Transform component must also have a Network Identity component. When you add a Network Transform component to a game object, Mirror also adds a Network Identity component on that game object if it does not already have one.
|
|
||||||
|
|
||||||
![The Network Transform component](NetworkTransform.png)
|
|
||||||
|
|
||||||
By default, Network Transform is server-authoritative unless you check the box for **Client Authority**. Client Authority applies to player objects as well as non-player objects that have been specifically assigned to a client, but only for this component. With this enabled, position changes are send from the client to the server.
|
|
||||||
|
|
||||||
Under **Sensitivity**, you can set the minimum thresholds of change to the transform values in order for network messages to be generated. This helps minimize network "noise" for minor twitch and jitter.
|
|
||||||
|
|
||||||
Normally, changes are sent to all observers of the object this component is on. Setting **Sync Mode** to Owner Only makes the changes private between the server and the client owner of the object.
|
|
||||||
|
|
||||||
You can use the **Sync Interval** to specify how often it syncs (in seconds).
|
|
Before Width: | Height: | Size: 45 KiB |
@ -1,11 +0,0 @@
|
|||||||
# Network Transform Child
|
|
||||||
|
|
||||||
The Network Transform Child component synchronizes the position and rotation of the child game object of a game object with a Network Transform component. You should use this component in situations where you need to synchronize an independently-moving child object of a Networked game object.
|
|
||||||
|
|
||||||
To use the Network Transform Child component, attach it to the same parent game object as the Network Transform, and use the Target field to define which child game object to apply the component settings to. You can have multiple Network Transform Child components on one parent game object .
|
|
||||||
|
|
||||||
![The Network Transform Child component](NetworkTransform.png)
|
|
||||||
|
|
||||||
You can modify **Compress Rotation** to save some bandwidth when synchronizing the rotation. You can use the **Network Sync Interval** to specify how often it syncs (in seconds).
|
|
||||||
|
|
||||||
This component takes authority into account, so local player game objects (which have local authority) synchronize their position from the client to server, then out to other clients. Other game objects (with server authority) synchronize their position from the server to clients.
|
|
@ -1,42 +0,0 @@
|
|||||||
# Components Overview
|
|
||||||
|
|
||||||
These core components are included in Mirror:
|
|
||||||
|
|
||||||
- [Network Animator](NetworkAnimator.md)
|
|
||||||
The Network Animator component allows you to synchronize animation states for networked objects. It synchronizes state and parameters from an Animator Controller.
|
|
||||||
- [Network Authenticator](Authenticators/index.md)
|
|
||||||
Network Authenticators facilitate integration of user accounts and credentials into your application.
|
|
||||||
- [Network Discovery](NetworkDiscovery.md)
|
|
||||||
Network Discovery uses a UDP broadcast on the LAN enabling clients to find the running server and connect to it.
|
|
||||||
- [Network Identity](NetworkIdentity.md)
|
|
||||||
The Network Identity component is at the heart of the Mirror networking high-level API. It controls a game object’s unique identity on the network, and it uses that identity to make the networking system aware of the game object. It offers two different options for configuration and they are mutually exclusive, which means either one of the options or none can be checked.
|
|
||||||
- [Network Headless Logger](NetworkHeadlessLogger.md)
|
|
||||||
Network Headless Logger adds color to log when running in headless mode
|
|
||||||
- [Network Lerp Rigidbody](NetworkLerpRigidbody.md)
|
|
||||||
The Network Lerp Rigidbody synchronizes position and velocity of a rigidbody across the network.
|
|
||||||
- [Network Manager](NetworkManager.md)
|
|
||||||
The Network Manager is a component for managing the networking aspects of a multiplayer game.
|
|
||||||
- [Network Manager HUD](NetworkManagerHUD.md)
|
|
||||||
The Network Manager HUD is a quick-start tool to help you start building your multiplayer game straight away, without first having to build a user interface for game creation/connection/joining. It allows you to jump straight into your gameplay programming, and means you can build your own version of these controls later in your development schedule.
|
|
||||||
- [Network Match Checker](NetworkMatchChecker.md)
|
|
||||||
The Network Match Checker component controls visibility of networked objects based on match id.
|
|
||||||
- [Network Owner Checker](NetworkOwnerChecker.md)
|
|
||||||
The Network Owner Checker component controls visibility of networked objects based on owner client.
|
|
||||||
- [Network Ping Display](NetworkPingDisplay.md)
|
|
||||||
Network Ping Display shows the Ping time for clients using OnGUI
|
|
||||||
- [Network Proximity Checker](NetworkProximityChecker.md)
|
|
||||||
The Network Proximity Checker component controls the visibility of game objects for network clients, based on proximity to players.
|
|
||||||
- [Network Rigidbody](NetworkRigidbody.md)
|
|
||||||
The Network Rigidbody synchronizes velocity and other properties of a rigidbody across the network.
|
|
||||||
- [Network Room Manager](NetworkRoomManager.md)
|
|
||||||
The Network Room Manager is an extension component of Network Manager that provides a basic functional room.
|
|
||||||
- [Network Room Player](NetworkRoomPlayer.md)
|
|
||||||
The Network Room Player is a component that's required on Player prefabs used in the Room Scene with the Network Room Manager above.
|
|
||||||
- [Network Scene Checker](NetworkSceneChecker.md)
|
|
||||||
The Network Scene Checker component controls visibility of networked objects between scenes.
|
|
||||||
- [Network Start Position](NetworkStartPosition.md)
|
|
||||||
Network Start Position is used by the Network Manager when creating player objects. The position and rotation of the Network Start Position are used to place the newly created player object.
|
|
||||||
- [Network Transform](NetworkTransform.md)
|
|
||||||
The Network Transform component synchronizes the movement and rotation of game objects across the network. Note that the network Transform component only synchronizes spawned networked game objects.
|
|
||||||
- [Network Transform Child](NetworkTransformChild.md)
|
|
||||||
The Network Transform Child component synchronizes the position and rotation of the child game object of a game object with a Network Transform component.
|
|
@ -1,41 +0,0 @@
|
|||||||
- name: Overview
|
|
||||||
href: index.md
|
|
||||||
- name: Network Animator
|
|
||||||
href: NetworkAnimator.md
|
|
||||||
- name: Network Authenticators
|
|
||||||
href: Authenticators/toc.yml
|
|
||||||
topicHref: Authenticators/index.md
|
|
||||||
- name: Network Discovery
|
|
||||||
href: NetworkDiscovery.md
|
|
||||||
- name: Network Identity
|
|
||||||
href: NetworkIdentity.md
|
|
||||||
- name: Network Headless Logger
|
|
||||||
href: NetworkHeadlessLogger.md
|
|
||||||
- name: Network Lerp Rigidbody
|
|
||||||
href: NetworkLerpRigidbody.md
|
|
||||||
- name: Network Manager
|
|
||||||
href: NetworkManager.md
|
|
||||||
- name: Network Manager HUD
|
|
||||||
href: NetworkManagerHUD.md
|
|
||||||
- name: Network Match Checker
|
|
||||||
href: NetworkMatchChecker.md
|
|
||||||
- name: Network Owner Checker
|
|
||||||
href: NetworkOwnerChecker.md
|
|
||||||
- name: Network Ping Display
|
|
||||||
href: NetworkPingDisplay.md
|
|
||||||
- name: Network Proximity Checker
|
|
||||||
href: NetworkProximityChecker.md
|
|
||||||
- name: Network Rigidbody
|
|
||||||
href: NetworkRigidbody.md
|
|
||||||
- name: Network Room Manager
|
|
||||||
href: NetworkRoomManager.md
|
|
||||||
- name: Network Room Player
|
|
||||||
href: NetworkRoomPlayer.md
|
|
||||||
- name: Network Scene Checker
|
|
||||||
href: NetworkSceneChecker.md
|
|
||||||
- name: Network StartPosition
|
|
||||||
href: NetworkStartPosition.md
|
|
||||||
- name: Network Transform
|
|
||||||
href: NetworkTransform.md
|
|
||||||
- name: Network Transform Child
|
|
||||||
href: NetworkTransformChild.md
|
|
@ -1,24 +0,0 @@
|
|||||||
# Additive Scenes Example
|
|
||||||
|
|
||||||
IMPORTANT: Make sure you have a layer in project settings called Player for this example to work well.
|
|
||||||
|
|
||||||
In Build Settings, remove all scenes and add all of the scenes from the Scenes folder in the following order:
|
|
||||||
- MainScene
|
|
||||||
- SubScene
|
|
||||||
|
|
||||||
Open the MainScene in the Editor and make sure the Sub Scenes list in the Network Manager component on the Network scene object contains the SubScene scene. This is already setup by default, but if the MainScene was opened and saved before putting the scenes in the Build Settings list, the Sub Scenes list may be cleared accidentally.
|
|
||||||
|
|
||||||
File -> Build and Run
|
|
||||||
|
|
||||||
Start up to 3 built instances: These will all be client players.
|
|
||||||
|
|
||||||
Press Play in the Editor and click Host (Server + Client) in the HUD
|
|
||||||
- This will be the host and the 1st player of up to 4. You can also use Server Only if you prefer.
|
|
||||||
|
|
||||||
Click Client in the built instances.
|
|
||||||
- WASDQE keys to move & turn your player capsule.
|
|
||||||
- There are objects in the corners of the scene hidden by Proximity Checkers.
|
|
||||||
- The big area in the middle is where the subscene will be loaded when you get near the shelter.
|
|
||||||
- There are also networked objects inside the subscene, also with Proximity Checkers.
|
|
||||||
- Since subscenes are only loaded for individual clients, other clients that are outside the middle Zone won't see what those in the subscene can see.
|
|
||||||
- If you play a built instance as Host or Server and play as client in the editor, you'll see the subscene content load and unload in the hierarchy as you move in and out of the middle Zone.
|
|
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 52 KiB |
@ -1,7 +0,0 @@
|
|||||||
# Basic
|
|
||||||
|
|
||||||
General description of Basic example.
|
|
||||||
|
|
||||||
![Basic Example](Basic.PNG)
|
|
||||||
|
|
||||||
![Basic Player](BasicPlayer.PNG)
|
|
Before Width: | Height: | Size: 40 KiB |
@ -1,36 +0,0 @@
|
|||||||
# Multiple Additive Scenes Example
|
|
||||||
|
|
||||||
In Build Settings, remove all scenes and add both of the scenes from the Scenes folder in the following order:
|
|
||||||
|
|
||||||
- Main
|
|
||||||
- Game
|
|
||||||
|
|
||||||
Open the Main scene in the Editor and make sure the Game Scene field in the MultiScene Network Manager on the Network scene object contains the Game scene. This is already setup by default, but if the Main scene was opened and saved before putting the scenes in the Build Settings list, the Game Scene field may be cleared accidentally.
|
|
||||||
|
|
||||||
## MultiScene Network Manager
|
|
||||||
|
|
||||||
The MultiScene Network Manager is derived from the base Network Manager and is responsible for additively loading the subscene instances and placing the players in their respective subscene instances and initializing player SyncVars. It has a Game Scene field where the Game subscene is assigned, and an Instances field to set how many instances are loaded on the server.
|
|
||||||
|
|
||||||
In this example, the subscene instances are additively loaded on the server with `localPhysicsMode = LocalPhysicsMode.Physics3D`. Physics subscenes do not auto-simulate, so each scene has a game object with a generic `PhysicsSimulator` script on it. This script does nothing on the client, only on the server.
|
|
||||||
|
|
||||||
Clients only ever have one instance of the subscene additively loaded (without `localPhysicsMode`), while server has them all. All networked objects have a `NetworkSceneChecker` component which is what isolates them to their specific subscene.
|
|
||||||
|
|
||||||
## Playing in the Instances
|
|
||||||
|
|
||||||
File -\> Build and Run
|
|
||||||
|
|
||||||
Start at least 3 built instances: These will all be client players.
|
|
||||||
|
|
||||||
Press Play in the Editor and click Host (Server + Client) in the HUD - This will be the host and the 1st player. You can also use Server Only if you prefer.
|
|
||||||
|
|
||||||
Click Client in the built instances.
|
|
||||||
|
|
||||||
- WASDQE keys to move & turn your player capsule, Space to jump.
|
|
||||||
|
|
||||||
- Colliding with the small colored spheres scores points base on their color.
|
|
||||||
|
|
||||||
- Colliding with the larger tumblers sends them rolling around...they're server-side non-kinematic rigidbodies.
|
|
||||||
|
|
||||||
- Only scores for the players in the same subscene are shown at the top of the game window.
|
|
||||||
|
|
||||||
![MultiScene Network Manager](MultiSceneNetworkManager.PNG)
|
|
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 229 KiB |
Before Width: | Height: | Size: 162 KiB |
Before Width: | Height: | Size: 9.7 KiB |