Culled some docs in favor of API, moved a few, navigation.

This commit is contained in:
Chris Langsenkamp 2019-09-19 07:00:50 -04:00
parent 82c647bd82
commit d635a3cec9
17 changed files with 80 additions and 251 deletions

View File

@ -1,5 +1,7 @@
# NetworkBehaviour
**See also [NetworkBehaviour API](../../api/Mirror.NetworkBehaviour.html).**
Network Behaviour scripts work with game objects that have a NetworkIdentity component. These scripts can perform high-level API functions such as Commands, ClientRpc's, SyncEvents and SyncVars.
With the server-authoritative system of Mirror, the server must use the `NetworkServer.Spawn` function to spawn game objects with Network Identity components. Spawning them this way assigns them a `netId` and creates them on clients connected to the server.

View File

@ -1,31 +0,0 @@
# NetworkClient
`NetworkClient` is a high-level API class that manages a network connection from a client to a server, and can send and receive messages between the client and the server. The `NetworkClient` class also helps to manage spawned network game object, and routing of RPC message and network events.
## Properties
- **active**
True while a client is connecting / connected.
- **allClients**
Deprecated. Use NetworkClient directly instead. There is always exactly one client.
- **connection**
The NetworkConnection game object this `NetworkClient` instance is using.
- **handlers**
The set of registered message handler functions.
- **isConnected**
True if the client is connected to a server.
- **numChannels**
Deprecated. QoS channels are available in some [Transports].
- **serverIP**
The IP address of the server this client is connected to.
- **serverPort**
Deprecated. Port was moved to the [Transports](../Transports/index.md) that support it.
## Methods
- static void **Connect**(string address)
- static void **Disconnect**()
- static void **RegisterHandler**\<T\>(Action\<NetworkConnection, T\> handler)
- static bool **Send**\<T\>(T message, int channelId = Channels.DefaultReliable)
- static void **Shutdown**()
- static void **UnregisterHandler**\<T\>()
 

View File

@ -1,84 +0,0 @@
# NetworkConnection
Network Connection is a high-level API class that encapsulates a network connection. `NetworkClient` objects have a single connection, and `NetworkServer`'s have multiple connections - one from each client. Network Connections have the ability to send byte arrays or serialized objects as network messages.
## Constructors
- **NetworkConnection**()
- **NetworkConnection**(string networkAddress)
- **NetworkConnection**(string networkAddress, int networkConnectionId)
## Properties
- **address**
The IP address of the end-point that this connection is connected to.
- **clientOwnedObjects**
The `HashSet` of objects that this connection has authority over.
- **connectionId**
The incremented connectionId for this connection.
- **hostId**
Deprecated. Use `connection.GetType() == typeof(NetworkConnection.md)` to check if it's a regular or local connection.
- **isReady**
Flag to control whether state updates are sent to this connection
- **lastMessageTime**
The last time that a message was received on this connection.
- **playerController**
A reference to the [NetworkIdentity](../Components/NetworkIdentity.md) playerController.
## Methods
- void **Disconnect**()
- bool **InvokeHandler**\<T\>(T msg)
- virtual bool **Send**\<T\>(T msg, int channelId = Channels.DefaultReliable)
- virtual void **TransportReceive**(ArraySegment\<byte\> buffer)
- virtual bool **TransportSend**(int channelId, byte[] bytes)
The NetworkConnection class has virtual functions that are called when data is sent to the transport layer or received from the transport layer. These functions allow specialized versions of NetworkConnection to inspect or modify this data, or even route it to different sources. These function are shown below, including the default behaviour:
```cs
public virtual void TransportRecieve(byte[] bytes, int numBytes, int channelId)
{
HandleBytes(bytes, numBytes, channelId);
}
public virtual bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error)
{
return NetworkTransport.Send(hostId, connectionId, channelId, bytes, numBytes, out error);
}
```
An example use of these function is to log the contents of incoming and outgoing packets. Below is an example of a `DebugConnection` class that is derived from `NetworkConnection` that logs the first 50 bytes of packets to the console. To use a class like this call the `SetNetworkConnectionClass()` function on a `NetworkClient` or `NetworkServer`.
```cs
class DebugConnection : NetworkConnection
{
public override void TransportRecieve(byte[] bytes, int numBytes, int channelId)
{
StringBuilder msg = new StringBuilder();
for (int i = 0; i < numBytes; i++)
{
var s = String.Format("{0:X2}", bytes[i]);
msg.Append(s);
if (i > 50) break;
}
UnityEngine.Debug.Log("TransportRecieve h:" + hostId + " con:" + connectionId + " bytes:" + numBytes + " " + msg);
HandleBytes(bytes, numBytes, channelId);
}
public override bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error)
{
StringBuilder msg = new StringBuilder();
for (int i = 0; i < numBytes; i++)
{
var s = String.Format("{0:X2}", bytes[i]);
msg.Append(s);
if (i > 50) break;
}
UnityEngine.Debug.Log("TransportSend h:" + hostId + " con:" + connectionId + " bytes:" + numBytes + " " + msg);
return NetworkTransport.Send(hostId, connectionId, channelId, bytes, numBytes, out error);
}
}
```

View File

@ -1,50 +0,0 @@
# NetworkServer
NetworkServer is a High-Level-API class that manages connections from multiple clients.
## Properties
- **active**
Checks if the server has been started.
- **connections**
A list of all the current connections from clients.
- **dontListen**
If you enable this, the server will not listen for incoming connections on the regular network port.
- **handlers**
Dictionary of the message handlers registered with the server.
- **hostTopology**
The host topology that the server is using.
- **localClientActive**
True if a local client is currently active on the server.
- **localConnection**
The connection to the local client. This is only used when in host mode
## Methods
- static bool **AddConnection**(NetworkConnection conn)
- static bool **AddPlayerForConnection**(NetworkConnection conn, GameObject player)
- static bool **AddPlayerForConnection**(NetworkConnection conn, GameObject player, Guid assetId)
- static void **ClearHandlers**()
- static void **Destroy**(GameObject obj)
- static void **DestroyPlayerForConnection**(NetworkConnection conn)
- static void **DisconnectAll**()
- static void **DisconnectAllConnections**()
- static bool **Listen**(int maxConns)
- static void **RegisterHandler**\<T\>(Action\<NetworkConnection, T\> handler)
- static bool **RemoveConnection**(int connectionId)
- static bool **ReplacePlayerForConnection**(NetworkConnection conn, GameObject player)
- static bool **ReplacePlayerForConnection**(NetworkConnection conn, GameObject player, Guid assetId)
- static void **Reset**()
- static bool **SendToAll**\<T\>(T msg, int channelId = Channels.DefaultReliable)
- static void **SendToClient**\<T\>(int connectionId, T msg)
- static void **SendToClientOfPlayer**\<T\>(NetworkIdentity identity, T msg)
- static void **SetAllClientsNotReady**()
- static void **SetClientNotReady**(NetworkConnection conn)
- static void **SetClientReady**(NetworkConnection conn)
- static void **Shutdown**()
- static void **Spawn**(GameObject obj)
- static void **Spawn**(GameObject obj, Guid assetId)
- static bool **SpawnObjects**()
- static bool **SpawnWithClientAuthority**(GameObject obj, GameObject player)
- static bool **SpawnWithClientAuthority**(GameObject obj, NetworkConnection conn)
- static bool **SpawnWithClientAuthority**(GameObject obj, Guid assetId, NetworkConnection conn)
- static void **UnregisterHandler**\<T\>()
- static void **UnSpawn**(GameObject obj)

View File

