-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBootstrapper.cs
More file actions
100 lines (84 loc) · 4.32 KB
/
Copy pathBootstrapper.cs
File metadata and controls
100 lines (84 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Constants;
using Infrastructure.StateMachine;
using Services;
using Services.Mono;
using Services.Mono.Sound;
using Services.UI;
using UnityEngine;
namespace Infrastructure
{
public class Bootstrapper : MonoBehaviour, ICoroutineRunner
{
private IGameStateMachine _gameStateMachine;
private void Awake()
{
bool isYaGamesEnvironment = false;
ServiceLocator serviceLocator = new ServiceLocator();
InitAndRegisterGlobalServices(serviceLocator, isYaGamesEnvironment);
_gameStateMachine = new GameStateMachine(serviceLocator, isYaGamesEnvironment);
if (isYaGamesEnvironment)
{
_gameStateMachine.Enter<LoadYaSaveDataState>();
}
else
{
_gameStateMachine.Enter<LoadLocalSaveDataState>();
}
serviceLocator.Register(_gameStateMachine);
DontDestroyOnLoad(this);
}
private void InitAndRegisterGlobalServices(ServiceLocator serviceLocator, bool isYaGamesEnvironment)
{
ISceneLoader sceneLoader = new SceneLoader(this);
IRandomService randomService = new RandomService();
IAssetProviderService assetProviderService = new AssetProviderService();
IStaticDataService staticDataService = new StaticDataService();
ISaveService saveService;
IAdsService adsService;
IYaGamesMonoService yaGamesMonoService;
if (isYaGamesEnvironment)
{
yaGamesMonoService = assetProviderService.Instantiate<YaGamesMonoService>(AssetPaths.YaGamesMonoServicePath);
saveService = new YaGamesSaveService(yaGamesMonoService);
adsService = new YaGamesAdsService(yaGamesMonoService);
}
else
{
yaGamesMonoService = new NullYaGamesMonoService();
saveService = new LocalSaveService();
adsService = new EmptyAdsService();
}
IPersistentDataService persistentDataService = new PersistentDataService(saveService);
ICustomizationService customizationService = new CustomizationService(staticDataService, persistentDataService);
ISettingsService settingsService = new SettingsService(persistentDataService);
ICoinService coinService = new CoinService(persistentDataService);
IPurchaseService purchaseService = new PurchaseService(staticDataService, persistentDataService, coinService);
ILocalizationService localizationService = new LocalizationService(staticDataService, settingsService);
ILoadingCurtainMonoService loadingCurtainMonoService = assetProviderService.Instantiate<LoadingCurtainMonoService>(AssetPaths.LoadingCurtainMonoServicePath);
ISoundMonoService soundMonoService = assetProviderService.Instantiate<SoundMonoService>(AssetPaths.SoundMonoServicePath);
soundMonoService.Init(randomService, settingsService);
IUpdateMonoService updateMonoService = assetProviderService.Instantiate<UpdateMonoService>(AssetPaths.UpdateMonoServicePath);
updateMonoService.Init();
IUiFactory uiFactory = new UiFactory(assetProviderService);
IWindowService windowService = new WindowService(uiFactory, localizationService);
serviceLocator.Register(sceneLoader);
serviceLocator.Register(randomService);
serviceLocator.Register(assetProviderService);
serviceLocator.Register(staticDataService);
serviceLocator.Register(saveService);
serviceLocator.Register(adsService);
serviceLocator.Register(persistentDataService);
serviceLocator.Register(customizationService);
serviceLocator.Register(purchaseService);
serviceLocator.Register(settingsService);
serviceLocator.Register(localizationService);
serviceLocator.Register(coinService);
serviceLocator.Register(yaGamesMonoService);
serviceLocator.Register(loadingCurtainMonoService);
serviceLocator.Register(soundMonoService);
serviceLocator.Register(updateMonoService);
serviceLocator.Register(uiFactory);
serviceLocator.Register(windowService);
}
}
}