Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (C) 2018-2019 gamevanilla. All rights reserved.
- // This code can only be used under the standard Unity Asset Store End User License Agreement,
- // a copy of which is available at http://unity3d.com/company/legal/as_terms.
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using Tutorial.Information;
- using UnityEditor;
- using UnityEditorInternal;
- using UnityEngine;
- using Object = UnityEngine.Object;
- using Random = UnityEngine.Random;
- namespace BubbleShooterKit
- {
- /// <summary>
- /// The 'Level editor' tab in the editor.
- /// </summary>
- public class LevelEditorTab : EditorTab
- {
- private Object levelDbObj;
- private LevelInfo currentLevelInfo;
- private Vector2 scrollPos;
- private const float LevelTileButtonSize = 40f;
- private enum BrushType
- {
- Bubble,
- RandomBubble,
- Booster,
- Blocker,
- Cover,
- Collectable,
- CollectableOldColor,
- CollectableRandomColor,
- Empty
- }
- private BrushType currentBrushType;
- private ColorBubbleType currentColorBubbleType;
- private RandomBubbleType currentRandomBubbleType;
- private BoosterBubbleType currentBoosterBubbleType;
- private BlockerBubbleType currentBlockerBubbleType;
- private CoverType currentCoverType;
- private CollectableBubbleType currentCollectableBubbleType;
- private enum BrushMode
- {
- Tile,
- Row,
- Column,
- Fill
- }
- private BrushMode currentBrushMode;
- private readonly Dictionary<string, Texture> tileTextures = new Dictionary<string, Texture>();
- private int prevRows, precColumns;
- private int tempRows, tempColumn;
- private ReorderableList availableColorsList;
- private ColorBubbleType currentColor;
- private ReorderableList goalList;
- private LevelGoal currentGoal;
- public LevelEditorTab(BubbleShooterKitEditor editor) : base(editor)
- {
- //var editorImagesPath = new DirectoryInfo(Application.dataPath + "/BubbleShooterKit/Editor/Resources");
- var path = Application.dataPath + "/Editor/Resources";
- //Debug.LogError("Path: " + path);
- var editorImagesPath = new DirectoryInfo(path);
- var fileInfo = editorImagesPath.GetFiles("*.png", SearchOption.TopDirectoryOnly);
- foreach (var file in fileInfo)
- {
- var filename = Path.GetFileNameWithoutExtension(file.Name);
- tileTextures[filename] = Resources.Load(filename) as Texture;
- }
- }
- public void DebugLog()
- {
- }
- public override void Draw()
- {
- if (currentLevelInfo != null && currentLevelInfo.tutorialInfo == null) currentLevelInfo.tutorialInfo = new TutorialInfo();
- scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
- var oldLabelWidth = EditorGUIUtility.labelWidth;
- EditorGUIUtility.labelWidth = 90;
- GUILayout.Space(15);
- DrawMenu();
- if (currentLevelInfo != null)
- {
- GUILayout.Space(15);
- GUILayout.BeginHorizontal();
- DrawLevel();
- GUILayout.BeginVertical();
- if(currentLevelInfo.tutorialInfo.isNeedTutorial) currentLevelInfo.tutorialInfo.DrawReord(currentLevelInfo);
- DrawAvailableColors();
- if(currentLevelInfo.isSetColorList) currentLevelInfo.AvalibleColorsStack.Draw(currentLevelInfo);
- DrawGoals();
- DrawAvailableBoosters();
- EditorTabInformer.OnEnterInformation(currentLevelInfo);
- GUILayout.EndVertical();
- GUILayout.EndHorizontal();
- }
- EditorGUIUtility.labelWidth = oldLabelWidth;
- EditorGUILayout.EndScrollView();
- if (GUI.changed && currentLevelInfo!=null)
- EditorUtility.SetDirty(currentLevelInfo);
- }
- private void DrawMenu()
- {
- var oldDb = levelDbObj;
- levelDbObj = EditorGUILayout.ObjectField("Asset", levelDbObj, typeof(LevelInfo), false, GUILayout.Width(340));
- if (levelDbObj != oldDb)
- {
- currentLevelInfo = (LevelInfo)levelDbObj;
- if (currentLevelInfo.AvailableColors == null)
- currentLevelInfo.Initialize();
- tempRows = currentLevelInfo.Rows;
- tempColumn = currentLevelInfo.Columns;
- //currentLevelInfo.Columns = 10;
- CreateAvailableColorsList();
- CreateGoalsList();
- currentLevelInfo.AvalibleColorsStack.CreateBubbleList();
- if(currentLevelInfo.tutorialInfo==null) currentLevelInfo.tutorialInfo = new TutorialInfo();
- currentLevelInfo.tutorialInfo.DOList();
- }
- }
- private void DrawLevel()
- {
- GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(300));
- var style = new GUIStyle
- {
- fontSize = 20,
- fontStyle = FontStyle.Bold,
- normal = { textColor = Color.white }
- };
- EditorGUILayout.LabelField("General", style);
- GUILayout.Space(10);
- GUILayout.BeginHorizontal(GUILayout.Width(300));
- EditorGUILayout.HelpBox(
- "The general settings of this level.",
- MessageType.Info);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Is hard level", "this level is hard."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.isHardLevel = EditorGUILayout.Toggle(currentLevelInfo.isHardLevel, GUILayout.Width(30));
- GUILayout.EndHorizontal();
- GUILayout.Space(10);
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Level number", "The number of this level."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.Number = EditorGUILayout.IntField(currentLevelInfo.Number, GUILayout.Width(30));
- GUILayout.EndHorizontal();
- GUILayout.Space(10);
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Level key", "The enum key of this level."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.Levelkey = (SortedLevelInfoType)EditorGUILayout.EnumPopup( currentLevelInfo.Levelkey,GUILayout.ExpandWidth(false));
- //currentLevelInfo.Number = EditorGUILayout.IntField(currentLevelInfo.Number, GUILayout.Width(30));
- GUILayout.EndHorizontal();
- GUILayout.Space(10);
- prevRows = currentLevelInfo.Rows;
- precColumns = currentLevelInfo.Columns;
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Rows", "The number of rows of this level."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- tempRows = EditorGUILayout.IntField(tempRows, GUILayout.Width(30));
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Columns", "The number of Columns of this level."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- tempColumn = EditorGUILayout.IntField(tempColumn, GUILayout.Width(30));
- GUILayout.EndHorizontal();
- if (GUILayout.Button("Set size",GUILayout.ExpandWidth(false)))
- {
- currentLevelInfo.Rows = tempRows;
- currentLevelInfo.Columns = tempColumn;
- }
- GUILayout.Space(10);
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Tutorial ", "Enable tutorial?"),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.tutorialInfo.isNeedTutorial = EditorGUILayout.Toggle(currentLevelInfo.tutorialInfo.isNeedTutorial, GUILayout.Width(30));
- GUILayout.EndHorizontal();
- GUILayout.Space(10);
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Bubbles", "The number of bubbles that can be used in this level."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.NumBubbles = EditorGUILayout.IntField(currentLevelInfo.NumBubbles, GUILayout.Width(30));
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Need time to level", "If need time in level to game over."),
- GUILayout.Width(150));
- currentLevelInfo.IsNeedTime = EditorGUILayout.Toggle(currentLevelInfo.IsNeedTime);
- if (currentLevelInfo.IsNeedTime)
- {
- EditorGUILayout.LabelField(new GUIContent("Time at level", "Level time in seconds."),
- GUILayout.Width(140));
- currentLevelInfo.TimeToLevel =
- EditorGUILayout.FloatField(currentLevelInfo.TimeToLevel, GUILayout.Width(70));
- }
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Need left bubble stack"),GUILayout.Width(140));
- currentLevelInfo.isSetColorList = EditorGUILayout.Toggle(currentLevelInfo.isSetColorList);
- /* if (currentLevelInfo.isSetColorList)
- {
- EditorGUILayout.LabelField(new GUIContent("Bubble stack", "Bullet bubble stack"),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- SerializedObject so = new SerializedObject(currentLevelInfo);
- var prop = so.FindProperty("leftBubleColors");
- so.Update();
- EditorGUILayout.PropertyField(prop, true);
- so.ApplyModifiedProperties();
- }*/
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Star 1 score", "The number of points needed to obtain the first star."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.Star1Score = EditorGUILayout.IntField(currentLevelInfo.Star1Score, GUILayout.Width(70));
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Star 2 score", "The number of points needed to obtain the second star."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.Star2Score = EditorGUILayout.IntField(currentLevelInfo.Star2Score, GUILayout.Width(70));
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Star 3 score", "The number of points needed to obtain the third star."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.Star3Score = EditorGUILayout.IntField(currentLevelInfo.Star3Score, GUILayout.Width(70));
- GUILayout.EndHorizontal();
- GUILayout.Space(10);
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Brush type", "The type of brush to paint the level."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentBrushType = (BrushType)EditorGUILayout.EnumPopup(currentBrushType, GUILayout.Width(100));
- GUILayout.EndHorizontal();
- switch (currentBrushType)
- {
- case BrushType.Bubble:
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Bubble type", "The bubble type to use."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentColorBubbleType = (ColorBubbleType)EditorGUILayout.EnumPopup(currentColorBubbleType, GUILayout.Width(100));
- GUILayout.EndHorizontal();
- currentCoverType = CoverType.None;
- break;
- }
- case BrushType.RandomBubble:
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Random bubble type", "The random bubble type to use."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentRandomBubbleType = (RandomBubbleType)EditorGUILayout.EnumPopup(currentRandomBubbleType, GUILayout.Width(100));
- GUILayout.EndHorizontal();
- currentCoverType = CoverType.None;
- break;
- }
- case BrushType.Booster:
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Booster type", "The booster type to use."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentBoosterBubbleType = (BoosterBubbleType)EditorGUILayout.EnumPopup(currentBoosterBubbleType, GUILayout.Width(100));
- GUILayout.EndHorizontal();
- currentCoverType = CoverType.None;
- break;
- }
- case BrushType.Blocker:
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Blocker type", "The blocker type to use."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentBlockerBubbleType = (BlockerBubbleType)EditorGUILayout.EnumPopup(currentBlockerBubbleType, GUILayout.Width(100));
- GUILayout.EndHorizontal();
- break;
- }
- case BrushType.Cover:
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Cover type", "The cover type to use."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentCoverType = (CoverType)EditorGUILayout.EnumPopup(currentCoverType, GUILayout.Width(100));
- GUILayout.EndHorizontal();
- break;
- }
- case BrushType.Collectable:
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Collectable type", "The collectable type to use."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentCollectableBubbleType = (CollectableBubbleType)EditorGUILayout.EnumPopup(currentCollectableBubbleType, GUILayout.Width(100));
- if(currentCollectableBubbleType == CollectableBubbleType.Crystal || currentCollectableBubbleType == CollectableBubbleType.Reward)
- {
- currentColorBubbleType = (ColorBubbleType)EditorGUILayout.EnumPopup(currentColorBubbleType, GUILayout.Width(100));
- }
- GUILayout.EndHorizontal();
- break;
- }
- case BrushType.CollectableOldColor:
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Collectable type", "The collectable type to use."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentCollectableBubbleType = (CollectableBubbleType)EditorGUILayout.EnumPopup(currentCollectableBubbleType, GUILayout.Width(100));
- if (currentCollectableBubbleType == CollectableBubbleType.Crystal || currentCollectableBubbleType == CollectableBubbleType.Reward)
- {
- currentColorBubbleType = (ColorBubbleType)EditorGUILayout.EnumPopup(currentColorBubbleType, GUILayout.Width(100));
- }
- GUILayout.EndHorizontal();
- break;
- }case BrushType.CollectableRandomColor:
- {
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Collectable type", "The collectable type to use."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentCollectableBubbleType = (CollectableBubbleType)EditorGUILayout.EnumPopup(currentCollectableBubbleType, GUILayout.Width(100));
- if (currentCollectableBubbleType == CollectableBubbleType.Crystal || currentCollectableBubbleType == CollectableBubbleType.Reward)
- {
- currentRandomBubbleType = (RandomBubbleType)EditorGUILayout.EnumPopup(currentRandomBubbleType, GUILayout.Width(100));
- }
- GUILayout.EndHorizontal();
- break;
- }
- }
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Brush mode", "The brush mode to paint the level."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentBrushMode = (BrushMode)EditorGUILayout.EnumPopup(currentBrushMode, GUILayout.Width(100));
- GUILayout.EndHorizontal();
- if (GUILayout.Button("Randomize", GUILayout.Width(100)))
- RandomizeLevel();
- GUILayout.Space(10);
- if (currentLevelInfo.Rows != prevRows || currentLevelInfo.Columns!= precColumns)
- {
- /*if (currentLevelInfo.Tiles != null)
- {
- foreach (var row in currentLevelInfo.Tiles)
- foreach (var tile in row.Tiles)
- Object.DestroyImmediate(tile, true);
- foreach (var row in currentLevelInfo.Tiles)
- Object.DestroyImmediate(row, true);
- }*/
- /*if (currentLevelInfo.Rows > 0 && currentLevelInfo.Columns > 0)
- {
- currentLevelInfo.Tiles = new List<LevelRow>();
- var evenWidth = currentLevelInfo.Columns;
- var oddWidth = currentLevelInfo.Columns - 1;
- for (var i = 0; i < currentLevelInfo.Rows; i++)
- {
- if (i % 2 == 0)
- {
- var row = ScriptableObject.CreateInstance<LevelRow>();
- row.hideFlags = HideFlags.HideInHierarchy;
- AssetDatabase.AddObjectToAsset(row, currentLevelInfo);
- row.Tiles = new List<TileInfo>(evenWidth);
- row.Tiles.AddRange(Enumerable.Repeat<TileInfo>(null, evenWidth));
- currentLevelInfo.Tiles.Add(row);
- }
- else
- {
- var row = ScriptableObject.CreateInstance<LevelRow>();
- row.hideFlags = HideFlags.HideInHierarchy;
- AssetDatabase.AddObjectToAsset(row, currentLevelInfo);
- row.Tiles = new List<TileInfo>(oddWidth);
- row.Tiles.AddRange(Enumerable.Repeat<TileInfo>(null, oddWidth));
- currentLevelInfo.Tiles.Add(row);
- }
- }
- }*/
- UpdatePrewAndCurrentSize();
- }
- /*if (currentLevelInfo.Tiles != null)
- {
- GUILayout.BeginVertical();
- for (var i = 0; i < currentLevelInfo.Tiles.Count; i++)
- {
- GUILayout.BeginHorizontal();
- if (i % 2 == 1) GUILayout.Space(LevelTileButtonSize * 0.65f);
- var row = currentLevelInfo.Tiles[i];
- if(row!=null && row.Tiles!=null)
- for (var j = 0; j < row.Tiles.Count; j++)
- {
- CreateButton(i, j);
- }
- GUILayout.EndHorizontal();
- }
- GUILayout.EndVertical();
- }*/
- GUILayout.EndVertical();
- }
- public void UpdatePrewAndCurrentSize()
- {
- var evenWidth = currentLevelInfo.Columns;
- var oddWidth = currentLevelInfo.Columns - 1;
- if (currentLevelInfo.Rows != prevRows)
- {
- List<LevelRow> TilesTemp = new List<LevelRow>();
- if (currentLevelInfo.Rows < prevRows)
- {
- for (int i = 0; i < prevRows; i++)
- {
- if(i<currentLevelInfo.Rows) TilesTemp.Add(currentLevelInfo.Tiles[i]);
- else
- {
- foreach (var tile in currentLevelInfo.Tiles[i].Tiles)
- {
- Object.DestroyImmediate(tile, true);
- }
- Object.DestroyImmediate(currentLevelInfo.Tiles[i], true);
- }
- }
- }
- else
- {
- for (int i = 0; i < currentLevelInfo.Rows; i++)
- {
- if(i<prevRows) TilesTemp.Add(currentLevelInfo.Tiles[i]);
- else
- {
- if (i % 2 == 0)
- {
- var row = ScriptableObject.CreateInstance<LevelRow>();
- row.hideFlags = HideFlags.HideInHierarchy;
- AssetDatabase.AddObjectToAsset(row, currentLevelInfo);
- row.Tiles = new List<TileInfo>(evenWidth);
- row.Tiles.AddRange(Enumerable.Repeat<TileInfo>(null, evenWidth));
- TilesTemp.Add(row);
- }
- else
- {
- var row = ScriptableObject.CreateInstance<LevelRow>();
- row.hideFlags = HideFlags.HideInHierarchy;
- AssetDatabase.AddObjectToAsset(row, currentLevelInfo);
- row.Tiles = new List<TileInfo>(oddWidth);
- row.Tiles.AddRange(Enumerable.Repeat<TileInfo>(null, oddWidth));
- TilesTemp.Add(row);
- }
- }
- }
- }
- currentLevelInfo.Tiles = TilesTemp;
- }
- if (currentLevelInfo.Columns != precColumns)
- {
- List<LevelRow> TilesTemp = new List<LevelRow>();
- for (int i = 0; i < currentLevelInfo.Tiles.Count(); i++)
- {
- var lst = new List<TileInfo>();
- var currentTile = currentLevelInfo.Tiles[i];
- bool isOdd = i % 2 != 0;
- if (currentLevelInfo.Columns < precColumns)
- {
- for (int j = 0; j < currentTile.Tiles.Count; j++)
- {
- if (j < (isOdd ? currentLevelInfo.Columns - 1 : currentLevelInfo.Columns))
- {
- lst.Add(currentTile.Tiles[j]);
- }
- else
- {
- Object.DestroyImmediate(currentTile.Tiles[j], true);
- }
- }
- }
- else
- {
- for (int j = 0; j < (isOdd ? currentLevelInfo.Columns-1 : currentLevelInfo.Columns); j++)
- {
- if (j < currentTile.Tiles.Count())
- {
- lst.Add(currentTile.Tiles[j]);
- }
- else
- {
- lst.Add(null);
- }
- }
- }
- currentTile.Tiles = lst;
- TilesTemp.Add(currentTile);
- }
- currentLevelInfo.Tiles = TilesTemp;
- }
- }
- private void CreateGoalsList()
- {
- goalList = SetupReorderableList("Goals", currentLevelInfo.Goals, ref currentGoal, (rect, x) =>
- {
- EditorGUI.LabelField(new Rect(rect.x, rect.y, 200, EditorGUIUtility.singleLineHeight),
- x.ToString());
- },
- (x) =>
- {
- currentGoal = x;
- },
- () =>
- {
- var menu = new GenericMenu();
- menu.AddItem(new GUIContent("Collect bubbles"), false, CreateGoalCallback, typeof(CollectBubblesGoal));
- menu.AddItem(new GUIContent("Collect random bubbles"), false, CreateGoalCallback, typeof(CollectRandomBubblesGoal));
- menu.AddItem(new GUIContent("Collect collectables"), false, CreateGoalCallback, typeof(CollectCollectablesGoal));
- menu.AddItem(new GUIContent("Collect leaves"), false, CreateGoalCallback, typeof(CollectLeavesGoal));
- menu.ShowAsContext();
- },
- (x) =>
- {
- Object.DestroyImmediate(currentGoal, true);
- currentGoal = null;
- });
- }
- private void DrawGoals()
- {
- GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(300));
- var style = new GUIStyle
- {
- fontSize = 20,
- fontStyle = FontStyle.Bold,
- normal = { textColor = Color.white }
- };
- EditorGUILayout.LabelField("Goals", style);
- GUILayout.Space(10);
- GUILayout.BeginHorizontal(GUILayout.Width(300));
- EditorGUILayout.HelpBox(
- "This list defines the goals needed to be achieved by the player in order to complete this level.",
- MessageType.Info);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.BeginVertical(GUILayout.Width(300));
- goalList?.DoLayoutList();
- GUILayout.EndVertical();
- if (currentGoal != null)
- DrawGoal(currentGoal);
- GUILayout.EndHorizontal();
- GUILayout.EndVertical();
- }
- private void DrawGoal(LevelGoal goal)
- {
- var oldLabelWidth = EditorGUIUtility.labelWidth;
- EditorGUIUtility.labelWidth = 60;
- switch (goal)
- {
- case CollectBubblesGoal collectBubblesGoal:
- goal.Draw();
- break;
- case CollectCollectablesGoal collectCollectablesGoal:
- int CountGoal = 0;
- foreach (var row_ in currentLevelInfo.Tiles)
- {
- if(row_!=null)
- foreach (var column in row_.Tiles)
- {
- if(column!=null)
- switch (column)
- {
- case CollectableTileInfo collectableTileInfo:
- if (collectCollectablesGoal.Type == collectableTileInfo.Type) CountGoal++;
- break;
- case ColectableRandomBubbleTileInfo colectableRandomBubbleTileInfo:
- if (collectCollectablesGoal.Type == colectableRandomBubbleTileInfo.Type) CountGoal++;
- break;
- }
- }
- }
- goal.Draw(CountGoal);
- break;
- case CollectLeavesGoal collectLeavesGoal:
- var firstRow = currentLevelInfo.Tiles[0];
- int CountLeaves = 0;
- if(firstRow!=null)
- foreach (var item in firstRow.Tiles)
- {
- if(item!=null)
- switch (item)
- {
- case BlockerTileInfo blockerTileInfo:
- CountLeaves++;
- break;
- case BoosterTileInfo boosterTileInfo:
- CountLeaves++;
- break;
- case BubbleTileInfo bubbleTileInfo:
- CountLeaves++;
- break;
- case CollectableTileInfo collectableTileInfo:
- CountLeaves++;
- break;
- case RandomBubbleTileInfo randomBubbleTileInfo:
- CountLeaves++;
- break;
- case ColectableRandomBubbleTileInfo colectableRandomBubbleTileInfo:
- CountLeaves++;
- break;
- case EnemyTileInfo enemyTileInfo:
- CountLeaves++;
- break;
- }
- }
- goal.Draw(CountLeaves);
- break;
- case CollectRandomBubblesGoal collectRandomBubblesGoal:
- goal.Draw();
- break;
- case KillEnimyGoal killEnimyGoal:
- goal.Draw();
- break;
- }
- EditorGUIUtility.labelWidth = oldLabelWidth;
- }
- private void CreateGoalCallback(object obj)
- {
- var goal = ScriptableObject.CreateInstance(((Type) obj).Name) as LevelGoal;
- if (goal != null)
- {
- goal.hideFlags = HideFlags.HideInHierarchy;
- currentLevelInfo.Goals.Add(goal);
- AssetDatabase.AddObjectToAsset(goal, currentLevelInfo);
- }
- }
- private void CreateAvailableColorsList()
- {
- availableColorsList = SetupReorderableList("Available colors", currentLevelInfo.AvailableColors, ref currentColor, (rect, x) =>
- {
- EditorGUI.LabelField(new Rect(rect.x, rect.y, 200, EditorGUIUtility.singleLineHeight),
- x.ToString());
- },
- (x) => { currentColor = x; },
- () =>
- {
- var menu = new GenericMenu();
- foreach (var color in Enum.GetValues(typeof(ColorBubbleType)))
- {
- var isUsed = currentLevelInfo.AvailableColors.Contains((ColorBubbleType)color);
- if (isUsed)
- menu.AddDisabledItem(new GUIContent(color.ToString()));
- else
- menu.AddItem(new GUIContent(color.ToString()), false, CreateColorCallback, color);
- }
- menu.ShowAsContext();
- },
- (x) => { currentColor = ColorBubbleType.Black; });
- }
- private void CreateColorCallback(object obj)
- {
- currentLevelInfo.AvailableColors.Add((ColorBubbleType)obj);
- }
- private void DrawAvailableColors()
- {
- GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(300));
- var style = new GUIStyle
- {
- fontSize = 20,
- fontStyle = FontStyle.Bold,
- normal = { textColor = Color.white }
- };
- EditorGUILayout.LabelField("Available colors", style);
- GUILayout.Space(10);
- GUILayout.BeginHorizontal(GUILayout.Width(300));
- EditorGUILayout.HelpBox(
- "This list defines the available bubble colors in this level.",
- MessageType.Info);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.BeginVertical(GUILayout.Width(300));
- availableColorsList?.DoLayoutList();
- GUILayout.EndVertical();
- GUILayout.EndHorizontal();
- GUILayout.EndVertical();
- }
- private void DrawAvailableBoosters()
- {
- GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(300));
- var style = new GUIStyle
- {
- fontSize = 20,
- fontStyle = FontStyle.Bold,
- normal = { textColor = Color.white }
- };
- EditorGUILayout.LabelField("Available boosters", style);
- GUILayout.Space(10);
- GUILayout.BeginHorizontal(GUILayout.Width(300));
- EditorGUILayout.HelpBox(
- "Cumulative booster.",
- MessageType.Info);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Left enable", "Left cumulative booster enable state"),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.isLeftBoosterEnabled = EditorGUILayout.Toggle(currentLevelInfo.isLeftBoosterEnabled);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Right enable", "Right cumulative booster enable state"),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.isRightBoosterEnabled = EditorGUILayout.Toggle(currentLevelInfo.isRightBoosterEnabled);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal(GUILayout.Width(300));
- EditorGUILayout.HelpBox(
- "Here you can specify the available purchasable boosters for this level.",
- MessageType.Info);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Super aim", "Super aim."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.IsSuperAimAvailable = EditorGUILayout.Toggle(currentLevelInfo.IsSuperAimAvailable);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Rainbow bomb", "Rainbow bomb."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.IsRainbowBombAvailable = EditorGUILayout.Toggle(currentLevelInfo.IsRainbowBombAvailable);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("undone", "Endone."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.IsHorizontalBombAvailable = EditorGUILayout.Toggle(currentLevelInfo.IsHorizontalBombAvailable);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Sun super bomb", "Sun super bomb."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.IsCircleBombAvailable = EditorGUILayout.Toggle(currentLevelInfo.IsCircleBombAvailable);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent("Show 3 bubble", "3 bubble."),
- GUILayout.Width(EditorGUIUtility.labelWidth));
- currentLevelInfo.Is3BubbleAvailable = EditorGUILayout.Toggle(currentLevelInfo.Is3BubbleAvailable);
- GUILayout.EndHorizontal();
- GUILayout.EndVertical();
- }
- private void CreateButton(int row, int column)
- {
- var tileTypeName = string.Empty;
- if (currentLevelInfo.Tiles.Count == 0) return;
- var tile = currentLevelInfo.Tiles[row].Tiles[column];
- if (tile != null)
- {
- var bubbleTile = tile as BubbleTileInfo;
- if (bubbleTile != null)
- {
- tileTypeName = $"{bubbleTile.Type.ToString()}Bubble";
- if (bubbleTile.CoverType != CoverType.None)
- tileTypeName += "_" + bubbleTile.CoverType;
- }
- var randomBubbleTile = tile as RandomBubbleTileInfo;
- if (randomBubbleTile != null)
- {
- tileTypeName = $"{randomBubbleTile.Type.ToString()}";
- if (randomBubbleTile.CoverType != CoverType.None)
- tileTypeName += "_" + randomBubbleTile.CoverType;
- }
- var blockerTile = tile as BlockerTileInfo;
- if (blockerTile != null)
- tileTypeName = $"{blockerTile.BubbleType.ToString()}";
- var boosterTile = tile as BoosterTileInfo;
- if (boosterTile != null)
- tileTypeName = $"{boosterTile.BubbleType.ToString()}";
- var collectableTile = tile as CollectableTileInfo;
- if (collectableTile != null)
- {
- tileTypeName = $"{collectableTile.Type.ToString()}";
- var inImage = $"{collectableTile.colorType.ToString()}Bubble";
- var color = collectableTile.colorType.ToString();
- var inText = "C " + color[0] + color[1] + color[2];
- DrawButton(tileTextures[tileTypeName], tileTextures[inImage], "", () => { DrawTile(row, column); });
- /*if (GUILayout.Button(tileTextures[tileTypeName], inText, GUILayout.Width(LevelTileButtonSize),GUILayout.Height(LevelTileButtonSize)))
- DrawTile(row, column);*/
- return;
- }
- var collectableRandom = tile as ColectableRandomBubbleTileInfo;
- if (collectableRandom != null)
- {
- tileTypeName = $"{collectableRandom.Type.ToString()}";
- var inImage = $"{collectableRandom.TypeRandom.ToString()}";
- //GUILayout.Box(tileTextures[inImage], GUILayout.Width(LevelTileButtonSize),GUILayout.Height(LevelTileButtonSize));
- //GUI.DrawTexture(new Rect(0, 0, LevelTileButtonSize, LevelTileButtonSize), );
- var inText = "R" + ((int)collectableRandom.TypeRandom+1);
- var content = new GUIContent();
- content.text = inText;
- content.image = tileTextures[tileTypeName];
- DrawButton(tileTextures[tileTypeName], tileTextures[inImage], "", () => { DrawTile(row, column); });
- /*if (GUILayout.Button(content ,GUILayout.Width(LevelTileButtonSize),GUILayout.Height(LevelTileButtonSize)))
- DrawTile(row, column);*/
- return;
- }
- if (GUILayout.Button(tileTextures[tileTypeName], GUILayout.Width(LevelTileButtonSize),GUILayout.Height(LevelTileButtonSize)))
- DrawTile(row, column);
- }
- else
- {
- if (GUILayout.Button("", GUILayout.Width(LevelTileButtonSize),
- GUILayout.Height(LevelTileButtonSize)))
- DrawTile(row, column);
- }
- }
- private void DrawButton(Texture t1, Texture t2, string text, Action action)
- {
- var content = new GUIContent();
- var btn = new GUIStyle(GUI.skin.button);
- btn.normal.background = (Texture2D)t2;
- btn.hover.background = (Texture2D)t2;
- btn.active.background = (Texture2D)t2;
- btn.stretchHeight = false;
- btn.stretchWidth = false;
- content.image = t1;
- content.text = text;
- if (GUILayout.Button(content, btn, GUILayout.Width(LevelTileButtonSize),
- GUILayout.Height(LevelTileButtonSize)))
- {
- if(action!=null) action.Invoke();
- }
- }
- private void DrawTile(int row, int column)
- {
- switch (currentBrushMode)
- {
- case BrushMode.Tile:
- currentLevelInfo.Tiles[row].Tiles[column] = DrawTile(currentLevelInfo.Tiles[row].Tiles[column], row);
- break;
- case BrushMode.Row:
- {
- var currentRow = currentLevelInfo.Tiles[row];
- for (var i = 0; i < currentRow.Tiles.Count; i++)
- {
- currentRow.Tiles[i] = DrawTile(currentRow.Tiles[i], row);
- }
- }
- break;
- case BrushMode.Column:
- for (var i = 0; i < currentLevelInfo.Rows; i++)
- {
- if (column < currentLevelInfo.Tiles[i].Tiles.Count)
- currentLevelInfo.Tiles[i].Tiles[column] = DrawTile(currentLevelInfo.Tiles[i].Tiles[column], row);
- }
- break;
- case BrushMode.Fill:
- for (var j = 0; j < currentLevelInfo.Rows; j++)
- {
- var currentRow = currentLevelInfo.Tiles[j];
- for (var i = 0; i < currentRow.Tiles.Count; i++)
- {
- currentLevelInfo.Tiles[j].Tiles[i] = DrawTile(currentLevelInfo.Tiles[j].Tiles[i], row);
- }
- }
- break;
- }
- }
- public bool isRandom = false;
- public RandomBubbleType randomType;
- private TileInfo DrawTile(TileInfo tile, int row)
- {
- if (currentBrushType == BrushType.Cover)
- {
- var info = tile as BubbleTileInfo;
- if (info != null)
- {
- info.CoverType = currentCoverType;
- return info;
- }
- var bubbleTileInfo = tile as RandomBubbleTileInfo;
- if (bubbleTileInfo != null)
- {
- bubbleTileInfo.CoverType = currentCoverType;
- return bubbleTileInfo;
- }
- }
- var bc = tile as BubbleTileInfo;
- var bcr = tile as RandomBubbleTileInfo;
- if (bcr != null && currentBrushType == BrushType.CollectableOldColor)
- {
- currentRandomBubbleType = bcr.Type;
- isRandom = true;
- }
- if (bc != null && currentBrushType == BrushType.CollectableOldColor)
- {
- var color = bc.Type;
- currentColorBubbleType = color;
- Debug.LogError("Get Color " + color);
- }
- Object.DestroyImmediate(tile, true);
- var tileInfo = GetTileInfo();
- if (tileInfo != null && !AssetDatabase.IsSubAsset(tileInfo))
- AssetDatabase.AddObjectToAsset(tileInfo, currentLevelInfo.Tiles[row]);
- return tileInfo;
- }
- private TileInfo GetTileInfo()
- {
- switch (currentBrushType)
- {
- case BrushType.Bubble:
- {
- var tileInfo = ScriptableObject.CreateInstance<BubbleTileInfo>();
- tileInfo.hideFlags = HideFlags.HideInHierarchy;
- tileInfo.Type = currentColorBubbleType;
- tileInfo.CoverType = currentCoverType;
- return tileInfo;
- }
- case BrushType.RandomBubble:
- {
- var tileInfo = ScriptableObject.CreateInstance<RandomBubbleTileInfo>();
- tileInfo.hideFlags = HideFlags.HideInHierarchy;
- tileInfo.Type = currentRandomBubbleType;
- tileInfo.CoverType = currentCoverType;
- return tileInfo;
- }
- case BrushType.Blocker:
- {
- var tileInfo = ScriptableObject.CreateInstance<BlockerTileInfo>();
- tileInfo.hideFlags = HideFlags.HideInHierarchy;
- tileInfo.BubbleType = currentBlockerBubbleType;
- return tileInfo;
- }
- case BrushType.Booster:
- {
- var tileInfo = ScriptableObject.CreateInstance<BoosterTileInfo>();
- tileInfo.hideFlags = HideFlags.HideInHierarchy;
- tileInfo.BubbleType = currentBoosterBubbleType;
- return tileInfo;
- }
- case BrushType.Collectable:
- {
- var tileInfo = ScriptableObject.CreateInstance<CollectableTileInfo>();
- tileInfo.hideFlags = HideFlags.HideInHierarchy;
- tileInfo.Type = currentCollectableBubbleType;
- tileInfo.colorType = currentColorBubbleType;
- return tileInfo;
- }
- case BrushType.CollectableOldColor:
- {
- var tileInfo = ScriptableObject.CreateInstance<CollectableTileInfo>();
- tileInfo.hideFlags = HideFlags.HideInHierarchy;
- tileInfo.Type = currentCollectableBubbleType;
- tileInfo.colorType = currentColorBubbleType;
- Debug.LogError("Set Color " + currentColorBubbleType);
- return tileInfo;
- }
- case BrushType.CollectableRandomColor:
- {
- var tileInfo = ScriptableObject.CreateInstance<ColectableRandomBubbleTileInfo>();
- tileInfo.hideFlags = HideFlags.HideInHierarchy;
- tileInfo.Type = currentCollectableBubbleType;
- tileInfo.TypeRandom = currentRandomBubbleType;
- Debug.LogError("Set Color " + currentColorBubbleType);
- return tileInfo;
- }
- default:
- return null;
- }
- }
- private void RandomizeLevel()
- {
- for (var j = 0; j < currentLevelInfo.Rows; j++)
- {
- for (var i = 0; i < currentLevelInfo.Tiles[j].Tiles.Count; i++)
- {
- var rndIdx = Random.Range(0, currentLevelInfo.AvailableColors.Count);
- var tileInfo = ScriptableObject.CreateInstance<RandomBubbleTileInfo>();
- tileInfo.hideFlags = HideFlags.HideInHierarchy;
- tileInfo.Type = (RandomBubbleType)rndIdx;
- currentLevelInfo.Tiles[j].Tiles[i] = tileInfo;
- if (!AssetDatabase.IsSubAsset(tileInfo))
- AssetDatabase.AddObjectToAsset(tileInfo, currentLevelInfo.Tiles[j]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement