示例#1
0
    /// <summary>
    ///     Returns a singletone instance of MainManagers. Creates a new one if necessary.
    /// </summary>
    public MainSystem CreateSingletonMainSystem()
    {
        // Enforce Singleton Factory
        if (_mainSystem != null)
        {
            return(_mainSystem);
        }

        // Create main system
        var mainObject = Instantiate(_mainSystemPrefab);

        _mainSystem = mainObject.GetComponent <MainSystem>();

        // Create scene manager
        var sceneObject  = Instantiate(_sceneManagerPrefab);
        var sceneManager = sceneObject.GetComponent <GameSceneManager>();

        // Create music manager
        var musicObject  = Instantiate(_musicManagerPrefab);
        var musicManager = musicObject.GetComponent <MusicManager>();

        // Initialize main system
        _mainSystem.Initialize(sceneManager, musicManager);

        return(_mainSystem);
    }