@ -1,16 +1,16 @@
# Classes Overview
Mirror includes the following classes:
- [NetworkServer](../../api/Mirror.NetworkServer.html)
Network Server is a High-Level-API class that manages connections from multiple clients.
- [NetworkClient](../../api/Mirror.NetworkClient.html)
Network Client is a high-level API class that manages a network connection from a client to a server, and can send and receive messages between the client and the server.
- [NetworkConnection](../../api/Mirror.NetworkConnecion.html)
Network Connection is a high-level API class that encapsulates a network connection.
- [NetworkBehaviour](NetworkBehaviour.md)
Network Behaviour scripts work with game objects that have a NetworkIdentity component. These scripts can perform high-level API functions such as Commands, ClientRpcs, SyncEvents and SyncVars.
- [Attributes](Attributes.md)
Networking attributes are added to member functions of NetworkBehaviour scripts, to make them run on either the client or server.
- [NetworkBehaviour](NetworkBehaviour.md)
Network Behaviour scripts work with game objects that have a NetworkIdentity component. These scripts can perform high-level API functions such as Commands, ClientRpcs, SyncEvents and SyncVars.
- [NetworkClient](../../api/Mirror.NetworkClient.html)
Network Client is a high-level API class that manages a network connection from a client to a server, and can send and receive messages between the client and the server.
- [NetworkConnection](../../api/Mirror.NetworkConnection.html)
Network Connection is a high-level API class that encapsulates a network connection.
- [NetworkServer](../../api/Mirror.NetworkServer.html)
Network Server is a High-Level-API class that manages connections from multiple clients.
- [SyncVars](SyncVars.md)
SyncVars are variables of scripts that inherit from NetworkBehaviour, which are synchronized from the server to clients.
- [SyncEvents](SyncEvent.md)

View File

@ -1,13 +1,13 @@
- name: NetworkServer
href: NetworkServer.md
- name: NetworkConnection
href: NetworkConnection.md
- name: NetworkClient
href: NetworkClient.md
- name: NetworkBehaviour
href: NetworkBehaviour.md
- name: Attributes
href: Attributes.md
- name: NetworkBehaviour
href: NetworkBehaviour.md
- name: NetworkClient
href: ../../api/Mirror.NetworkClient.html
- name: NetworkConnection
href: ../../api/Mirror.NetworkConnection.html
- name: NetworkServer
href: ../../api/Mirror.NetworkServer.html
- name: SyncVars
href: SyncVars.md
- name: SyncVar Hooks

View File

@ -0,0 +1,11 @@
# 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](BasicAuthenticator.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.

View File

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View File

@ -1,3 +0,0 @@
# NetworkController
General description of NetworkController

View File

@ -1,3 +0,0 @@
# NetworkNavMeshAgent
General description of NetworkNavMeshAgent

View File

@ -1,3 +0,0 @@
# NetworkRigidbody
General description of NetworkRigidbody

View File

