public void Extend(IContext context)
        {
            IMediatorMap     mediatorMap = context.injector.GetInstance <IMediatorMap> ();
            IEventCommandMap commandMap  = context.injector.GetInstance <IEventCommandMap> ();

            // Sound
            context.injector.Map <ISoundModel>().ToSingleton <SoundModel>();
            commandMap.Map(SoundEvent.Type.PLAY_SOUND_EFFECT).ToCommand <PlaySoundCommand>();
            commandMap.Map(SoundEvent.Type.PLAY_MUSIC_TRACK).ToCommand <PlaySoundCommand>();
            commandMap.Map(SoundEvent.Type.STOP_MUSIC_TRACK).ToCommand <PlaySoundCommand>();
            commandMap.Map(SoundEvent.Type.STOP_SOUND_EFFECTS).ToCommand <PlaySoundCommand>();
            commandMap.Map(SoundVolumeEvent.Type.SET_MUSIC_VOLUME).ToCommand <SetSoundVolumeCommand>();
            commandMap.Map(SoundVolumeEvent.Type.SET_SOUND_EFFECTS_VOLUME).ToCommand <SetSoundVolumeCommand>();

            mediatorMap.Map(typeof(SoundLoaderView)).ToMediator(typeof(SoundLoaderMediator));
            mediatorMap.Map(typeof(ISoundSetView)).ToMediator(typeof(SoundSetMediator));
            mediatorMap.Map(typeof(ISoundView)).ToMediator(typeof(SoundMediator));
            soundFX           = new GameObject("SoundFX");
            soundMusic        = new GameObject("SoundMusic");
            soundFX.hideFlags = soundMusic.hideFlags = HideFlags.HideInHierarchy;
            GameObject.DontDestroyOnLoad(soundFX);
            GameObject.DontDestroyOnLoad(soundMusic);
            context.injector.Map <GameObject>(SoundKeys.GAMEOBJECT_EFFECTS).ToValue(soundFX);
            context.injector.Map <GameObject>(SoundKeys.GAMEOBJECT_MUSIC).ToValue(soundMusic);

            context.AfterDestroying(Cleanup);
        }
    private void Awake()
    {
        _injector        = new Injector();
        _directCommand   = new DirectCommand(_injector);
        _eventDispatcher = new EventDispatcher();
        _eventCommandMap = new EventCommandMap(_eventDispatcher, _injector);
        _viewFactory     = new ViewFactory();
        _mediatorMap     = new MediatorMap(_viewFactory, _injector);
        _entityDatabase  = new EntityDatabase();
        _systemMap       = new SystemMap(_entityDatabase);
        _updater         = new Updater();

        _injector.Inject(_directCommand);
        _injector.Inject(_eventDispatcher);
        _injector.Inject(_entityDatabase);
        _injector.Inject(_mediatorMap);
        _injector.Inject <IUpdater>(_updater);

        // systems
        _systemMap.Add(new PlayerMovementSystem());
        _systemMap.Add(new PlayerShootingSystem());
        _systemMap.Add(new CameraFollowSystem());
        _systemMap.Add(new EnemySpawnerSystem());
        _systemMap.Add(new EnemyMovementSystem());
        _systemMap.Add(new EnemyDamageSystem());
        _systemMap.Add(new EnemyAttackSystem());
        _systemMap.Add(new PlayerDamageSystem());
        _systemMap.Add(new EnemySinkingSystem());

        // injection
        _injector.Inject <IGameData>(gameData);
        _injector.Inject(new AudioModel());
        _injector.Inject(new PlayerHealthModel());
        _injector.Inject(new ScoreModel());

        // view factory
        _viewFactory.Register(damageView, false);
        _viewFactory.Register(gameOverView, false);
        _viewFactory.Register(healthView, false);
        _viewFactory.Register(pauseView, false);
        _viewFactory.Register(scoreView, false);

        // mediator
        _mediatorMap.Map <DamageMediator>(ViewType.Damage);
        _mediatorMap.Map <GameOverMediator>(ViewType.GameOver);
        _mediatorMap.Map <HealthMediator>(ViewType.Health);
        _mediatorMap.Map <PauseMediator>(ViewType.Pause);
        _mediatorMap.Map <ScoreMediator>(ViewType.Score);

        // event command
        _eventCommandMap.Map(GameEvent.GameOverComplete, new RestartCommand());
    }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Context"/> class.
 /// </summary>
 public Module()
 {
     m_eventDispatcher = new EventDispatcher();
     m_modelMap        = new ModelMap();
     m_mediatorMap     = new MediatorMap();
 }