Mirror/docs/Concepts/Conversion.md
Chris Langsenkamp 76b75dbb9b New Documentation (#184)
* Documentation Outline

* Spacing adjustments

* Captured old wiki content

* yml fix

* Docs work

* resize images

* Replaced images

* Removed md from links

* Renamed Misty to Fizzy

* Captured Unity docs

* links cleanup

* clear links

* Cleanup and moved NetworkBehavior to Classes.

* added slashes to yml paths

* reverted slashes

* Fixes bad link

* Update Ignorance.md

This should be enough documentation for now, yeah?

* Localized images

* Update Ignorance.md

formatting updates

* Lots of Cleanup

* fix link

* Formatting

* fix code blocks

* Lots of content and cleanup

* fixed yml

* Added blank line

* Added spaces in titles

* tightened bullets

* Fixed bullet spacing

* Fixed more bullets

* unbolded content

* Cleanup and removal of empty pages
Updated README with links to docs pages

* Restored prior version

* Contributing

* Improvements to content

* lower case fix

* fix link

* renamed Contributions

* fixed link

* home page content

* Fixed Encoding

* Moved Why TCP

* Replaced Unity with Mirror

* Telepathy Description

* changed to h2

* Moved Sample down

* Removed dead links

* Copied Contributions
Added Test
Fixed h3's

* Fixed headings

* added to Test

* Fixed image alts and links

* fixed last alt
2018-12-26 16:07:24 -06:00

3.0 KiB
Raw Blame History

Converting a Single-Player Game to Mirror

This document describes steps to converting a single player game to a multiplayer game, using Mirror. The process described here is a simplified, higher level version of the actual process for a real game; it doesnt always work exactly like this, but it provides a basic recipe for the process.

NetworkManager set-up

  • Add a new GameObject and rename it “NetworkManager”.
  • Add the NetworkManager component to the “NetworkManager” GameObject.
  • Add the NetworkManagerHUD component to the GameObject. This provides the default UI for managing the network game state.

See Using the NetworkManager.

Player Prefab Setup

  • Find the Prefab for the player GameObject in the game, or create a Prefab from the player GameObject
  • Add the NetworkIdentity component to the player Prefab
  • Check the LocalPlayerAuthority box on the NetworkIdentity
  • Set the playerPrefab in the NetworkManagers Spawn Info section to the player Prefab
  • Remove the player GameObject instance from the Scene if it exists in the Scene

See Player Objects for more information.

Player Movement

  • Add a NetworkTransform component to the player Prefab
  • Update input and control scripts to respect isLocalPlayer
  • Fix Camera to use spawned player and isLocalPlayer

For example, this script only processes input for the local player:

using UnityEngine;
using Mirror;

public class Controls : NetworkBehaviour
{
    void Update()
    {
        if (!isLocalPlayer)
        {
            // exit from update if this is not the local player
            return;
        }

        // handle player input for movement
    }
}

Basic Player Game State

  • Make scripts that contain important data into NetworkBehaviours instead of MonoBehaviours
  • Make important member variables into SyncVars

See State Synchronization.

Networked Actions

  • Make scripts that perform important actions into NetworkBehaviours instead of MonoBehaviours
  • Update functions that perform important player actions to be commands

See Networked Actions.

Non-player GameObjects

Fix non-player prefabs such as enemies:

  • Add the NetworkIdentify component
  • Add the NetworkTransform component
  • Register spawnable Prefabs with the NetworkManager
  • Update scripts with game state and actions

Spawners

  • Potentially change spawner scripts to be NetworkBehaviours
  • Modify spawners to only run on the server (use isServer property or the OnStartServer() function)
  • Call NetworkServer.Spawn() for created GameObjects

Spawn Positions for Players

  • Add a new GameObject and place it at players start location
  • Add the NetworkStartPosition component to the new GameObject

Lobby

  • Create Lobby Scene
  • Add a new GameObject to the Scene and rename it to “NetworkLobbyManager”.
  • Add the NetworkLobbyManager component to the new GameObject.
  • Configure the Manager:
    • Scenes
    • Prefabs
    • Spawners