@ -1,31 +1,29 @@
# Components Overview
General description of Components
- [NetworkManager](NetworkManager.md)
The Network Manager is a component for managing the networking aspects of a multiplayer game.
- [NetworkRoomManager](NetworkRoomManager.md)
The Network Room Manager is an extension component of Network Manager that provides a basic functional room.
- [NetworkRoomPlayer](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.
- [NetworkManagerHUD](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.
These core components are included in Mirror:
- [NetworkAnimator](NetworkAnimator.md)
The Network Animator component allows you to synchronize animation states for networked objects. It synchronizes state and parameters from an Animator Controller.
- [NetworkIdentity](NetworkIdentity.md)
The Network Identity component is at the heart of the Mirror networking high-level API. It controls a game objects 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.
- [NetworkStartPosition](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.
- [NetworkManager](NetworkManager.md)
The Network Manager is a component for managing the networking aspects of a multiplayer game.
- [NetworkManagerHUD](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.
- [NetworkProximityChecker](NetworkProximityChecker.md)
The Network Proximity Checker component controls the visibility of game objects for network clients, based on proximity to players.
- [NetworkStartPosition](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.
- [NetworkTransform](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.
- [NetworkTransformChild](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.
- [NetworkAnimator](NetworkAnimator.md)
The Network Animator component allows you to synchronize animation states for networked objects. It synchronizes state and parameters from an Animator Controller.
- [NetworkNavMeshAgent](NetworkNavMeshAgent.md)
Coming Soon
- [NetworkController](NetworkController.md)
Coming Soon
- [NetworkRigidbody](NetworkRigidbody.md)
Coming Soon
 
These additional components are also included:
- [BasicAuthenticator](BasicAuthenticator.md)
Simple username and password authenticator
- [NetworkRoomManager](NetworkRoomManager.md)
The Network Room Manager is an extension component of Network Manager that provides a basic functional room.
- [NetworkRoomPlayer](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.

View File

@ -1,26 +1,22 @@
- name: NetworkManager
href: NetworkManager.md
- name: NetworkRoomManager
href: NetworkRoomManager.md
- name: NetworkRoomPlayer
href: NetworkRoomPlayer.md
- name: NetworkManagerHUD
href: NetworkManagerHUD.md
- name: NetworkAnimator
href: NetworkAnimator.md
- name: NetworkIdentity
href: NetworkIdentity.md
- name: NetworkStartPosition
href: NetworkStartPosition.md
- name: NetworkManager
href: NetworkManager.md
- name: NetworkManagerHUD
href: NetworkManagerHUD.md
- name: NetworkProximityChecker
href: NetworkProximityChecker.md
- name: NetworkStartPosition
href: NetworkStartPosition.md
- name: NetworkTransform
href: NetworkTransform.md
- name: NetworkTransformChild
href: NetworkTransformChild.md
- name: NetworkAnimator
href: NetworkAnimator.md
- name: NetworkNavMeshAgent
href: NetworkNavMeshAgent.md
- name: NetworkController
href: NetworkController.md
- name: NetworkRigidbody
href: NetworkRigidbody.md
- name: BasicAuthenticator
href: BasicAuthenticator.md
- name: NetworkRoomManager
href: NetworkRoomManager.md
- name: NetworkRoomPlayer
href: NetworkRoomPlayer.md

View File

@ -49,6 +49,10 @@ At this point, you might get some compilation errors. Don't panic, these are eas
### 4. Remove NetworkSettings
Replace references to 'NetworkConnection.playerController` with `NetworkConnection.identity`. Click [here](PlayerControllerToIdentity.md) for guidance.
### 5. Remove NetworkSettings
NetworkSettings in UNet have channels, but this is flat out broken. Rather than ignoring your settings we removed channels from NetworkSettings completely. `sendInterval` is now set in code and / or the inspector too.
For example, if you have this code:
@ -73,9 +77,9 @@ public class NetStreamer : NetworkBehaviour
}
```
Please note that the default transport (Telepathy.md), completely ignores channels, all messages are reliable, sequenced and fragmented. They just work with no fuss. If you want to take advantage of unreliable channels use LLAPITransport instead.
Please note that the default transport [Telpathy](../Transports/Telepathy.md), completely ignores channels, all messages are reliable, sequenced and fragmented. They just work with no fuss. If you want to take advantage of unreliable channels use LLAPITransport instead.
### 5. Change SyncListStruct to SyncList
### 6. Change SyncListStruct to SyncList
There is a bug in the original UNet Weaver that makes it mess with our `Mirror.SyncListStruct` without checking the namespace. In Mirror, we fixed SyncLists so that they work with structs by default.
@ -91,7 +95,7 @@ replace them with:
public class SyncListQuest : SyncList<Quest> { }
```
### 6. Replace NetworkHash128 and NetworkInstanceId
### 7. Replace NetworkHash128 and NetworkInstanceId
These have been changed to System.Guid and uint, respectively.
@ -119,7 +123,7 @@ public sealed class SpawnItemMessage : MessageBase
}
```
### 7. Update your synclist callbacks
### 8. Update your synclist callbacks
In UNet, SyncLists have a callback delegate that gets called in the client whenever the list is updated. We have changed the callback to be a C\# event instead and we also pass the item that was updated/removed.
@ -169,13 +173,13 @@ public class MyBehaviour : NetworkBehaviour
Notice the callback will also work in the server in Mirror.
### 8. Replace Components
### 9. Replace Components
Every networked prefab and scene object needs to be adjusted. They will be using `NetworkIdentity` from Unet, and you need to replace that componenent with `NetworkIdentity` from Mirror. You may be using other network components, such as `NetworkAnimator` or `NetworkTransform`. All components from Unet should be replaced with their corresponding component from Mirror.
Note that if you remove and add a NetworkIdentity, you will need to reassign it in any component that was referencing it.
### 9. Update Extended Components
### 10. Update Extended Components
Some commonly extended components, such as NetworkManager, have changed method parameters in Mirror. A commonly used override is OnServerAddPlayer. Using the original HLAPI, your override may have looked like this:
@ -199,15 +203,15 @@ public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage
Note that in UNet the parameter "extraMessageReader" is optional, but in Mirror it is required.
### 10. Pick your transport
### 11. Pick your transport
You can choose one of several transports in Mirror. Open your NetworkManager gameobject, in the inspector you will see a `TelepathyTranport` component by default. Drag in one of the available transports and remove `TelepathyTransport` if you wish to use a UDP based transport instead.
### 11. Configure address and port
### 12. Configure address and port
In HLAPI, you configure the port and local address in the NetworkManager. One of our goals is to make Mirror transport independent. Not all transports need address and port. Some transports might even use more than one port at the same time, so these settings were inadequate. We removed the port and address and all other Network Info properties from NetworkManager, and we moved them to the transport components instead.
### 12. Update your firewall and router
### 13. Update your firewall and router
LLAPI uses UDP. Mirror uses TCP by default. This means you may need to change your router port forwarding and firewall rules in your machine to expose the TCP port instead of UDP. This highly depends on your router and operating system.

View File

@ -2,7 +2,7 @@
If you need to fix up a project after `NetworkConnection.playerController` was changed to `identity` these instructions should be helpful.
1.Open your Unity project and look for Assets/Mirror/Runtime/**NetworkConnection**:
1. Open your Unity project and look for Assets/Mirror/Runtime/**NetworkConnection**:
![Project window in Unity](pc2i-1.png)
@ -21,7 +21,7 @@ The line numbers could be off a bit if minor file changes happen above them afte
```
4. Double-click and then right-click `playerController` and select Rename:
4. Double-click and then right-click `playerController` and select Rename:
![Start of Rename process](pc2i-3.png)

View File

@ -9,20 +9,21 @@ When you have a multiplayer game, often you need to store information about your
- Use Game Center in IOS
- Use a web service in your website
Mirror includes an `Authenticator` abstract class that allows you to implement any authentication scheme you need.
## Encryption Warning
By default Mirror uses Telepathy, which is not encrypted, so if you want to do authentication through Mirror, we highly recommend you use a transport that supports encryption.
## Custom Authenticators
Mirror includes an `Authenticator` abstract class that allows you to implement any authentication scheme you need.
To make your own custom Authenticator, you can just create a new script in your project (not in the Mirror folders) that inherits from `Authenticator` and override the methods as needed.
- When a client is authenticated to your satisfaction, you simply call `base.OnServerAuthenticated.Invoke(conn)` and `base.OnClientAuthenticated.Invoke(conn)` on the server and client, respectively. Mirror is listening for these events to proceed with the connection sequence.
- In the inspector you can optionally subscribe your own methods to the OnServerAuthenticated and OnClientAuthenticated events.
Here are some tips for custom Authenticators:
- `OnStartServer` and `OnStartClient` are the appropriate methods to register server and client messages and their handlers. They're called from StartServer/StartHost, and StartClient, respectively.
- `RegisterMessage` has a boolean parameter `requireAuthentication`. This defaults to true and **must** be specified false for any messages you need to exchange with the client before they're authenticated.
- 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.
@ -33,13 +34,4 @@ Now that you have the foundation of a custom Authenticator component, the rest i
## 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 Authentication component](BasicAuthentication.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.
Mirror includes a [Basic Authenticator](../Components/BasicAuthenticator.md) in the Mirror / Authenticators folder which just uses a simple username and password.