BomberUnits
...a Unity learning project
PlayerManager Class Reference

The PlayerManager controlls the local and remote players. More...

+ Inheritance diagram for PlayerManager:
+ Collaboration diagram for PlayerManager:

Public Member Functions

bool IsAddingNewPlayerPossible ()
 

Static Public Member Functions

static void RemovePlayer (Player p)
 Player removal caused by: More...
 
- Static Public Member Functions inherited from MonoSingleton< PlayerManager >
static T Get ()
 Singleton access.
 

Public Attributes

bool logEnabled
 

Static Public Attributes

static UnityPlayerChangeEvent playerChangeEvent
 Invoked from NET layer but located better here. More...
 

Protected Member Functions

override void MyAwake ()
 You may override this to have an Awake()-like function. More...
 

Private Member Functions

void Start ()
 
void OnApplicationQuit ()
 Called also when ending play mode in Unity Editor.
 
void RegisterCallbacks ()
 
void UnregisterCallbacks ()
 
void SpawnPlayer (LocalPlayer p)
 
void OnConnectedToMaster ()
 Callback for updating the local players' client ID after connection.
 
void OnClientPropertiesUpdate (string clientId, ExitGames.Client.Photon.Hashtable changedProps)
 Callback for the clientPropertiesUpdateEvent The NetData needs to be identified and converted first. More...
 
void InterpreteNetDataChangeAndSendEvents (string clientId, int uid, NetData netData)
 Invoking the event is always the last step to be consistent between direct callbacks during OfflineMode and delayed transmission when online. More...
 
void OnJoinedRoom ()
 When entering another client's room, this client needs to: More...
 
void OnLeftRoom ()
 Leaving a room, we can remove all remote players and clients. More...
 
void OnPlayerSpawnInfo (PlayerSpawnNetData data)
 This is the spawn order with location issued by the master when the match begins. More...
 
void OnClientLeftRoom (string clientId)
 When a client leaves, we can remove all his remote players. More...
 

Additional Inherited Members

- Static Protected Attributes inherited from MonoSingleton< PlayerManager >
static T instance
 Singleton pattern instance.
 

Detailed Description

The PlayerManager controlls the local and remote players.

It is a Singleton and persistent over scenes, like the GameManager. This manager also provides Input Schemes for the local players.

Definition at line 29 of file PlayerManager.cs.

Member Function Documentation

◆ InterpreteNetDataChangeAndSendEvents()

void InterpreteNetDataChangeAndSendEvents ( string  clientId,
int  uid,
NetData  netData 
)
inlineprivate

Invoking the event is always the last step to be consistent between direct callbacks during OfflineMode and delayed transmission when online.

A change can mean an addition, a removal or a change in content. Local Players are not added/removed via their net Data normally -> issue warnings. Also a data change will have occurred due to previous local customization. Remote players in turn are signaled to have been added or removed via their net data.

Definition at line 181 of file PlayerManager.cs.

◆ MyAwake()

override void MyAwake ( )
inlineprotectedvirtual

You may override this to have an Awake()-like function.

Only called if this is the first instance as all further instances are destroyed.

Reimplemented from MonoSingleton< PlayerManager >.

Definition at line 78 of file PlayerManager.cs.

◆ OnClientLeftRoom()

void OnClientLeftRoom ( string  clientId)
inlineprivate

When a client leaves, we can remove all his remote players.

Interestingly, the netData is still available for these for a while and a second event may arrive after a while! -> catch this gracefully. Maybe this functionality shall make a reconnect possible...

Definition at line 272 of file PlayerManager.cs.

◆ OnClientPropertiesUpdate()

void OnClientPropertiesUpdate ( string  clientId,
ExitGames.Client.Photon.Hashtable  changedProps 
)
inlineprivate

Callback for the clientPropertiesUpdateEvent The NetData needs to be identified and converted first.

Then it is interpreted.

Definition at line 161 of file PlayerManager.cs.

◆ OnJoinedRoom()

void OnJoinedRoom ( )
inlineprivate

When entering another client's room, this client needs to:

  1. Add all already existing players in the room
  2. Check own local players for compatibility.
  3. Adapt (if needed) local players and publish them to the other clients. This is best done in simply re-transmitting the player net data for other to pick up the change event. Regarding adding already existing remote players, we only locally re-send the change event without actually sending out data of another client.
Todo:
: Add checks here whether own players can be added at all (resources, nr of players.) Do necessary modification to local players if there are conflicts. Iterate over all Remote players

Definition at line 221 of file PlayerManager.cs.

◆ OnLeftRoom()

void OnLeftRoom ( )
inlineprivate

Leaving a room, we can remove all remote players and clients.

We do not have access to their netData any longer -> Remove remaining local representations.

Definition at line 248 of file PlayerManager.cs.

◆ OnPlayerSpawnInfo()

void OnPlayerSpawnInfo ( PlayerSpawnNetData  data)
inlineprivate

This is the spawn order with location issued by the master when the match begins.

Each client spawns their own players.

Todo:
: dangerous
Todo:
: Do not spawn now but at the given synced point in time and only if all local players have been given a spawn. (Match init phase needed)

Definition at line 259 of file PlayerManager.cs.

◆ RemovePlayer()

static void RemovePlayer ( Player  p)
inlinestatic

Player removal caused by:

  • a local user UI interaction to remove a player
  • disconnect of this client: Remove All Remote Players of any clients which were present before.
  • disconnect another client: Remove All Remote Players Of the particular client.
    Todo:
    : the removal strategy is dependent on the net status. Make things more clear! E.g. this won't work outside of a room, right?

Definition at line 60 of file PlayerManager.cs.

◆ SpawnPlayer()

void SpawnPlayer ( LocalPlayer  p)
inlineprivate

Hand networked information to the created object, which allows connecting it to a Player instance:

Definition at line 136 of file PlayerManager.cs.

Member Data Documentation

◆ playerChangeEvent

UnityPlayerChangeEvent playerChangeEvent
static

Invoked from NET layer but located better here.

This is activated when player data changes for any client, also for the local client. THIS does however not work when disconnected! -> Do no player modifications then!

Todo:
: care for this.

The EventCause further specifies what exactly has happended to the player. Addition: Has to be added to the local Model and Views. No guarantee to have net Data yet! Deletion: Has to be removed from local Model and Views A Data Change can affect anything stored in player.NetData:

  • string name : Is displayed in a Lobby Slot, so the slot needs to register to this.
  • ColorScheme color : Same as above
  • PlayerFigurePrefab prefab : Will be added to the Lobby Slots in the future.
  • Player.State state : Can lead to the match end -> bound by match manager

Definition at line 52 of file PlayerManager.cs.


The documentation for this class was generated from the following file: