# Engine Architecture

The engine is designed with the following principles in mind: scene independence and service-orientation.

# Scene Independent

While Unity design promotes using scenes and prefabs composition, it's not very practical when developing visual novels.

All the Naninovel systems either not directly bound to a MonoBehaviour or attached to a persistent root GameObject.

The following root objects are used, depending on the environment:

  • Naninovel<Runtime> for runtime (builds and editor play mode);
  • Naninovel<Editor> for editor (outside of play mode).

All the required gameobjects are created on engine initialization, which is executed automatically and asynchronously when the application starts (right after entering play mode or running a build) via a RuntimeInitializeOnLoadMethod method. You can change this behavior by disabling Initialize On Application Load property in the engine configuration and manually invoking the initialization using RuntimeInitializer (for runtime) or EditorInitializer (for editor) classes.

As the initialization process is asynchronous, either use async-await approach when invoking the InitializeAsync() method or subscribe to the static Engine.OnInitialized event.

To completely disable and remove from memory all the engine systems, use Engine.Destroy() static method.

# Service-Oriented

Most of the engine features are implemented via engine services. Engine service is an implementation of an IEngineService interface, which handles a specific job, like executing naninovel scripts, managing actors or saving-loading the game state.

In case you wish to interact with an engine system, you'll most likely want to use an engine service. You can get a reference to an engine service using Engine.GetService<TService>() static method, where TService is the type (interface) of service you wish to reference; e.g., to get a IScriptPlayer service:

var player = Engine.GetService<IScriptPlayer>();

You can find list of all the currently available engine services and information on how to override/add custom ones in the engine services guide.

# High-Level Concept

The following UML diagram illustrates a high-level concept of the engine architecture. Note that all the class and interface names in the diagram are organized under Naninovel namespace. Eg, to reference Engine class, use Naninovel.Engine or include the namespace.

Обновлено: June 29, 2020