2020-09-30 13:23:01 +01:00
|
|
|
|
using UnityEngine;
|
2020-10-03 09:40:51 +01:00
|
|
|
|
using UnityEngine.SceneManagement;
|
2020-09-30 13:23:01 +01:00
|
|
|
|
|
|
|
|
|
namespace Pink.Environment
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This class exposes the the game model in the inspector, and ticks the
|
|
|
|
|
/// simulation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class GameController : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public static GameController Instance { get; private set; }
|
|
|
|
|
|
|
|
|
|
//This model field is public and can be therefore be modified in the
|
|
|
|
|
//inspector.
|
|
|
|
|
//The reference actually comes from the InstanceRegister, and is shared
|
|
|
|
|
//through the simulation and events. Unity will deserialize over this
|
|
|
|
|
//shared reference when the scene loads, allowing the model to be
|
|
|
|
|
//conveniently configured inside the inspector.
|
|
|
|
|
public EnvironmentModel model = Simulation.GetModel<EnvironmentModel>();
|
|
|
|
|
|
|
|
|
|
void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
if (Instance == this) Instance = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2020-10-01 18:11:43 +01:00
|
|
|
|
if (Instance == this) Simulation.Tick();
|
2020-09-30 13:23:01 +01:00
|
|
|
|
}
|
2020-10-03 09:40:51 +01:00
|
|
|
|
|
|
|
|
|
void LoadLevel(string levelName)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"Loading level {levelName}");
|
|
|
|
|
SceneManager.LoadScene(levelName);
|
|
|
|
|
}
|
2020-09-30 13:23:01 +01:00
|
|
|
|
}
|
|
|
|
|
}
|