Skip to main content

How To

Using the Yumon Lite Template is simply reacting to the 3 events triggered by the game loop and calling EndLevel() at the end of your level, that’s it.

  1. Your gameplay should listen to the OnLevelStart event to start
  2. Your gameplay should call EndLevel() with a score at the end condition of your level
    1. You can listen to OnLevelEnd to trigger any end of level related feedbacks (animation, confetti…)
  3. Your gameplay should listen to the OnReturnToHome event to reset and be ready to restart
    1. ⚠️ Note that we are not reloading the scene here, you must reset all your component to the initial state manually

The easiest way to integrate your gameplay scripts within the game loop is by inheriting from the YumonGameplay abstract class. This class already subscribes to the OnLevelStart, OnLevelEnd, and OnReturnToHome events and provide corresponding methods for you to override with your gameplay logic.

Let see a basic example of a script inheriting from YumonGameplay that logs the game loop:

public class ExampleGameplay : YumonGameplay
{
public override void OnStartLevel() => Debug.Log("Gameplay started");
public override void OnEndLevel() => Debug.Log("Gameplay ended");
public override void OnReturnToHome() => Debug.Log("Returned to home");
}

This script will log OnLevelStart, OnLevelEnd, and OnReturnToHome because it overrides the virtual methods of YumonGameplay that listen to these events.

YumonGameplay

public abstract class YumonGameplay : MonoBehaviour, IYumonGameplay
{
void OnEnable()
{
YumonGameManager.OnLevelStart += OnStartLevel;
YumonGameManager.OnLevelEnd += OnEndLevel;
YumonGameManager.OnReturnToHome += OnReturnToHome;
}

void OnDisable()
{
YumonGameManager.OnLevelStart -= OnStartLevel;
YumonGameManager.OnLevelEnd -= OnEndLevel;
YumonGameManager.OnReturnToHome -= OnReturnToHome;
}

public virtual void OnStartLevel() {}
public virtual void OnEndLevel() {}
public virtual void OnReturnToHome() {}
}

The YumonGameplay script subscribes to OnLevelStart, OnLevelEnd, and OnReturnToHome on the OnEnable unity callback. These events are declared in the YumonGameManager.

YumonGameManager

The YumonGameManager class provides the events and the EndLevel() method as public static members so it is easy to access them from any of your scripts.

public static class YumonGameManager
{
// subscribe to these events to react to the game state changes
public static event Action OnLevelStart;
public static event Action OnReturnToHome;
public static event Action OnLevelEnd;

// call this method to end a level and send the player's score
public static void EndLevel(int score) { }
}

Another class, the YumonLeagueManager, is also providing public static members.

YumonLeagueManager (Optional)

The Yumon Template provide 4 leagues (Practice, Common, Limited, Epic) for the competitive modes. The higher the league, the higher the entry price and the reward will be.

You can query the current league with YumonLeagueManager.CurrentLeague and subscribe to the event OnLeagueChanged to react to changes in league from the UI arrows on the Home Canvas.

⚠️This is optional but it allows you to customize the look and feel of the gameplay based on the league. You don’t have to create new levels or changes in difficulty, this is only for aesthetic purposes.

public static class YumonLeagueManager
{
public static League CurrentLeague { get; private set; }
public static event Action<League> OnLeagueChanged;
}

Summary

  • ➡️ Your gameplay must start when OnLevelStart is raised
  • ➡️ You must stop your gameplay by calling YumonGameManager.EndLevel(int score)
  • ➡️ You must reset your gameplay when OnReturnToHome is raised, there is no reload of the scene.
  • Your scripts can inherit from YumonGameplay class and override its virtual methods that are subscribed to the 3 events for you.
  • Or you can subscribe to events manually from any of your script if needed by accessing them with the YumonGameManager class.
  • (Optional) You can customize the look and feel of the gameplay elements based on the League from the YumonLeagueManager class.
  • If you have currency pickups in your level, use the provided Zip assets (Yumon soft currency) instead of coins, gems... The provided assets are presented below.