/// <summary> /// Create GUI elements for operations with level tiles. /// </summary> private void DisplayEditLevelGui() { EditorGUILayout.BeginVertical(_innerContainerGuiStyle); EditorGUILayout.LabelField("Level Edit", EditorStyles.boldLabel); EditorGUILayout.LabelField("Select tile config and click over the small buttons to repaint level tile.", EditorStyles.miniLabel); EditorGUILayout.Space(); if (_currentLevelDataModel != null) { if (_currentTileConfig == null) { EditorGUILayout.HelpBox("Select Tile Config to have ability edit current level tiles.", MessageType.Warning); } else { var levelSize = _currentLevelDataModel.GetLevelSize(); for (var y = 0; y < levelSize.y; y++) { EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); for (var x = 0; x < levelSize.x; x++) { var materialType = _currentLevelDataModel.GetTileByCoords(x, y).tileMaterialType; if (materialType != TileMaterialTypes.EMPTY) { var texture = _tileConfigsLibrary.GetTileConfigByMaterialType(materialType).tileMaterialConfig.materialSprite.texture; _tileEditButtonGuiContent = new GUIContent(texture); } else { _tileEditButtonGuiContent = new GUIContent($"{x}-{y}"); } if (GUILayout.Button(_tileEditButtonGuiContent, _tileEditButtonGuiStyle, GUILayout.Width(TILE_BUTTON_SIZE), GUILayout.Height(TILE_BUTTON_SIZE))) { var tileData = _currentLevelDataModel.GetTileByCoords(x, y); tileData.tileType = _currentTileConfig.tileType; tileData.tileMaterialType = _currentTileConfig.tileMaterialConfig.tileMaterialType; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } } } EditorGUILayout.EndVertical(); }
/// <summary> /// Create GUI elements for operations with level creation or loading. /// </summary> private void DisplayCreateLevelGui() { EditorGUILayout.BeginVertical(_innerContainerGuiStyle); EditorGUILayout.LabelField("Level Creation", EditorStyles.boldLabel); _levelName = EditorGUILayout.TextField("Level Name", _levelName); EditorGUILayout.LabelField("How much tiles will have level with and height.", EditorStyles.miniLabel); _levelSize = EditorGUILayout.Vector2IntField("Level Size: ", _levelSize); EditorGUILayout.Space(); if (GUILayout.Button("Create New Level", GUILayout.ExpandWidth(true), GUILayout.Height(PRIMARY_BUTTON_HEIGHT))) { _currentLevelDataModel = new LevelDataModel(_levelSize.x, _levelSize.y) { levelName = _levelName }; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Level Loading", EditorStyles.boldLabel); _savedLevelJSON = (TextAsset)EditorGUILayout.ObjectField("JSON Level:", _savedLevelJSON, typeof(TextAsset), false); if (GUILayout.Button("Load Level", GUILayout.ExpandWidth(true), GUILayout.Height(PRIMARY_BUTTON_HEIGHT))) { var deserializedData = JsonUtility.FromJson <LevelDataModel>(_savedLevelJSON.text); _currentLevelDataModel = deserializedData; _levelSize = _currentLevelDataModel.GetLevelSize(); _levelName = _currentLevelDataModel.levelName; } EditorGUILayout.Space(); if (_currentLevelDataModel == null) { EditorGUILayout.HelpBox("Click at the button \"Create New Level\" to create new Level Data.\nOr \"Load Level\" to load levels JSON config.", MessageType.Warning); } EditorGUILayout.EndVertical(); }