Skip to main content

Welcome to the Service Framework by the Reality Collective

The Service Framework is an extensible service framework to build highly performant components for your Unity projects by the Reality Collective.

Overview

The Service framework provides a service repository for enabling background services to run efficiently in a Unity project, it features capabilities such as:

  • Platform specific operation - choose which platforms your service runs on.
  • Zero Latency from Unity operations - services are fully c# based with no Unity overhead.
  • Ability to host several sub-services (data providers) as part of a service, automatically maintained by a parent service and also platform aware.
  • Fully configurable with Scriptable profiles - Each service can host a configuration profile to change the behavior of your service without changing code.

Requirements

OpenUPM

openupm

The simplest way to getting started using the utilities package in your project is via OpenUPM. Visit OpenUPM to learn more about it. Once you have the OpenUPM CLI set up use the following command to add the package to your project:

`openupm add com.realitycollective.service-framework`

For more details on using OpenUPM CLI, check the docs here.

Build Status

branchbuild status
mainmain
developmentdevelopment

Use cases

The service framework has been the foundation behind such toolkits as Microsoft's MRTK and open source projects like the XRTK as well as the newly formed Reality Toolkit. These use the framework to enable such use cases as:

  • A platform independent input system - A single service able to route input data from multiple controllers on various platforms, each controller only activates on the platform it was designed for.
  • An Authentication service - Able to integrate with multiple authentication providers as needed through a single interface.
  • A networking service - Utilizing multiple endpoints for Lobby's, communication routes and data sharing.

The possibilities are almost endless.

Quickstart

If you want a more indepth tutorial on the Service Framework and creating services, check out the Introduction series.

1. Creating a service

A fully featured "Service Generator" is included with the Service Framework to get you started quickly, by simply giving a service a name and a namespace with which to run from, the generator will quickly create:

  • An interface to identify your service to the Service Framework (all services are identified by their parent interface)
  • A configuration profile - to customize to the needs of your service (optional, delete if not required)
  • The Service Implementation - You service to do with as you wish.

Additionally, the generator can also create additional data providers (sub services) for your service to maintain, these require you to specify the parent services interface when generating to ensure they are appropriately bound in creation. Data Providers are automatically started with a parent service provided their platforms match the current operating environment.

2. Configuring your service

With your service created, it will need to be registered with an active "Service Manager" in a scene, this can either use the provided "Service Manager Instance" component on a GameObject, or consume it using a private property on a class of your own.

Note, at this time, only a single Service Framework Manager can be active in the scene at a time. If you are intending to use the Framework with toolkit's such as the Reality Toolkit which already has an instance of the Service Framework embedded, then you will need to use the toolkit's endpoints to communicate with the Service Framework.

Simply create an empty GameObject and add the ServiceManagerInstance component to it to begin. From there it is simply a matter of creating a Profile for the Service Manager and then adding your services to it.

3. Accessing your running services

Your services are available at any time from anywhere in your code by simply requesting the service from the Service Manager using its interface (Data Providers are also accessible directly, although we recommend working through your service), for example:

    var myService = ServiceManager.Instance.GetService<MyServiceInterface>();

Alternatively, there are also "TryGet" versions of the Service endpoints which return a bool to denote the service retrieval was successful and an out parameter to output the service instance, for example:

    IService myServiceInstance;
if(!ServiceManager.Instance.TryGetService<MyServiceInterface>(out myServiceInstance))
{
// Do something if your service was not found.
}

Final notes

The Service Framework is robustly tested and confirmed to be working in most versions of Unity, including Unity 2021 LTS. However, it is still classed as a preview while the rest of the Reality Toolkit is going through active development. It is being used in production solutions by the Reality Collective team, but it will be up to you as a developer how you choose to consume and operate the framework in your solutions.

Feedback

Please feel free to provide feedback via the Reality Toolkit dev channel here, all feedback. suggestions and fixes are welcome.

Known Issues

There are some fringe areas of the framework which are still under development and improvement, these include:

  • In Unity 2021, the inspector for selecting Service Framework Profiles is a little inconsistent due to 2021 changes. No issues found in Unity 2020 or below
  • The Lookups for Service Types and Data Providers types include all services and providers the toolkit can see, this includes base types and testing data. These will be filtered out later.
  • We resolved a critical issue where some data types (such as delegates) can cause Unity to crash when used, this is a known Unity issue and has been logged. Several workarounds have been implemented to handle these edge cases but there could possibly be more on different platforms (because Unity...)
  • More documentation is needed for the Service Framework, including examples (currently the Reality Toolkit is the best set of examples). These will be improved over time.


Raise an Information Request

If there is anything not mentioned in this document or you simply want to know more, raise an RFI (Request for Information) request here.