-
Notifications
You must be signed in to change notification settings - Fork 117
Services
While services can serve for almost any purpose, they can be used to seperate various features of uFrame, and your application. Examples might include, FacebookService, NetworkingService, AchievementsService...etc
As a matter of fact, at the time of this writing, uFrame ships with two default services, The 'ViewService', and the 'SceneManagementService'.
There is really only one general rule of thumb when implementing services, they should only be listening to events, processing them, and publishing its own events that might be useful to other services. While you can inject other services and use them directly, it's highly reommended to use events as the means of communication.
To access a running list of a specific viewmodel just add this property to any service, and make sure you specify the viewmodel type you need.
[Inject] IViewModelManager<PlayerViewModel> AllPlayers { get;set; }
Example MyService.designer.cs
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UniRx;
public class MyServiceBase : SystemServiceMonoBehavior {
/// <summary>
/// This method is invoked whenever the kernel is loading.
/// Since the kernel lives throughout the entire lifecycle of the game, this will only be invoked once.
/// </summary>
public override void Setup() {
this.OnEvent<ViewCreatedEvent>().Subscribe(this.ViewCreatedEventHandler);
}
/// <summary>
// This method is executed when using this.Publish(new ViewCreatedEvent())
/// </summary>
public virtual void ViewCreatedEventHandler(ViewCreatedEvent data) {
// Process the commands information. Also, you can publish new events by using the line below.
// this.Publish(new AnotherEvent())
}
}
Example MyService.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UniRx;
public class MyService : MyServiceBase {
/// <summary>
/// This method is invoked whenever the kernel is loading.
/// Since the kernel lives throughout the entire lifecycle of the game, this will only be invoked once.
/// </summary>
public override void Setup() {
base.Setup();
// Use the line below to subscribe to events.
// this.OnEvent<MyEvent>().Subscribe(myEventInstance=>{ TODO });
}
/// <summary>
// This method is executed when using this.Publish(new ViewCreatedEvent())
/// </summary>
public override void ViewCreatedEventHandler(ViewCreatedEvent data) {
base.ViewCreatedEventHandler(data);
// Process the commands information. Also, you can publish new events by using the line below.
// this.Publish(new AnotherEvent())
}
}