中文 | English

RocketDriver Pro

Logo

RocketDriver Pro is a game framework for Unity engine


7. Service Framework (Service)

7.1 Design Purpose

Game projects have some obvious characteristics: high degree of data coupling and strong system dependence.
So the entire game project can easily evolve into a monolithic software.
As there are more modules in the system, the monolithic architecture becomes more complex. In addition, the interleaving of new functions and modification of old functions affects each other and is ultimately difficult to manage.
In order to solve or reduce the impact of the above problems, combined with the idea of service-oriented architecture(SOA), here is a solution and solve the following problems::

7.2 Design Ideas

7.3 Interface description

7.3.1 Service Basics

Execution timing: IArgumentService -> IAWakableService -> IInitService

7.3.4 Event Description

image

image
Dispatching order: OnServiceInjected > OnServiceAllInjected > OnServiceAwaked > OnServiceAllAwaked

image
image
Dispatching order: OnServiceInitStart > OnServiceInited > OnServiceAllInited > OnServiceDataInitStart > OnServiceDataInited > OnServiceDataAllInited

image

image

7.4 How to use the framework

Before getting the service to use, it must be registered to the framework management, and then can be used after initialization. This is to ensure that the data has been processed completely.

7.4.1 Register the service to the framework management

By calling the AddConfig function in the ServiceConfig instance, the service can be registered with the framework management.
ServiceConfig.Shared.AddConfig(new ServiceInfo(serviceName, serviceImpl, args)); image
Suggest:

  1. Manage the registration logic with a class dedicated to handling registration services. Such as ServiceRegister in the example.
  2. Registration logic calls should be guaranteed to be unique.

7.4.2 Service initialization

Start initialization by calling the StartInitalization function in the ServiceManager instance.
Note: It should not be called repeatedly after initialization has started.
image

7.4.3 Service call

After the initial completion of all services, the service instance can be obtained by calling the GetService function in ServiceConfig.
There are multiple functions for obtaining service instances in ServiceConfig, but the GetService function is ultimately called.
image
Suggest:

  1. Manage the acquisition logic using a class that specifically manages acquiring service instances. Such as ServiceCenter in the example.

7.4.4 Service cleanup

When the game is to achieve a soft restart, it is necessary to reset all services and then reinitialize.
All services can be reset by calling ClearServices in ServiceManager.
Only services that implement the IClearService interface will perform reset logic.
image
image
Suggest:

  1. Each service is recommended to implement the IClearService interface.
  2. In the Clear function in the IClearService interface, also clear all event listeners.

7.5 Example

JLGames/RocketDriver/Samples/Service
image
image
Service description in example: