The UnityStarterKit assembly provides a foundation brick that is used to develop virtual reality applications. Using this starter kit, you can easily do dependency injection in your application, improve the backend quality code, make REST or SOAP API calls, etc... without external code dependencies !
Base class that must be inherited by all created Monobehavior scripts.
public abstract class BaseComponent : MonoBehaviour
{
...
private void InjectServices() { ... }
...
private void CheckBindableObjects() { ... }
...
private void CheckComponentObjects() { ... }
...
protected virtual void InitializeComponent() { }
protected virtual void UseComponent() { }
protected virtual void UnuseComponent() { }
protected virtual void DestroyComponent() { }
...
}
This class allows :
✔ Dependency injection by calling InjectServices method.
ℹ Injected services must be decorated of the attribute [InjectableService].
✔ The checking of the non-nullity of public fields (can be usefull for the bindings with Unity Game Objects that can be lost 😒) by calling CheckBindableObjects method.
ℹ These fields must be decorated of the attribute [BindableObject].
✔ The checking of the non-nullity of private and protected fields built at runtime (and so prevent execeptions 😄) via l'appel � la m�thode CheckComponentObjects.
ℹ These fields must be decorated of the attribute [ComponentObject].
✔ A better code structure because it provides a clear set of methods to better manage the script lifecycle :
1️⃣ InitializeComponent invoked by the Awake method, to instanciate
private fields and do some initializations.
2️⃣ UseComponent called by the Start method, to subscribe
to external objects events.
3️⃣ UnuseComponent called by the OnDestroy method, to unsubscribe
from external objects events.
4️⃣ DestroyComponent invoked by the OnDestroy method too, to destroy
Game Objects generated during this script execution.
This class registeres all services used by the application.
These must inherit the interface IServiceModule and are stored in a container inside the singleton IUnityServiceLocator.
⚠ Your implementation of the bootstrapper must be the first script to be executed (see unity documentation).
public abstract class Bootstrapper : UnityEngine.MonoBehaviour
{
...
protected abstract void RegisterServices(IUnityServiceContainerBuilder builder);
...
}
This abstract class defines only one method RegisterServices(...) that allows to register all services of type IServiceModule and therefore injects them later in the application.
To do this :
↪ At Awake
, a container is created in which we add all the services. Then this container is sent to the ServiceLocator class which "mount" it as its main container.
↪ At Start
, the ServiceLocator starts all registered services (form now on they can be injected).
↪ Au OnDestroy
, the ServiceLocator stops all services and unmount the container.
The UnityServiceLocator holds every registered IServiceModule.
The IMainthreadService dispatch actions on UI thread.
public interface IMainThreadService : IServiceModule
{
event EventHandler<System.Action> NewActionExecuted;
void DispatchActionOnMainThread(System.Action action);
}
⚠ An excessive use of this service can block the UI.
↪ The method DispatchActionOnMainThread(...) push a new action that must be made on UI thread (ex: update a text on screen after a REST API call made in another thread).
↪ The event NewActionExecuted notify the MainThreadBehavior to enqueue the action to be executed on main thread (30 queues are created by default to minimize congestion).
During the Update
sequence, actions are dequeue and executed as long as there is..
private void Update()
{
lock (asyncTasksQueue)
{
if (asyncTasksQueue.Count > 0)
{
if (asyncTasksQueue.TryDequeue(out Action action))
{
action.Invoke();
}
}
}
}
Provides a standard to make SOAP requests.
public abstract class SoapExecute<_IN_, _OUT_> : SoapExecute
{
protected async Task<SoapExecuteOutput<_OUT_>> _Execute_(SoapExecuteInput<_IN_> input) { ... }
protected abstract ISoapRequestEnvelope BuildRequest(_IN_ input);
protected abstract _OUT_ BuildResponse(ISoapResponseEnvelope soapResponseEnvelope);
}
public abstract class SoapExecute<_OUT_> : SoapExecute
{
protected async Task<SoapExecuteOutput<_OUT_>> _Execute_(SoapExecuteInput input) { ... }
protected abstract ISoapRequestEnvelope BuildRequest();
protected abstract _OUT_ BuildResponse(ISoapResponseEnvelope soapResponseEnvelope);
}
➡ SoapExecuteInput<_IN_> contains (or not) the entry _IN_, the URI, and the request timeout.
➡ SoapExecuteOutput<_OUT_> contains out datas _OUT_ and the request time execution.
ℹ The request and response envelopes must respectively implement the interfaces ISoapRequestEnvelope & ISoapResponseEnvelope.