Added cs to code blocks

This commit is contained in:
Chris Langsenkamp 2019-07-07 02:05:45 -04:00
parent 2bd922ffdf
commit bbc257722b
7 changed files with 17 additions and 17 deletions

View File

@ -70,7 +70,7 @@ There are two types of player objects with the Network Lobby Manager:
### Server Virtual Methods
```
```cs
public virtual void OnLobbyStartHost() {}
public virtual void OnLobbyStopHost() {}
@ -106,7 +106,7 @@ public virtual void OnLobbyServerPlayersReady()
### Client Virtual Methods
```
```cs
public virtual void OnLobbyClientEnter() {}
public virtual void OnLobbyClientExit() {}

View File

@ -22,7 +22,7 @@ A game object with a Network Lobby Player component must also have a Network Ide
### Client Virtual Methods
```
```cs
public virtual void OnClientEnterLobby() {}
public virtual void OnClientExitLobby() {}

View File

@ -28,7 +28,7 @@ Assigning authority to a client causes Mirror to call OnStartAuthority() on each
If you want non-player game objects to have client authority, you must enable localPlayerAuthority on their Network Identity component. The example below spawns a game object and assigns authority to the client of the player that spawned it.
```
```cs
[Command]
void CmdSpawn()
{

View File

@ -8,7 +8,7 @@ For multiplayer games with no dedicated server, one of the players running the g
A common pattern for multiplayer games is to have a game object that manages the network state of the game. Below is the start of a NetworkManager script. This script would be attached to a game object that is in the start-up Scene of the game. It has a simple UI and keyboard handling functions that allow the game to be started in different network modes. Before you release your game you should create a more visually appealing menu, with options such as “Start single player game” and “Start multiplayer game”.
```
```cs
using UnityEngine;
using Mirror;
@ -47,7 +47,7 @@ public class MyNetworkManager : MonoBehaviour {
This basic code calls setup functions to get things going. Below are the simple setup functions for each of the scenarios. These functions create a server, or the right kind of client for each scenario. Note that the remote client assumes the server is on the same machine (127.0.0.1). For a finished game this would be an internet address, or something supplied by the Matchmaking system.
```
```cs
// Create a server and listen on a port
public void SetupServer()
{
@ -75,7 +75,7 @@ public void SetupLocalClient()
The clients in this code register a callback function for the connection event [MsgType.Connect](https://docs.unity3d.com/ScriptReference/Networking.MsgType.Connect.html). This is a built-in message of Mirror that the script invokes when a client connects to a server. In this case, the code for the handler on the client is:
```
```cs
// client function
public void OnConnected(NetworkMessage netMsg)
{

View File

@ -20,7 +20,7 @@ To spawn game objects without using the Network Manager, you can handle the Pref
### Example: MyNetworkManager
```
```cs
using UnityEngine;
using Mirror;
@ -49,7 +49,7 @@ Registering Prefabs ensures that the Asset, so that there is no stalling or load
However, for the script to work, you also need to add code for the server. Add this to the MyNetworkManager script:
```
```cs
public void ServerListen()
{
NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnect);
@ -91,7 +91,7 @@ For more advanced uses, such as object pools or dynamically created Assets, you
If the game object has a network state like synchronized variables, then that state is synchronized with the spawn message. In the following example, this script is attached to the tree Prefab:
```
```cs
using UnityEngine;
using Mirror;
@ -109,7 +109,7 @@ class Tree : NetworkBehaviour
With this script attached, you can change the `numLeaves` variable and modify the `SpawnTrees` function to see it accurately reflected on the client:
```
```cs
void SpawnTrees()
{
int x = 0;
@ -179,7 +179,7 @@ Objects spawned with client authority must have `LocalPlayerAuthority` set in th
For example, the tree spawn example above can be modified to allow the tree to have client authority like this (note that we now need to pass in a NetworkConnection game object for the owning clients connection):
```
```cs
void SpawnTrees(NetworkConnection conn)
{
int x = 0;
@ -196,7 +196,7 @@ void SpawnTrees(NetworkConnection conn)
The Tree script can now be modified to send a command to the server:
```
```cs
public override void OnStartAuthority()
{
CmdMessageFromTree("Tree with " + numLeaves + " reporting in");

View File

@ -8,7 +8,7 @@ When the Network Manager adds a player, it also instantiates a game object from
The example below customizes the color of a player. First, add the color script to the player prefab:
```
```cs
using UnityEngine;
using Mirror;
class Player : NetworkBehaviour
@ -20,7 +20,7 @@ class Player : NetworkBehaviour
Next, create a NetworkManager to handle spawning.
```
```cs
using UnityEngine;
using Mirror;
@ -53,7 +53,7 @@ To replace the player game object for a connection, use NetworkServer.ReplacePla
You can also use `ReplacePlayerForConnection` to respawn a player after their game object is destroyed. In some cases it is better to just disable a game object and reset its game attributes on respawn. The following code sample demonstrates how to actually replace the destroyed game object with a new game object:
```
```cs
class GameManager
{
public void PlayerWasKilled(Player player)

View File

@ -19,7 +19,7 @@ On the `NetworkBehaviour`class (which your networked scripts inherit from), ther
You can check whether any given networked game object is a player by checking if its `NetworkIdentity` has a valid connectionToClient. For example:
```
```cs
var hits = Physics.OverlapSphere(transform.position, visRange);
foreach (var hit in hits)
{