Skip to content

Instantly share code, notes, and snippets.

@codehoose
Created December 11, 2018 02:25
Show Gist options
  • Save codehoose/2286b6110aab649d8e98ec4264354cc8 to your computer and use it in GitHub Desktop.
Save codehoose/2286b6110aab649d8e98ec4264354cc8 to your computer and use it in GitHub Desktop.
The `GameSystems` MonoBehaviour is the singleton and contains code to access the systems in the game from one location.
public class GameSystems : MonoBehaviour
{
private static GameSystems _instance;
public static GameSystems Instance
{
get
{
if (_instance == null)
{
_instance = GameObject.FindObjectOfType<GameSystems>();
if (_instance == null)
{
var go = new GameObject("__GAMESYSTEMS__");
_instance = go.AddComponent<GameSystems>();
_instance.Cloud = CloudFactory.Create();
_instance.FileIO = FileSystemFactory.Create();
}
}
}
}
public ICloudService Cloud { get; private set; }
public IFileSystem FileIO { get; private set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment