Game Managers - Capi-Metaverse/Template GitHub Wiki

Table of Contents

What are Game Managers?

Game Managers are an important part of the structure of our application. This Game Managers allow us to send and keep information along the instance of the game. There are three Game Managers at this moment in the project:

  • SceneManager : This manager keep and track information about the user movements between scenes and it has the majority of Photon Callbacks implemented.

  • PhotonEventManager : The PhotonEventManager has all the callbacks related to the diverse Photon Events like lights, user synchronization…​

  • PlayerManager : This manager instantiates de Player in Photon and in the Scene. This manager contains the states of the user too.

  • MusicManager : ???

SceneManager

The Scene Manager implements a great part of the Photon Callbacks like OnJoinedRoom, OnLeftRoom, OnPlayerEnteredRoom, OnLeftEnteredRoom among others. This manager creates all the new rooms in the game too.

Variables

  • ROOM_NAMES : String array with the names of the avaliable maps.

  • onMap : Boolean that indicates if the user is on a map.

  • onNewMap : Boolean that indicates if the user is going to another map.

  • PlayerProperties : Hashtable with the properties of the player like his current avatar.

Other Managers

  • LobbyManager : This variable will recieve the information from this manager to update the UI of the user.

  • PlayerManager : This variable will recieve the information from this manager to instantiate the player on a Room.

Methods

Create New Room

This method creates a new room with a HashSet of custom settings. This Hashset must be a Photon.HashTable. It contains the following settings:

  • Map : Number of the actual map

  • Name : Name of the current room

All new rooms have to contain a Photon.RoomOptions too. This RoomOptions allow to indicate some room settings like the following:

  • MaxPlayers : Indicates the max number of players that can be in a room.

  • PublishUserId : Allow us to get the user ID when he joins a room.

  • IsVisible : It allows the room to be found in the Room List.

  • EmptyRoomTtl : It specificates the time that the room is alive without users.

We can call the method PhotonNetwork.JoinOrCreateRoom() with the map name and when the settings are set to join or create the room.

OnConnectedToMaster

This method is a Photon Callback. It’s called at the end of the OnLeftRoom Callback or the first time a user joins to the PhotonNetwork. The method just add the user to the Game Server with the method PhotonNetwork.JoinLobby().

OnJoinedLobby

This method is a Photon Callback. It’s called when the user joins to the Game Server. The first time this method is called the Lobby Manager and the VoiceChat are added to this manager.

It doesn’t have more functionality unless the user is going to join a new map. If the user is going to join a new map the boolean onMap is set and the PhotonNetwork.JoinOrCreateRoom() is called. The new map is starting to load here too. It’s important to mention that the PhotonNetwork message events must be disabled to avoid connection problems.

OnJoinedRoom

This method is a Photon Callback. It’s called when the user joins to a room. If the user is at the Lobby Screen sets the room panel. On the other hand, if the user is on a map, it instantiates the player.

OnLeftRoom

This method is a Photon Callback. It’s called when the user lefts a room.

The behaviour of this method changes depending of the booleans onMap and onNewMap:

  • onMap == false && onNewMap == false : The user is in the Lobby and he left the room -→ Resets PlayerSettings and Change the panel to the Room List.

  • onMap == false && onNewMap == true : The user is in the Lobby and he’s going to a new Room -→ Sets the Loading Screen.

  • onMap == true && onNewMap == false : The user is in a map and he’s returning to Lobby -→ Resets all variables and change to the Lobby Scene.

  • onMap == true && onNewMap == true : The user is in a map and he’s going to a new Room -→ Do nothing.

PhotonEventManager

The PhotonEventManager implements the IOnEventCallback from Photon. Each Event has a code that specifies the type of the event.

Events

EventCode 2

Animation

EventCode 21

This is the event related to the Lights. If a user activates a Lamp or Bulb this event will activate it to the rest of the players.

EventCode 22

This event is related to the Powerpoint presentations. When a user uploads a presentation, the other users will received it too. The event just find the canvas and download and charge the images in a array in memory.

EventCode 23

This event advances or move back the slide of the presentation. Just change the sprite of the presentation canvas with the former or the next one of the array.

EventCode 24

EventCode 25

PlayerManager

⚠️ **GitHub.com Fallback** ⚠️