Skip to content

unitycoder/VirtualSession

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Unity Virtual Sessions Package

Unity package for creating virtual session games.

Avaliable on Asset Store: https://assetstore.unity.com/packages/slug/309268

Forum thread: https://discussions.unity.com/t/virtual-session-manager-open-source/1603167

Overview

This Unity package provides a set of customizable prefabs and scripts designed to facilitate virtual sessions. It includes:

  • Customizable Prefabs: Prebuilt objects with everything needed for virtual sessions.
  • Session Management Scripts: Scripts to control visibility and interaction between sessions.
  • Demo Scene: A simple scenario demonstrating the package's functionality.

Installation

There are 3 different ways of adding the package to your project:

Usage

Prefabs

The package includes two basics prefabs for quick integration:

  • NetworkPlayer.prefab: PlayerObject with the basic functionalities necessary for the correct functioning of inter-session visibility. Open to its extension in the customisation of attributes or methods.
  • Session.prefab: NetworkObject in charge of managing visibility between clients connected to the same session.

To use these two prefabs, make sure that they are included in the Network Prefab List managed by the NetworkManager, and select the NetworkPlayer.prefab as the Default Player Prefab in the NetworkManager configuration. Session.prefab is instantiated from the SessionManager.cs, so be sure to indicate the path where the prefab is located.

Demo Scene

A sample scene is included to demonstrate a basic implementation. Open it via VirtualSession/DemoScene to explore.

Scripts Documentation

SessionManager.cs

Description: Handles the current active sessions.

Methods:

  • GameObject GetSession(string sessionId): Gets the GameObject associated to the session.
  • void AssignToSession(string session, ulong clientId): Assigns the new connected client to the session. If it does not exist, it creates one by calling CreateGameSession(session).
  • void CreateGameSession(string sessionId): Instantiates a session and spawns it. The new session is added to active sessions.
  • void RemoveGameSession(string sessionId): Removes the session from the actives sessions and destroys its GameObject.

Session.cs

Description: Manages the logic inside a single session.

Methods:

  • void OnNetworkSpawn(): Overrides default implementation when client-side code running. It requests the server to parent the client to the session's GameObject and makes visible already connected clients.
  • void ShowClientInSessionServerRpc(ulong clientObjectId, ulong clientIdToShow): ServerRPC used to make visible a NetworkObject to a single client.
  • void PlayersChanged(NetworkListEvent<ulong> changeEvent): Listens to changes on the players list and performs the corresponding actions. When a new client is added to the session, ShowClientInSessionServerRpc(ulong clientObjectId, ulong clientIdToShow) is called for every connected client.
  • void AddPlayer(ulong clientId): Called from SessionManager.cs, it makes visible the session to the new client and adds the client to the players list.
  • void ParentClientToSessionObjectServerRpc(ServerRpcParams serverRpcParams = default): ServerRPC used for parenting the client to the session.

NetworkPlayer.cs

Description: Manages the logic of a single client.

Methods:

  • void OnNetworkSpawn(): Overrides default implementation for both client-side (only the owner) and server-side. If it is the owner, it asks the server to be assigned to the session. If it is the server, it subscribes CheckVisibility to the client's visibility delegate.
  • bool CheckVisibility(ulong clientId): As they spawn with no observers, it is changed the CheckObjectVisibility delegate of the client to return true for the owner of the script, i.e. the client itself.
  • void UnsubscribeVisibility(): Unsubscribes the visibility delegate to reset to default behaviour.
  • void AddPlayer(ulong clientId): Called from SessionManager.cs, it makes visible the session to the new client and it adds the client to the players list.
  • AssignToSessionServerRpc(string session, ServerRpcParams serverRpcParams = default): ServerRPC called from OnNetworkSpawn to assign the client to the session. It calls AssigntToSession from SessionManager.cs.

Contribution

Feel free to submit issues, feature requests, or pull requests to improve the package.

License

This project is licensed under the MIT License. See LICENSE for details.

Contact

For questions or support, reach out via the repository's issue tracker.

About

Unity package for creating virtual session games

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%