private void Awake() { controllers = GetComponents <BaseGameController>(); dependencies = new DependencyContainer(); view = FindObjectOfType <GameLevelView>(); model = GameLevelModel.Create(view.Read()); dependencies.Register(model); dependencies.Register(view); dependencies.Register(Camera.main); dependencies.RegisterMultiple(controllers); dependencies.InjectDependencies(); foreach (var controller in controllers) { controller.Subscribe(); } }
void OnGUI() { if (!level) { level = FindObjectOfType <GameLevelView>(); } showGrid = EditorGUILayout.Toggle("Show grid", showGrid); gridSize = EditorGUILayout.IntSlider("Grid size", gridSize, 10, 100); showWalkableTiles = EditorGUILayout.Toggle("Show walkable tiles", showWalkableTiles); showObstacleTiles = EditorGUILayout.Toggle("Show obstacle tiles", showObstacleTiles); if (GUILayout.Button("Save")) { var config = CreateInstance <GameLevelConfig>(); config.data = level.Read(); AssetDatabaseApi.SaveAsset(config); } if (GUILayout.Button("Load") && AssetDatabaseApi.LoadAsset <GameLevelConfig>(out var loadedConfig)) { level.Write(loadedConfig.data); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } if (GUILayout.Button("Clear")) { level.Clear(); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } var filter = CellType.Empty; if (showObstacleTiles) { filter |= CellType.Obstacle; } if (showWalkableTiles) { filter |= CellType.Walkable; } level.SetFilter(filter); }