Advertisement
Pro_Unit

GameController

Nov 30th, 2020
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using Platformer.Core;
  2. using Platformer.Model;
  3. using UnityEngine;
  4.  
  5. namespace Platformer.Mechanics
  6. {
  7.     /// <summary>
  8.     /// This class exposes the the game model in the inspector, and ticks the
  9.     /// simulation.
  10.     /// </summary>
  11.     public class GameController : MonoBehaviour
  12.     {
  13.         public static GameController Instance { get; private set; }
  14.  
  15.         //This model field is public and can be therefore be modified in the
  16.         //inspector.
  17.         //The reference actually comes from the InstanceRegister, and is shared
  18.         //through the simulation and events. Unity will deserialize over this
  19.         //shared reference when the scene loads, allowing the model to be
  20.         //conveniently configured inside the inspector.
  21.         public PlatformerModel model = Simulation.GetModel<PlatformerModel>();
  22.  
  23.         void OnEnable()
  24.         {
  25.             Instance = this;
  26.         }
  27.  
  28.         void OnDisable()
  29.         {
  30.             if (Instance == this) Instance = null;
  31.         }
  32.  
  33.         void Update()
  34.         {
  35.             if (Instance == this) Simulation.Tick();
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement