Skip to content

Commit

Permalink
refactor: rename PlayerSpawner to CharacterSpawner (MirageNet#686)
Browse files Browse the repository at this point in the history
As discussed in Discord,  Player is the meat bag between the keyboard
and the chair. The gameobject he controls is the Character.
There may be any number of characters from 0 to n per Player.

Therefore this class is renamed to stay consistent with the new
terminology.

BREAKING CHANGE: Renamed PlayerSpawner to CharacterSpawner
  • Loading branch information
paulpach committed Mar 12, 2021
1 parent f2a5522 commit 1db3498
Show file tree
Hide file tree
Showing 24 changed files with 55 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Assets/Mirage/Editor/NetworkMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class NetworkMenu
[MenuItem("GameObject/Network/NetworkManager", priority = 7)]
public static GameObject CreateNetworkManager()
{
var go = new GameObject("NetworkManager", typeof(NetworkManager), typeof(NetworkServer), typeof(NetworkClient), typeof(NetworkSceneManager), typeof(ServerObjectManager), typeof(ClientObjectManager), typeof(PlayerSpawner), typeof(KcpTransport), typeof(LogSettings));
var go = new GameObject("NetworkManager", typeof(NetworkManager), typeof(NetworkServer), typeof(NetworkClient), typeof(NetworkSceneManager), typeof(ServerObjectManager), typeof(ClientObjectManager), typeof(CharacterSpawner), typeof(KcpTransport), typeof(LogSettings));

KcpTransport transport = go.GetComponent<KcpTransport>();
NetworkSceneManager nsm = go.GetComponent<NetworkSceneManager>();
Expand All @@ -37,7 +37,7 @@ public static GameObject CreateNetworkManager()
networkManager.ClientObjectManager = clientObjectManager;
networkManager.SceneManager = nsm;

PlayerSpawner playerSpawner = go.GetComponent<PlayerSpawner>();
CharacterSpawner playerSpawner = go.GetComponent<CharacterSpawner>();
playerSpawner.Client = networkClient;
playerSpawner.Server = networkServer;
playerSpawner.SceneManager = nsm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace Mirage
/// <summary>
/// Spawns a player as soon as the connection is authenticated
/// </summary>
public class PlayerSpawner : MonoBehaviour
public class CharacterSpawner : MonoBehaviour
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(PlayerSpawner));
static readonly ILogger logger = LogFactory.GetLogger(typeof(CharacterSpawner));

[FormerlySerializedAs("client")]
public NetworkClient Client;
Expand All @@ -36,7 +36,7 @@ public virtual void Start()
{
if (PlayerPrefab == null)
{
throw new InvalidOperationException("Assign a player in the PlayerSpawner");
throw new InvalidOperationException("Assign a player in the CharacterSpawner");
}
if (Client != null)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ public virtual void RequestServerSpawnPlayer()

void OnServerAddPlayerInternal(INetworkPlayer conn, AddPlayerMessage msg)
{
logger.Log("PlayerSpawner.OnServerAddPlayer");
logger.Log("CharacterSpawner.OnServerAddPlayer");

if (conn.Identity != null)
{
Expand Down Expand Up @@ -165,7 +165,7 @@ public virtual Transform GetStartPosition()
public enum PlayerSpawnMethod { Random, RoundRobin }

/// <summary>
/// The current method of spawning players used by the PlayerSpawner.
/// The current method of spawning players used by the CharacterSpawner.
/// </summary>
[Tooltip("Round Robin or Random order of Start Position selection")]
public PlayerSpawnMethod playerSpawnMethod;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Assets/Mirage/Samples~/Pong/Scripts/PaddleSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Mirage.Examples.Pong
{
public class PaddleSpawner : PlayerSpawner
public class PaddleSpawner : CharacterSpawner
{
public Transform leftRacketSpawn;
public Transform rightRacketSpawn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
namespace Mirage
{

public class PlayerSpawnerTest
public class CharacterSpawnerTest
{
private GameObject go;
private NetworkClient client;
private NetworkServer server;
private PlayerSpawner spawner;
private CharacterSpawner spawner;
private NetworkSceneManager sceneManager;
private ServerObjectManager serverObjectManager;
private ClientObjectManager clientObjectManager;
Expand All @@ -26,7 +26,7 @@ public void Setup()
go = new GameObject();
client = go.AddComponent<NetworkClient>();
server = go.AddComponent<NetworkServer>();
spawner = go.AddComponent<PlayerSpawner>();
spawner = go.AddComponent<CharacterSpawner>();
sceneManager = go.AddComponent<NetworkSceneManager>();
serverObjectManager = go.AddComponent<ServerObjectManager>();
clientObjectManager = go.AddComponent<ClientObjectManager>();
Expand Down Expand Up @@ -101,7 +101,7 @@ public void GetStartPositionRoundRobinTest()
{
spawner.Start();

spawner.playerSpawnMethod = PlayerSpawner.PlayerSpawnMethod.RoundRobin;
spawner.playerSpawnMethod = CharacterSpawner.PlayerSpawnMethod.RoundRobin;
Assert.That(spawner.GetStartPosition(), Is.SameAs(pos1.transform));
Assert.That(spawner.GetStartPosition(), Is.SameAs(pos2.transform));
Assert.That(spawner.GetStartPosition(), Is.SameAs(pos1.transform));
Expand All @@ -113,7 +113,7 @@ public void GetStartPositionRandomTest()
{
spawner.Start();

spawner.playerSpawnMethod = PlayerSpawner.PlayerSpawnMethod.Random;
spawner.playerSpawnMethod = CharacterSpawner.PlayerSpawnMethod.Random;
Assert.That(spawner.GetStartPosition(), Is.SameAs(pos1.transform) | Is.SameAs(pos2.transform));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void ParseForServerMode()
{
if (!string.IsNullOrEmpty(GetArg("-server")))
{
var serverGo = new GameObject($"Server", typeof(NetworkServer), typeof(ServerObjectManager), typeof(NetworkSceneManager), typeof(PlayerSpawner));
var serverGo = new GameObject($"Server", typeof(NetworkServer), typeof(ServerObjectManager), typeof(NetworkSceneManager), typeof(CharacterSpawner));

server = serverGo.GetComponent<NetworkServer>();
server.MaxConnections = 9999;
Expand All @@ -115,7 +115,7 @@ void ParseForServerMode()
serverObjectManager.NetworkSceneManager = networkSceneManager;
serverObjectManager.Start();

PlayerSpawner spawner = serverGo.GetComponent<PlayerSpawner>();
CharacterSpawner spawner = serverGo.GetComponent<CharacterSpawner>();
spawner.PlayerPrefab = PlayerPrefab.GetComponent<NetworkIdentity>();
spawner.ServerObjectManager = serverObjectManager;
spawner.Server = server;
Expand Down Expand Up @@ -162,10 +162,10 @@ async UniTaskVoid StartClients()

async UniTask StartClient(int i, string networkAddress)
{
var clientGo = new GameObject($"Client {i}", typeof(NetworkClient), typeof(ClientObjectManager), typeof(PlayerSpawner), typeof(NetworkSceneManager));
var clientGo = new GameObject($"Client {i}", typeof(NetworkClient), typeof(ClientObjectManager), typeof(CharacterSpawner), typeof(NetworkSceneManager));
NetworkClient client = clientGo.GetComponent<NetworkClient>();
ClientObjectManager objectManager = clientGo.GetComponent<ClientObjectManager>();
PlayerSpawner spawner = clientGo.GetComponent<PlayerSpawner>();
CharacterSpawner spawner = clientGo.GetComponent<CharacterSpawner>();
NetworkSceneManager networkSceneManager = clientGo.GetComponent<NetworkSceneManager>();
networkSceneManager.Client = client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

namespace Mirage.Tests.Host
{
public class PlayerSpawnerTest : HostSetup<MockComponent>
public class CharacterSpawnerTest : HostSetup<MockComponent>
{
AssetBundle bundle;
GameObject player;
PlayerSpawner spawner;
CharacterSpawner spawner;

public override void ExtraSetup()
{
bundle = AssetBundle.LoadFromFile("Assets/Tests/Runtime/TestScene/testscene");

spawner = networkManagerGo.AddComponent<PlayerSpawner>();
spawner = networkManagerGo.AddComponent<CharacterSpawner>();

spawner.Client = client;
spawner.Server = server;
Expand Down
2 changes: 1 addition & 1 deletion doc/Articles/Components/NetworkLerpRigidbody.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A game object with a Network Rigidbody component must also have a Network Identi

When using the Network Lerp Rigidbody you should 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.
By default, Network Lerp Rigidbody is server-authoritative unless you check the box for **Client Authority**. Client Authority applies to character objects as well as non-character 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.

Expand Down
2 changes: 1 addition & 1 deletion doc/Articles/Components/NetworkRigidbody.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Network Rigidbody works best when there is also a NetworkTransform for the objec

![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.
By default, Network Rigidbody is server-authoritative unless you check the box for **Client Authority**. Client Authority applies to character objects as well as non-character 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.

Expand Down
2 changes: 1 addition & 1 deletion doc/Articles/Components/NetworkRoomManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The Network Room Manager is a specialized type of [Network Manager](NetworkManag
- 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:
There are two types of character objects with the Network Room Manager:

**Room Player Prefab**
- One for each player
Expand Down
10 changes: 5 additions & 5 deletions doc/Articles/Components/NetworkSceneChecker.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Scene objects with a Network Scene Checker component are disabled when they're n

In Mirage, 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.
All character 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 character 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`:

Expand All @@ -39,17 +39,17 @@ SceneMessage msg = new SceneMessage
connectionToClient.Send(msg);
```

Then, on the server only, you just move the player object to the subscene:
Then, on the server only, you just move the character object to the subscene:

```cs
// Position the player object in world space first
// Position the character 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
// Then move the character 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.
Depending on the complexity of your game, you may find it helpful when switching a player between subscenes to move the character object to the main scene first, yield 100 ms, re-position it, and finally move it to the new subscene.
2 changes: 1 addition & 1 deletion doc/Articles/Components/NetworkTransform.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A game object with a Network Transform component must also have a Network Identi

![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.
By default, Network Transform is server-authoritative unless you check the box for **Client Authority**. Client Authority applies to character objects as well as non-character 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.

Expand Down
2 changes: 1 addition & 1 deletion doc/Articles/Components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ These core components are included in Mirage:
- [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 Start Position is used by the Network Manager when creating character objects. The position and rotation of the Network Start Position are used to place the newly created character 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)
Expand Down
6 changes: 3 additions & 3 deletions doc/Articles/General/Start.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ See [Using the NetworkManager](../Components/NetworkManager.md).
## Player Prefab
- Find the Prefab for the player game object in the game, or create a Prefab from the player game object
- Add the NetworkIdentity component to the player Prefab
- Set the `playerPrefab` field on the `PlayerSpawner` component to the player Prefab. You can find this component on the GameObject you created in the first setup.
- Set the `playerPrefab` field on the `CharacterSpawner` component to the player Prefab. You can find this component on the GameObject you created in the first setup.
- Remove the player game object instance from the Scene if it exists in the Scene

See [Player Objects](../Guides/GameObjects/SpawnPlayer.md) for more information.
See [character objects](../Guides/GameObjects/SpawnPlayer.md) for more information.

## Player movement
- Add a NetworkTransform component to the player Prefab
Expand Down Expand Up @@ -74,4 +74,4 @@ Fix non-player prefabs such as enemies:

## Spawn positions for players
- Add a new game object and place it at player’s start location
- Add this GameObject to the `PlayerSpawner`'s `Positions` list.
- Add this GameObject to the `CharacterSpawner`'s `Positions` list.
8 changes: 4 additions & 4 deletions doc/Articles/Guides/Authority.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Even if a client has authority over an object the server still controls SyncVar

## How to give authority

By default the server has Authority over all objects. The server can give authority to objects that a client needs to control, like the player object.
By default the server has Authority over all objects. The server can give authority to objects that a client needs to control, like the character object.

If you spawn a player object using `NetworkServer.AddPlayerForConnection` then it will automatically be given authority.
If you spawn a character object using `NetworkServer.AddPlayerForConnection` then it will automatically be given authority.


### Using NetworkServer.Spawn
Expand All @@ -41,7 +41,7 @@ identity.AssignClientAuthority(conn);
You may want to do this when a player picks up an item

```cs
// Command on player object
// Command on character object
[ServerRpc]
void PickupItem(NetworkIdentity item)
{
Expand All @@ -57,7 +57,7 @@ You can use `identity.RemoveClientAuthority` to remove client authority from an
identity.RemoveClientAuthority();
```

Authority can't be removed from the player object. Instead you will have to replace the player object using `NetworkServer.ReplacePlayerForConnection`.
Authority can't be removed from the character object. Instead you will have to replace the character object using `NetworkServer.ReplacePlayerForConnection`.


## On Authority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is a full list of virtual methods (callbacks) that you can implement on `Ne
- called when behaviour has authority when it is spawned (eg local player)
- called when behaviour is given authority by the sever
- OnStartLocalPlayer
- called when the behaviour is on the local player object
- called when the behaviour is on the local character object

- OnStopAuthority
- called when authority is taken from the object (eg local player is replaced but not destroyed)
Expand Down
Loading

0 comments on commit 1db3498

Please sign in to comment.