// Update is called once per frame //void Update() //{ //} #region Logic ball public void InitBalls(LevelProfile level) { if (_gridManager == null) { _gridManager = new GridManager(8, 14, 120, 100); if (level is ProceduralLevelProfile) { _secondaryGridManager = new GridManager(8, 14, 120, 100, new Vector2(0, -_gridManager.GetCellSizeY() / 2 * 27 - _gridManager.GetCellSizeY() / 2.0f)); } _numberOfInitRow = level.GetInitRow(); _numberOfDiffColor = level.GetNumColor(); } for (int i = 0; i < _gridManager.GetGridSizeX(); i++) { for (int j = 0; j < _numberOfInitRow; j++) { if (_gridManager.IsValidGridPosition(i, j)) { Ball ball = instantiateNewBall(randomBallColor(_numberOfDiffColor + 1)); assignBallToGrid(ball, i, j); ball.FixPosition(); } } } }
public static void InitWithContent(LevelProfile profile) { FirstWindow window = EditorWindow.GetWindow(typeof(FirstWindow)) as FirstWindow; window.currentProfile = profile; window.Show(); }
public LevelProfile GetClone() { LevelProfile clone = new LevelProfile(); clone.level = level; clone.width = width; clone.height = height; clone.chipCount = chipCount; clone.countOfEachTargetCount = countOfEachTargetCount; clone.targetSugarDropsCount = targetSugarDropsCount; clone.targetColorCount = targetColorCount; clone.firstStarScore = firstStarScore; clone.secondStarScore = secondStarScore; clone.thirdStarScore = thirdStarScore; clone.target = target; clone.duraction = duraction; clone.moveCount = moveCount; clone.slot = slot; clone.generator = generator; clone.teleport = teleport; clone.sugarDrop = sugarDrop; clone.chip = chip; clone.jelly = jelly; clone.block = block; clone.powerup = powerup; clone.wallV = wallV; clone.wallH = wallH; return(clone); }
static bool DrawWallButton(int x, int y, string t, Rect r, LevelProfile lp) { bool btn = false; if (t == "H") { btn = lp.GetWallH(x, y); } if (t == "V") { btn = lp.GetWallV(x, y); } defaultColor = GUI.color; Color color = defaultColor; if (btn) { color *= Color.black; } GUI.color = color; if (t == "V") { btn = GUI.Button(new Rect(r.xMin + (x + 1) * (30 + slotOffect) - 5 - slotOffect / 2, r.yMin + y * (30 + slotOffect) - 10 + 15, 10, 20), "", slotStyle); } if (t == "H") { btn = GUI.Button(new Rect(r.xMin + x * (30 + slotOffect) - 10 + 15, r.yMin + (y + 1) * (30 + slotOffect) - 5 - slotOffect / 2, 20, 10), "", slotStyle); } GUI.color = defaultColor; return(btn); }
public void InitBalls(LevelProfile level) { if (_gridManager == null) { _gridManager = new GridManager(12, level.numRows + level.extraRows, CELL_SIZE_X, CELL_SIZE_Y); _numberOfDiffColor = level.GetNumColor(); } _bottomRow = level.numRows - 1; _lastRowToPushDown = Mathf.FloorToInt((850 - Deadline.transform.localPosition.y) / CELL_SIZE_Y) - level.extraRows; PivotGrid.localPosition = new Vector2(PivotGrid.localPosition.x, (Deadline.localPosition.y + ((level.numRows + level.extraRows - 1) * CELL_SIZE_Y)) + 10); for (int i = 1; i < _gridManager.GetGridSizeX() - 1; i++) { for (int j = 0; j < level.numRows; j++) { if (_gridManager.IsValidGridPosition(i, j)) { Ball ball = instantiateNewBall(randomBallColor()); assignBallToGrid(ball, i, j); if (ball != null) { ball.FixPosition(); } } } } }
public static void DrawWallPreview(Rect r, LevelProfile lp) { int x; int y; GUI.enabled = false; for (x = 0; x < lp.width - 1; x++) { for (y = 0; y < lp.height; y++) { if (lp.GetWallV(x, y) && lp.GetSlot(x, y) && lp.GetSlot(x + 1, y)) { DrawWallButton(x, y, "V", r, lp); } } } for (x = 0; x < lp.width; x++) { for (y = 0; y < lp.height - 1; y++) { if (lp.GetWallH(x, y) && lp.GetSlot(x, y) && lp.GetSlot(x, y + 1)) { DrawWallButton(x, y, "H", r, lp); } } } GUI.enabled = true; }
public LevelProfile GetClone() { LevelProfile clone = new LevelProfile(); clone.level = level; clone.width = width; clone.height = height; clone.chipCount = chipCount; clone.firstStarScore = firstStarScore; clone.secondStarScore = secondStarScore; clone.thirdStarScore = thirdStarScore; clone.target = target; clone.duraction = duraction; clone.moveCount = moveCount; clone.slot = slot; clone.chip = chip; clone.jelly = jelly; clone.block = block; clone.powerup = powerup; clone.wallV = wallV; clone.wallH = wallH; return(clone); }
public static LevelProfile OpenLevel(string nameLevel) { LevelProfile _level = null; string levelText; if (_levelPath.Contains("://")) { WWW www = new WWW(_levelPath + nameLevel + ".xml"); while (!www.isDone) { } levelText = www.text; } // --- Для РС IOS и тд грузим так ---// else { #if UNITY_IOS && !UNITY_EDITOR _levelPath = Application.persistentDataPath + "/Levels/"; #endif levelText = File.ReadAllText(_levelPath + nameLevel + ".xml"); } XmlSerializer serializer = new XmlSerializer(typeof(LevelProfile)); _level = serializer.Deserialize(new StringReader(levelText)) as LevelProfile; return(_level); }
public LevelProfile GetClone() { LevelProfile clone = new LevelProfile(); clone = (LevelProfile)MemberwiseClone(); clone.levelID = -1; return(clone); }
public static void LoadLevelInEditor(int key) { if (!all.ContainsKey(key)) { return; } LevelProfile.SetLevelProfile(all[key]); }
public void ShowField(LevelProfile level) { Level _newLevel = new Level(); _newLevel.profile = level; ExitLevel(); InstantiateField(_newLevel); }
void StartLevel(int level) { if (level < levels.Count) { currentLP = this [level]; if (currentLP.condition is ITimable) { (currentLP.condition as ITimable).Start(); } BeginEvent(); } }
public static void SaveLevel(LevelProfile prof) { Debug.Log(_levelPath + prof.nameOfLevel); #if UNITY_IOS && !UNITY_EDITOR _levelPath = Application.persistentDataPath + "/Levels/"; #endif using (FileStream fg = new FileStream(string.Format(_levelPath + prof.nameOfLevel + ".xml"), FileMode.Create)) { formatter.Serialize(fg, prof); } }
public void SetCurrentLevel(ViewCellInLevelList cell) { Debug.Log("SetCurrentLevel cell.Name " + cell.Name); _currentLevel = XmlSerializator.OpenLevel(cell.Name); cell.ProfileContainedInCell = _currentLevel; _showFieldInEditor.ShowField(_currentLevel); _btnEditLevel.interactable = true; LevelSelectInEditor = int.Parse(_currentLevel.nameOfLevel); }
public Field(LevelProfile profile) { width = profile.width; height = profile.height; colorCount = profile.colorCount; foreach (SlotSettings slot in profile.slots) { if (!slots.ContainsKey(slot.position)) { slots.Add(slot.position, slot.GetClone()); } } FirstChipGeneration(); }
void Awake() { if (!Application.isEditor) { Destroy(gameObject); } for (int i = 0; i < 50; i++) { profile = new LevelProfile(); profile.level = (i + 1); all.Add(profile.level, XmlSerializator.OpenLevel((i + 1).ToString())); } }
public Field(LevelProfile profile) { width = profile.width; height = profile.height; colorCount = profile.colorCount; foreach (SlotSettings slot in profile.slots) { if (!slots.ContainsKey(slot.position)) { slots.Add(slot.position, slot.GetClone()); } } wall_horizontal = new List <int2>(profile.wall_horizontal); wall_vertical = new List <int2>(profile.wall_vertical); FirstChipGeneration(); }
bool DrawSlotButtonTeleport(int x, int y, Rect r, LevelProfile lp) { if (!lp.GetSlot(x, y)) { return(false); } defaultColor = GUI.backgroundColor; Color color = Color.cyan; if (teleportID.x == x && teleportID.y == y) { color = Color.magenta; } if (lp.GetTeleport(Mathf.FloorToInt(teleportID.x), Mathf.FloorToInt(teleportID.y)) == 12 * y + x + 1) { color = Color.yellow; } string label = ""; bool btn = false; GUI.backgroundColor = color; btn = GUI.Button(new Rect(r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect), cellSize, cellSize), label, slotStyle); if (lp.GetSlot(x, y) && lp.GetGenerator(x, y)) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) - 2, r.yMin + y * (cellSize + slotOffect) - 2, 10, 10), "G", iconStyle); } if (lp.GetSlot(x, y) && lp.GetTeleport(x, y) > 0) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + 10, r.yMin + y * (cellSize + slotOffect) - 2, cellSize - 12, 10), "T:" + lp.GetTeleport(x, y).ToString(), iconStyle); } if (lp.GetSlot(x, y)) { GUI.backgroundColor = transparentColor; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect) + cellSize - 10, 20, 10), (y * 12 + x + 1).ToString(), slotStyle); } GUI.backgroundColor = defaultColor; return(btn); }
public static void SetLevelProfile(LevelProfile profile) { LevelProfileNow = profile; int[] colorMask = { 0, 1, 2, 3, 4, 5 }; int j; for (int i = 5; i > 0; i--) { j = Random.Range(0, i); colorMask[j] = colorMask[j] + colorMask[i]; colorMask[i] = colorMask[j] - colorMask[i]; colorMask[j] = colorMask[j] - colorMask[i]; } ColorMask = colorMask; }
public static void DrawSlotPreview(Rect r, LevelProfile lp) { int x; int y; GUI.enabled = false; for (x = 0; x < lp.width; x++) { for (y = 0; y < lp.height; y++) { if (lp.GetSlot(x, y)) { DrawSlotButton(x, y, r, lp); } } } GUI.enabled = true; }
static bool DrawSlotButton(int x, int y, Rect r, LevelProfile lp) { defaultColor = GUI.color; Color color = defaultColor; string label = ""; bool btn = false; if (!lp.GetSlot(x, y)) { color *= transparentColor; } else { if (lp.GetBlock(x, y) == 0 && lp.GetChip(x, y) > 0) { if (lp.GetChip(x, y) > lp.chipCount) { lp.SetChip(x, y, lp.chipCount); } color *= chipColor[lp.GetChip(x, y) - 1]; } if (lp.GetBlock(x, y) == 0 && lp.GetChip(x, y) == -1 && lp.GetPowerup(x, y) == 0) { color *= unpressedColor; } if (lp.GetBlock(x, y) == 0 && lp.GetPowerup(x, y) > 0) { label += (label.Length == 0 ? "" : "\n"); label += powerupLabel[lp.GetPowerup(x, y) - 1]; } if (lp.GetBlock(x, y) > 0) { label += (label.Length == 0 ? "" : "\n") + "B:" + lp.GetBlock(x, y).ToString(); } if (lp.GetJelly(x, y) > 0) { label += (label.Length == 0 ? "" : "\n") + "J:" + lp.GetJelly(x, y).ToString(); } } GUI.color = color; btn = GUI.Button(new Rect(r.xMin + x * (30 + slotOffect), r.yMin + y * (30 + slotOffect), 30, 30), label, slotStyle); GUI.color = defaultColor; return(btn); }
public LevelProfile GetClone() { LevelProfile clone = new LevelProfile(); clone.level = level; clone.width = width; clone.height = height; clone.chipCount = chipCount; clone.target = target; clone.firstStarScore = firstStarScore; clone.secondStarScore = secondStarScore; clone.thirdStarScore = thirdStarScore; clone.duraction = duraction; return(clone); }
bool DrawSlotButton(int x, int y, Rect r, LevelProfile lp) { defaultColor = GUI.backgroundColor; Color color = Color.white; string label = ""; bool btn = false; int chip = lp.GetChip(x, y); if (!lp.GetSlot(x, y)) { color *= 0; } GUI.backgroundColor = color; btn = GUI.Button(new Rect(r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect), cellSize, cellSize), label, slotStyle); float cursor = -2; if (lp.GetSlot(x, y) && lp.GetGenerator(x, y)) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + cursor, r.yMin + y * (cellSize + slotOffect) - 2, 10, 10), "G", iconStyle); cursor += 10 + 2; } if (lp.GetSlot(x, y) && lp.GetTeleport(x, y) > 0) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + cursor, r.yMin + y * (cellSize + slotOffect) - 2, cellSize - 12, 10), "T:" + lp.GetTeleport(x, y).ToString(), iconStyle); } if (lp.GetSlot(x, y)) { GUI.backgroundColor = transparentColor; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect) + cellSize - 10, 20, 10), (y * 12 + x + 1).ToString(), slotStyle); } GUI.backgroundColor = defaultColor; return(btn); }
public void InitBalls(LevelProfile level) { if (_gridManager == null) { _gridManager = new GridManager(7, 14, 120, 100); _numberOfInitRow = level.GetInitRow(); _numberOfDiffColor = level.GetNumColor(); } for (int i = 0; i < _gridManager.GetGridSizeX(); i++) { for (int j = 0; j < _numberOfInitRow; j++) { if (_gridManager.IsValidGridPosition(i, j)) { Ball ball = instantiateNewBall(randomBallColor(_numberOfDiffColor + 1)); assignBallToGrid(ball, i, j); ball.FixPosition(); } } } }
public override void OnInspectorGUI() { button = (LevelButton)target; profile = button.profile; if (profile.levelID == 0 || profile.levelID != target.GetInstanceID()) { if (profile.levelID != target.GetInstanceID()) { profile = profile.GetClone(); } profile.levelID = target.GetInstanceID(); } button.name = (button.transform.GetSiblingIndex() + 1).ToString(); parametersFade.target = GUILayout.Toggle(parametersFade.target, "Level Parameters", EditorStyles.foldout); if (EditorGUILayout.BeginFadeGroup(parametersFade.faded)) { profile.width = Mathf.RoundToInt(EditorGUILayout.Slider("Width", 1f * profile.width, 5f, 12f)); profile.height = Mathf.RoundToInt(EditorGUILayout.Slider("Height", 1f * profile.height, 5f, 12f)); profile.chipCount = Mathf.RoundToInt(EditorGUILayout.Slider("Count of Possible Colors", 1f * profile.chipCount, 3f, 6f)); profile.stonePortion = EditorGUILayout.Slider("Stone Portion (" + Mathf.RoundToInt(profile.stonePortion * 100f).ToString() + "%)", profile.stonePortion, 0f, 0.7f); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Score Stars", GUILayout.ExpandWidth(true)); profile.firstStarScore = Mathf.Max(EditorGUILayout.IntField(profile.firstStarScore, GUILayout.ExpandWidth(true)), 1); profile.secondStarScore = Mathf.Max(EditorGUILayout.IntField(profile.secondStarScore, GUILayout.ExpandWidth(true)), profile.firstStarScore + 1); profile.thirdStarScore = Mathf.Max(EditorGUILayout.IntField(profile.thirdStarScore, GUILayout.ExpandWidth(true)), profile.secondStarScore + 1); EditorGUILayout.EndHorizontal(); profile.limitation = (Limitation)EditorGUILayout.EnumPopup("Limitation", profile.limitation); switch (profile.limitation) { case Limitation.Moves: profile.moveCount = Mathf.Clamp(EditorGUILayout.IntField("Move Count", profile.moveCount), 5, 90); break; case Limitation.Time: profile.duraction = Mathf.Max(0, EditorGUILayout.IntField("Session duration", profile.duraction)); break; } profile.target = (FieldTarget)EditorGUILayout.EnumPopup("Target", profile.target); colorModeFade.target = profile.target == FieldTarget.Color; if (EditorGUILayout.BeginFadeGroup(colorModeFade.faded)) { defaultColor = GUI.color; profile.targetColorCount = Mathf.RoundToInt(EditorGUILayout.Slider("Targets Count", profile.targetColorCount, 1, profile.chipCount)); for (int i = 0; i < 6; i++) { GUI.color = chipColor[i]; if (i < profile.targetColorCount) { profile.SetTargetCount(i, Mathf.Clamp(EditorGUILayout.IntField("Color " + alphabet[i].ToString(), profile.GetTargetCount(i)), 1, 999)); } else { profile.SetTargetCount(i, 0); } } GUI.color = defaultColor; } EditorGUILayout.EndFadeGroup(); sugarDropFade.target = profile.target == FieldTarget.SugarDrop; if (EditorGUILayout.BeginFadeGroup(sugarDropFade.faded)) { profile.targetSugarDropsCount = Mathf.RoundToInt(EditorGUILayout.Slider("Sugar Count", profile.targetSugarDropsCount, 1, 20)); } EditorGUILayout.EndFadeGroup(); } EditorGUILayout.EndFadeGroup(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; GUI.color = currentMode == EditMode.Slot ? unpressedColor : defaultColor; if (GUILayout.Button("Slot", EditorStyles.toolbarButton, GUILayout.Width(40))) { currentMode = EditMode.Slot; } GUI.color = currentMode == EditMode.Chip ? unpressedColor : defaultColor; if (GUILayout.Button("Chip", EditorStyles.toolbarButton, GUILayout.Width(40))) { currentMode = EditMode.Chip; } GUI.color = currentMode == EditMode.PowerUp ? unpressedColor : defaultColor; if (GUILayout.Button("PowerUp", EditorStyles.toolbarButton, GUILayout.Width(70))) { currentMode = EditMode.PowerUp; } if (profile.target == FieldTarget.Jelly) { GUI.color = currentMode == EditMode.Jelly ? unpressedColor : defaultColor; if (GUILayout.Button("Jelly", EditorStyles.toolbarButton, GUILayout.Width(50))) { currentMode = EditMode.Jelly; } } GUI.color = currentMode == EditMode.Block ? unpressedColor : defaultColor; if (GUILayout.Button("Block", EditorStyles.toolbarButton, GUILayout.Width(50))) { currentMode = EditMode.Block; } GUI.color = currentMode == EditMode.Wall ? unpressedColor : defaultColor; if (GUILayout.Button("Wall", EditorStyles.toolbarButton, GUILayout.Width(40))) { currentMode = EditMode.Wall; } GUI.color = defaultColor; GUILayout.FlexibleSpace(); if (GUILayout.Button("Reset", EditorStyles.toolbarButton, GUILayout.Width(40))) { profile = new LevelProfile(); } EditorGUILayout.EndVertical(); // Slot modes if (currentMode == EditMode.Slot) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; GUI.color = toolID == "Slots" ? unpressedColor : defaultColor; if (GUILayout.Button("Slots", EditorStyles.toolbarButton, GUILayout.Width(40))) { toolID = "Slots"; } GUI.color = toolID == "Generators" ? unpressedColor : defaultColor; if (GUILayout.Button("Generators", EditorStyles.toolbarButton, GUILayout.Width(70))) { toolID = "Generators"; } GUI.color = toolID == "Teleports" ? unpressedColor : defaultColor; if (GUILayout.Button("Teleports", EditorStyles.toolbarButton, GUILayout.Width(70))) { toolID = "Teleports"; } if (profile.target == FieldTarget.SugarDrop) { GUI.color = toolID == "Sugar Drop" ? unpressedColor : defaultColor; if (GUILayout.Button("Sugar Drop", EditorStyles.toolbarButton, GUILayout.Width(70))) { toolID = "Sugar Drop"; } } GUI.color = defaultColor; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } // Chip modes if (currentMode == EditMode.Chip) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); string key; defaultColor = GUI.color; GUI.color = toolID == "Random" ? unpressedColor : defaultColor; if (GUILayout.Button("Random", EditorStyles.toolbarButton, GUILayout.Width(50))) { toolID = "Random"; } for (int i = 0; i < profile.chipCount; i++) { key = "Color " + alphabet[i]; GUI.color = toolID == key ? unpressedColor * chipColor[i] : defaultColor * chipColor[i]; if (GUILayout.Button(key, EditorStyles.toolbarButton, GUILayout.Width(50))) { toolID = key; } } GUI.color = toolID == "Stone" ? unpressedColor : defaultColor; if (GUILayout.Button("Stone", EditorStyles.toolbarButton, GUILayout.Width(40))) { toolID = "Stone"; } GUI.color = defaultColor; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } // Block modes if (currentMode == EditMode.Block) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; GUI.color = toolID == "Simple Block" ? unpressedColor : defaultColor; if (GUILayout.Button("Simple Block", EditorStyles.toolbarButton, GUILayout.Width(80))) { toolID = "Simple Block"; } GUI.color = toolID == "Weed" ? unpressedColor : defaultColor; if (GUILayout.Button("Weed", EditorStyles.toolbarButton, GUILayout.Width(40))) { toolID = "Weed"; } GUI.color = toolID == "Branch" ? unpressedColor : defaultColor; if (GUILayout.Button("Branch", EditorStyles.toolbarButton, GUILayout.Width(50))) { toolID = "Branch"; } GUI.color = defaultColor; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins); rect = GUILayoutUtility.GetRect(profile.width * (cellSize + slotOffect), profile.height * (cellSize + slotOffect)); rect.x += slotOffect; rect.y += slotOffect; EditorGUILayout.BeginHorizontal(); DrawModeTools(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); switch (currentMode) { case EditMode.Slot: DrawSlot(); break; case EditMode.Chip: DrawChip(); break; case EditMode.PowerUp: DrawPowerUp(); break; case EditMode.Jelly: DrawJelly(); break; case EditMode.Block: DrawBlock(); break; case EditMode.Wall: DrawWall(); break; } button.profile = profile; EditorUtility.SetDirty(button); }
bool DrawSlotButton(int x, int y, Rect r, LevelProfile lp) { defaultColor = GUI.backgroundColor; Color color = Color.white; string label = ""; bool btn = false; int block = lp.GetBlock(x, y); int jelly = lp.GetJelly(x, y); int chip = lp.GetChip(x, y); if (!lp.GetSlot(x, y)) { color *= 0; } else { if (block == 0) { if (chip == 9) { color *= stoneColor; lp.SetPowerup(x, y, 0); } else if (chip > 0) { if (chip > lp.chipCount) { lp.SetChip(x, y, -1); } color *= chipColor[chip - 1]; } } if (block == 5) { if (chip > 0) { if (chip > lp.chipCount) { lp.SetChip(x, y, -1); } color *= chipColor[chip - 1]; } } if (block == 0 && chip == -1 && lp.GetPowerup(x, y) == 0) { color *= unpressedColor; } if (block == 0 && lp.GetPowerup(x, y) > 0) { label += (label.Length == 0 ? "" : "\n"); label += powerupLabel[lp.GetPowerup(x, y) - 1]; } if (block > 0 && block <= 3) { label += (label.Length == 0 ? "" : "\n") + "B:" + block.ToString(); } if (block == 4) { label += (label.Length == 0 ? "" : "\n") + "Weed"; } if (block == 5) { label += (label.Length == 0 ? "" : "\n") + "Brch"; } if (jelly > 0 && lp.target == FieldTarget.Jelly) { label += (label.Length == 0 ? "" : "\n") + "J:" + jelly.ToString(); } } GUI.backgroundColor = color; btn = GUI.Button(new Rect(r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect), cellSize, cellSize), label, slotStyle); float cursor = -2; if (lp.GetSlot(x, y) && lp.GetGenerator(x, y)) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + cursor, r.yMin + y * (cellSize + slotOffect) - 2, 10, 10), "G", iconStyle); cursor += 10 + 2; } if (lp.target == FieldTarget.SugarDrop && lp.GetSlot(x, y) && lp.GetSugarDrop(x, y)) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + cursor, r.yMin + y * (cellSize + slotOffect) - 2, 10, 10), "S", iconStyle); cursor += 10 + 2; } if (lp.GetSlot(x, y) && lp.GetTeleport(x, y) > 0) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + cursor, r.yMin + y * (cellSize + slotOffect) - 2, cellSize - 12, 10), "T:" + lp.GetTeleport(x, y).ToString(), iconStyle); } if (lp.GetSlot(x, y)) { GUI.backgroundColor = transparentColor; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect) + cellSize - 10, 20, 10), (y * 12 + x + 1).ToString(), slotStyle); } GUI.backgroundColor = defaultColor; return(btn); }
bool DrawSlotButtonTeleport(int x, int y, Rect r, LevelProfile lp) { if (!lp.GetSlot(x, y)) return false; defaultColor = GUI.backgroundColor; Color color = Color.cyan; if (teleportID.x == x && teleportID.y == y) color = Color.magenta; if (lp.GetTeleport(Mathf.FloorToInt(teleportID.x), Mathf.FloorToInt(teleportID.y)) == 12 * y + x + 1) color = Color.yellow; string label = ""; bool btn = false; GUI.backgroundColor = color; btn = GUI.Button (new Rect (r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect), cellSize, cellSize), label, slotStyle); if (lp.GetSlot(x, y) && lp.GetGenerator (x, y)) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) - 2, r.yMin + y * (cellSize + slotOffect) - 2, 10, 10), "G", iconStyle); } if (lp.GetSlot(x, y) && lp.GetTeleport (x, y) > 0) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + 10, r.yMin + y * (cellSize + slotOffect) - 2, cellSize - 12, 10), "T:" + lp.GetTeleport (x, y).ToString(), iconStyle); } if (lp.GetSlot (x, y)) { GUI.backgroundColor = transparentColor; GUI.Box (new Rect (r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect) + cellSize - 10, 20, 10), (y * 12 + x + 1).ToString (), slotStyle); } GUI.backgroundColor = defaultColor; return btn; }
bool DrawSlotButton(int x, int y, Rect r, LevelProfile lp) { defaultColor = GUI.backgroundColor; Color color = Color.white; string label = ""; bool btn = false; int block = lp.GetBlock (x, y); int jelly = lp.GetJelly (x, y); int chip = lp.GetChip (x, y); if (!lp.GetSlot(x, y)) color *= 0; else { if (block == 0) { if (chip == 9) { color *= buttonColor; lp.SetPowerup(x, y, 0); } else if (chip > 0) { if (chip > lp.chipCount) lp.SetChip(x, y, -1); color *= chipColor[chip - 1]; } } if (block == 5) { if (chip > 0) { if (chip > lp.chipCount) lp.SetChip(x, y, -1); color *= chipColor[chip - 1]; } } if (block == 0 && chip == -1 && lp.GetPowerup(x, y) == 0) { color *= unpressedColor; } if (block == 0 && lp.GetPowerup(x, y) > 0) { label += (label.Length == 0 ? "" : "\n"); label += powerupLabel[lp.GetPowerup(x, y)]; } if (block > 0 && block <= 3) label += (label.Length == 0 ? "" : "\n") + "B:" + block.ToString(); if (block == 4) label += (label.Length == 0 ? "" : "\n") + "Weed"; if (block == 5) label += (label.Length == 0 ? "" : "\n") + "Brch"; if (jelly > 0 && lp.target == FieldTarget.Jelly) { label += (label.Length == 0 ? "" : "\n"); switch (jelly) { case 1: label += "JS"; break; case 2: label += "JT"; break; } } } GUI.backgroundColor = color; btn = GUI.Button(new Rect(r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect), cellSize, cellSize), label, slotStyle); float cursor = -2; if (lp.GetSlot(x, y) && lp.GetGenerator (x, y)) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + cursor, r.yMin + y * (cellSize + slotOffect) - 2, 10, 10), "G", iconStyle); cursor += 10 + 2; } if (lp.target == FieldTarget.SugarDrop && lp.GetSlot(x, y) && lp.GetSugarDrop(x, y)) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + cursor, r.yMin + y * (cellSize + slotOffect) - 2, 10, 10), "S", iconStyle); cursor += 10 + 2; } if (lp.GetSlot(x, y)) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + cursor, r.yMin + y * (cellSize + slotOffect) - 2, 10, 10), gravityLabel[profile.GetGravity(x, y)], iconStyle); cursor += 10 + 2; } if (lp.GetSlot(x, y) && lp.GetTeleport (x, y) > 0) { GUI.backgroundColor = Color.black; GUI.Box(new Rect(r.xMin + x * (cellSize + slotOffect) + cursor, r.yMin + y * (cellSize + slotOffect) - 2, cellSize - 12, 10), "T:" + lp.GetTeleport (x, y).ToString(), iconStyle); } if (lp.GetSlot (x, y)) { GUI.backgroundColor = transparentColor; GUI.Box (new Rect (r.xMin + x * (cellSize + slotOffect), r.yMin + y * (cellSize + slotOffect) + cellSize - 10, 20, 10), (y * 12 + x + 1).ToString (), slotStyle); } GUI.backgroundColor = defaultColor; return btn; }
public override void OnInspectorGUI() { if (!metaTarget) { return; } level = (Level)metaTarget; if (!level) { EditorGUILayout.HelpBox("No level selected", MessageType.Info); return; } if (level.profile == null) { level.profile = new LevelProfile(); } profile = level.profile; #region Temporary arrays slots = profile.slots.ToDictionary(x => x.position, x => x); chipInfos = SessionAssistant.main.chipInfos.ToDictionary(x => x.name, x => x); blockInfos = SessionAssistant.main.blockInfos.ToDictionary(x => x.name, x => x); #endregion if (profile.levelID == 0) { profile = new LevelProfile(); profile.levelID = level.gameObject.GetInstanceID(); ResetField(); } if (profile.levelID != level.gameObject.GetInstanceID()) { if (profile.levelID != level.gameObject.GetInstanceID()) { profile = profile.GetClone(); } profile.levelID = level.gameObject.GetInstanceID(); } Undo.RecordObject(level, "Level design changed"); #region Level parameters GUILayout.Label("Level Parameters", EditorStyles.centeredGreyMiniLabel, GUILayout.ExpandWidth(true)); profile.level = level.transform.GetSiblingIndex() + 1; EditorGUILayout.BeginVertical(EditorStyles.textArea); #region Navigation Panel EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("<<", EditorStyles.miniButtonLeft, GUILayout.Width(30))) { SelectLevel(1); return; } if (GUILayout.Button("<", EditorStyles.miniButtonMid, GUILayout.Width(30))) { SelectLevel(profile.level - 1); return; } GUILayout.Label("Level #" + profile.level, EditorStyles.miniButtonMid, GUILayout.Width(70)); if (GUILayout.Button(">", EditorStyles.miniButtonMid, GUILayout.Width(30))) { SelectLevel(profile.level + 1); return; } if (GUILayout.Button(">>", EditorStyles.miniButtonRight, GUILayout.Width(30))) { SelectLevel(Level.all.Count); return; } EditorGUILayout.EndHorizontal(); #endregion profile.width = Mathf.RoundToInt(EditorGUILayout.Slider("Width", 1f * profile.width, 5f, LevelProfile.maxSize)); profile.height = Mathf.RoundToInt(EditorGUILayout.Slider("Height", 1f * profile.height, 5f, LevelProfile.maxSize)); profile.colorCount = Mathf.RoundToInt(EditorGUILayout.Slider("Count of Possible Colors", 1f * profile.colorCount, 3f, chipColor.Length)); #region Stars EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Score Stars", GUILayout.ExpandWidth(true)); profile.firstStarScore = Mathf.Max(EditorGUILayout.IntField(profile.firstStarScore, GUILayout.ExpandWidth(true)), 1); profile.secondStarScore = Mathf.Max(EditorGUILayout.IntField(profile.secondStarScore, GUILayout.ExpandWidth(true)), profile.firstStarScore + 1); profile.thirdStarScore = Mathf.Max(EditorGUILayout.IntField(profile.thirdStarScore, GUILayout.ExpandWidth(true)), profile.secondStarScore + 1); EditorGUILayout.EndHorizontal(); #endregion #region Limitation profile.limit = Mathf.RoundToInt(EditorGUILayout.Slider("Move Count", profile.limit, 5, 100)); #endregion EditorGUILayout.Space(); EditorGUILayout.EndVertical(); #endregion UpdateName(level); #region Slot parameters GUILayout.Label("Slot Parameters", EditorStyles.centeredGreyMiniLabel, GUILayout.ExpandWidth(true)); EditorGUILayout.BeginHorizontal(); DrawSlotSettings(); EditorGUILayout.EndHorizontal(); #endregion GUILayout.Label("Level Layout", EditorStyles.centeredGreyMiniLabel, GUILayout.ExpandWidth(true)); DrawActionBar(); defaultColor = GUI.backgroundColor; GUI.backgroundColor = Color.gray; EditorGUILayout.BeginHorizontal(EditorStyles.textArea, GUILayout.MinWidth(10)); GUI.backgroundColor = defaultColor; rect = GUILayoutUtility.GetRect( profile.width * (cellSize + slotOffset) + legendSize + EditorStyles.textArea.margin.left + EditorStyles.textArea.margin.right, profile.height * (cellSize + slotOffset) + legendSize + EditorStyles.textArea.margin.top + EditorStyles.textArea.margin.bottom); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); DrawFieldView(); profile.slots = slots.Values.Where(x => x.position.IsItHit(0, 0, profile.width - 1, profile.height - 1)).ToList(); level.profile = profile; }
public static void DrawWallPreview(Rect r, LevelProfile lp) { int x; int y; GUI.enabled = false; for (x = 0; x < lp.width-1; x++) for (y = 0; y < lp.height; y++) if (lp.GetWallV(x,y) && lp.GetSlot(x,y) && lp.GetSlot(x+1,y)) DrawWallButton(x, y, "V", r, lp); for (x = 0; x < lp.width; x++) for (y = 0; y < lp.height-1; y++) if (lp.GetWallH(x,y) && lp.GetSlot(x,y) && lp.GetSlot(x,y+1)) DrawWallButton(x, y, "H", r, lp); GUI.enabled = true; }
public override void OnInspectorGUI() { design = (LevelDesign)target; profile = design.profile; if (profile.levelId == 0 || profile.levelId != target.GetInstanceID()) { if (profile.levelId != target.GetInstanceID()) { profile = profile.GetClone(); } profile.levelId = target.GetInstanceID(); } design.name = (design.transform.GetSiblingIndex() + 1).ToString(); parametersFade.target = GUILayout.Toggle(parametersFade.target, "Level Parameters", EditorStyles.foldout); if (EditorGUILayout.BeginFadeGroup(parametersFade.faded)) { profile.width = Mathf.RoundToInt(EditorGUILayout.Slider("Width", 1f * profile.width, 5f, 12f)); profile.height = Mathf.RoundToInt(EditorGUILayout.Slider("Height", 1f * profile.height, 5f, 12f)); profile.chipCount = Mathf.RoundToInt(EditorGUILayout.Slider("Count of Possible Colors", 1f * profile.chipCount, 3f, 6f)); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Score Stars", GUILayout.ExpandWidth(true)); profile.firstStarScore = Mathf.Max(EditorGUILayout.IntField(profile.firstStarScore, GUILayout.ExpandWidth(true)), 1); profile.secondStarScore = Mathf.Max(EditorGUILayout.IntField(profile.secondStarScore, GUILayout.ExpandWidth(true)), profile.firstStarScore + 1); profile.thirdStarScore = Mathf.Max(EditorGUILayout.IntField(profile.thirdStarScore, GUILayout.ExpandWidth(true)), profile.secondStarScore + 1); EditorGUILayout.EndHorizontal(); profile.limitation = (Limitation)EditorGUILayout.EnumPopup("Limitation", profile.limitation); switch (profile.limitation) { case Limitation.Time: profile.duraction = Mathf.Max(0, EditorGUILayout.IntField("Session duration", profile.duraction)); break; } profile.target = (FieldTarget)EditorGUILayout.EnumPopup("Target", profile.target); EditorGUILayout.EndFadeGroup(); } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; GUI.color = currentMode == EditMode.Slot ? unpressedColor : defaultColor; if (GUILayout.Button("Slot", EditorStyles.toolbarButton, GUILayout.Width(40))) { currentMode = EditMode.Slot; } GUI.color = currentMode == EditMode.Chip ? unpressedColor : defaultColor; if (GUILayout.Button("Chip", EditorStyles.toolbarButton, GUILayout.Width(40))) { currentMode = EditMode.Chip; } GUI.color = currentMode == EditMode.PowerUp ? unpressedColor : defaultColor; if (GUILayout.Button("PowerUp", EditorStyles.toolbarButton, GUILayout.Width(70))) { currentMode = EditMode.PowerUp; } GUI.color = defaultColor; GUILayout.FlexibleSpace(); if (GUILayout.Button("Reset", EditorStyles.toolbarButton, GUILayout.Width(40))) { profile = new LevelProfile(); } EditorGUILayout.EndVertical(); // Slot modes if (currentMode == EditMode.Slot) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; GUI.color = toolID == "Slots" ? unpressedColor : defaultColor; if (GUILayout.Button("Slots", EditorStyles.toolbarButton, GUILayout.Width(40))) { toolID = "Slots"; } GUI.color = toolID == "Generators" ? unpressedColor : defaultColor; if (GUILayout.Button("Generators", EditorStyles.toolbarButton, GUILayout.Width(70))) { toolID = "Generators"; } GUI.color = toolID == "Teleports" ? unpressedColor : defaultColor; if (GUILayout.Button("Teleports", EditorStyles.toolbarButton, GUILayout.Width(70))) { toolID = "Teleports"; } GUI.color = defaultColor; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } // Chip modes if (currentMode == EditMode.Chip) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); string key; defaultColor = GUI.color; GUI.color = toolID == "Random" ? unpressedColor : defaultColor; if (GUILayout.Button("Random", EditorStyles.toolbarButton, GUILayout.Width(50))) { toolID = "Random"; } for (int i = 0; i < profile.chipCount; i++) { key = "Color " + alphabet[i]; GUI.color = toolID == key ? unpressedColor * chipColor[i] : defaultColor * chipColor[i]; if (GUILayout.Button(key, EditorStyles.toolbarButton, GUILayout.Width(50))) { toolID = key; } } GUI.color = toolID == "Stone" ? unpressedColor : defaultColor; if (GUILayout.Button("Stone", EditorStyles.toolbarButton, GUILayout.Width(40))) { toolID = "Stone"; } GUI.color = defaultColor; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins); rect = GUILayoutUtility.GetRect(profile.width * (cellSize + slotOffect), profile.height * (cellSize + slotOffect)); rect.x += slotOffect; rect.y += slotOffect; EditorGUILayout.BeginHorizontal(); DrawModeTools(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); switch (currentMode) { case EditMode.Slot: DrawSlot(); break; // case EditMode.Chip: DrawChip(); break; // case EditMode.PowerUp: DrawPowerUp(); break; } design.profile = profile; EditorUtility.SetDirty(design); }
internal void AddLevelProfiles(string p_levels) { System.Text.RegularExpressions.Regex rx_level = new System.Text.RegularExpressions.Regex(@"^(?<level>[0-9]+)(?<role>[a-z])"); string[] levels = p_levels.Split(' '); for (int v = 0; v < levels.Length; v++) { string currLP = levels[v]; if (rx_level.IsMatch(currLP) == true) { LevelProfile createLP = new LevelProfile(); System.Text.RegularExpressions.Match myMatch = rx_level.Match(currLP); int.TryParse(myMatch.Groups["level"].Value, out createLP.Level); string role = myMatch.Groups["role"].Value; createLP.Class = role.ToUpper(); /* switch (role) { case "u": createLP.Class = "Lurker"; break; case "k": createLP.Class = "Skirmisher"; break; case "b": createLP.Class = "Brute"; break; case "s": createLP.Class = "Soldier"; break; case "a": createLP.Class = "Artillery"; break; case "c": createLP.Class = "Controller"; break; default: createLP.Class = "ERROR"; break; } */ this.Levels.Add(createLP); } } }
static bool DrawWallButton(int x, int y, string t, Rect r, LevelProfile lp) { bool btn = false; if (t == "H") btn = lp.GetWallH(x,y); if (t == "V") btn = lp.GetWallV(x,y); defaultColor = GUI.color; Color color = defaultColor; if (btn) color *= Color.red; GUI.color = color; if (t == "V") btn = GUI.Button(new Rect(r.xMin + (x + 1) * (cellSize + slotOffect) - 4 - slotOffect / 2, r.yMin + y * (cellSize + slotOffect) - 10 + 20, 8, 20), "", slotStyle); if (t == "H") btn = GUI.Button(new Rect(r.xMin + x * (cellSize + slotOffect) - 10 + 20, r.yMin + (y + 1) * (cellSize + slotOffect) - 4 - slotOffect / 2, 20, 8), "", slotStyle); GUI.color = defaultColor; return btn; }
public void DrawSlotPreview(Rect r, LevelProfile lp) { int x; int y; GUI.enabled = false; for (x = 0; x < lp.width; x++) for (y = 0; y < lp.height; y++) if (lp.GetSlot(x, y)) DrawSlotButton(x, y, r, lp); GUI.enabled = true; }
public override void OnInspectorGUI() { if (!metaTarget) { return; } level = (Level)metaTarget; if (!level) { EditorGUILayout.HelpBox("No level selected", MessageType.Info); return; } if (level.profile == null) { level.profile = new LevelProfile(); } profile = level.profile; #region Temporary arrays slots = profile.slots.ToDictionary(x => x.position, x => x); chipInfos = SessionAssistant.main.chipInfos.ToDictionary(x => x.name, x => x); blockInfos = SessionAssistant.main.blockInfos.ToDictionary(x => x.name, x => x); teleportTargets.Clear(); foreach (int2 coord in selected) { if (slots.ContainsKey(coord) && !teleportTargets.Contains(slots[coord].teleport)) { teleportTargets.Add(slots[coord].teleport); } } #endregion if (profile.levelID == 0) { profile = new LevelProfile(); profile.levelID = level.gameObject.GetInstanceID(); ResetField(); } if (profile.levelID != level.gameObject.GetInstanceID()) { if (profile.levelID != level.gameObject.GetInstanceID()) { profile = profile.GetClone(); } profile.levelID = level.gameObject.GetInstanceID(); } Undo.RecordObject(level, "Level design changed"); #region Level parameters GUILayout.Label("Level Parameters", EditorStyles.centeredGreyMiniLabel, GUILayout.ExpandWidth(true)); profile.level = level.transform.GetSiblingIndex() + 1; EditorGUILayout.BeginVertical(EditorStyles.textArea); #region Navigation Panel EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("<<", EditorStyles.miniButtonLeft, GUILayout.Width(30))) { SelectLevel(1); return; } if (GUILayout.Button("<", EditorStyles.miniButtonMid, GUILayout.Width(30))) { SelectLevel(profile.level - 1); return; } GUILayout.Label("Level #" + profile.level, EditorStyles.miniButtonMid, GUILayout.Width(70)); if (GUILayout.Button(">", EditorStyles.miniButtonMid, GUILayout.Width(30))) { SelectLevel(profile.level + 1); return; } if (GUILayout.Button(">>", EditorStyles.miniButtonRight, GUILayout.Width(30))) { SelectLevel(Level.all.Count); return; } EditorGUILayout.EndHorizontal(); #endregion profile.width = Mathf.RoundToInt(EditorGUILayout.Slider("Width", 1f * profile.width, 5f, LevelProfile.maxSize)); profile.height = Mathf.RoundToInt(EditorGUILayout.Slider("Height", 1f * profile.height, 5f, LevelProfile.maxSize)); profile.colorCount = Mathf.RoundToInt(EditorGUILayout.Slider("Count of Possible Colors", 1f * profile.colorCount, 3f, chipColor.Length)); profile.stonePortion = Mathf.Round(EditorGUILayout.Slider("Stone Portion", profile.stonePortion, 0f, 0.7f) * 100) / 100; #region Stars EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Score Stars", GUILayout.ExpandWidth(true)); profile.firstStarScore = Mathf.Max(EditorGUILayout.IntField(profile.firstStarScore, GUILayout.ExpandWidth(true)), 1); profile.secondStarScore = Mathf.Max(EditorGUILayout.IntField(profile.secondStarScore, GUILayout.ExpandWidth(true)), profile.firstStarScore + 1); profile.thirdStarScore = Mathf.Max(EditorGUILayout.IntField(profile.thirdStarScore, GUILayout.ExpandWidth(true)), profile.secondStarScore + 1); EditorGUILayout.EndHorizontal(); #endregion #region Limitation Enum limitation = EditorGUILayout.EnumPopup("Limitation", profile.limitation); if (profile.limitation != (Limitation)limitation) { profile.limit = 30; } profile.limitation = (Limitation)limitation; switch (profile.limitation) { case Limitation.Moves: profile.limit = Mathf.RoundToInt(EditorGUILayout.Slider("Move Count", profile.limit, 5, 100)); break; case Limitation.Time: profile.limit = Mathf.RoundToInt(EditorGUILayout.Slider("Session duration (" + Utils.ToTimerFormat(profile.limit) + ")", Mathf.Ceil(profile.limit / 5) * 5, 5, 300)); break; } #endregion #region Target profile.target = (FieldTarget)EditorGUILayout.EnumPopup("Target", profile.target); if (profile.target == FieldTarget.Color) { defaultColor = GUI.color; profile.targetColorCount = Mathf.RoundToInt(EditorGUILayout.Slider("Targets Count", profile.targetColorCount, 1, profile.colorCount)); for (int i = 0; i < chipColor.Length; i++) { GUI.color = chipColor[i]; if (i < profile.targetColorCount) { profile.SetTargetCount(i, Mathf.Clamp(EditorGUILayout.IntField("Color " + alphabet[i].ToString(), profile.GetTargetCount(i)), 1, 999)); } else { profile.SetTargetCount(i, 0); } } GUI.color = defaultColor; } if (profile.target == FieldTarget.SugarDrop) { profile.targetSugarDropsCount = Mathf.RoundToInt(EditorGUILayout.Slider("Sugar Count", profile.targetSugarDropsCount, 1, 20)); } #endregion EditorGUILayout.Space(); EditorGUILayout.EndVertical(); #endregion UpdateName(level); #region Slot parameters GUILayout.Label("Slot Parameters", EditorStyles.centeredGreyMiniLabel, GUILayout.ExpandWidth(true)); EditorGUILayout.BeginHorizontal(); DrawSlotSettings(); DrawLayersSettings(); EditorGUILayout.EndHorizontal(); #endregion GUILayout.Label("Level Layout", EditorStyles.centeredGreyMiniLabel, GUILayout.ExpandWidth(true)); DrawActionBar(); defaultColor = GUI.backgroundColor; GUI.backgroundColor = Color.gray; EditorGUILayout.BeginHorizontal(EditorStyles.textArea, GUILayout.MinWidth(10)); GUI.backgroundColor = defaultColor; rect = GUILayoutUtility.GetRect( profile.width * (cellSize + slotOffset) + legendSize + EditorStyles.textArea.margin.left + EditorStyles.textArea.margin.right, profile.height * (cellSize + slotOffset) + legendSize + EditorStyles.textArea.margin.top + EditorStyles.textArea.margin.bottom); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); DrawFieldView(); profile.slots = slots.Values.Where(x => x.position.IsItHit(0, 0, profile.width - 1, profile.height - 1)).ToList(); level.profile = profile; }
public override void OnInspectorGUI() { button = (LevelButton)target; profile = button.profile; if (profile.levelID == 0 || profile.levelID != target.GetInstanceID()) { if (profile.levelID != target.GetInstanceID()) { profile = profile.GetClone(); } profile.levelID = target.GetInstanceID(); } button.name = (button.transform.GetSiblingIndex() + 1).ToString(); profile.width = Mathf.RoundToInt(EditorGUILayout.Slider("Width", 1f * profile.width, 5f, 12f)); profile.height = Mathf.RoundToInt(EditorGUILayout.Slider("Height", 1f * profile.height, 5f, 12f)); profile.chipCount = Mathf.RoundToInt(EditorGUILayout.Slider("Chip Count", 1f * profile.chipCount, 3f, 6f)); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Score Stars", GUILayout.Width(150)); profile.firstStarScore = Mathf.Max(EditorGUILayout.IntField(profile.firstStarScore, GUILayout.Width(90)), 1); profile.secondStarScore = Mathf.Max(EditorGUILayout.IntField(profile.secondStarScore, GUILayout.Width(90)), profile.firstStarScore + 1); profile.thirdStarScore = Mathf.Max(EditorGUILayout.IntField(profile.thirdStarScore, GUILayout.ExpandWidth(true)), profile.secondStarScore + 1); EditorGUILayout.EndHorizontal(); profile.target = (FieldTarget)EditorGUILayout.EnumPopup("Target", profile.target); if (profile.target == FieldTarget.Timer) { profile.duraction = Mathf.Max(0, EditorGUILayout.IntField("Session duration", profile.duraction)); } else { profile.moveCount = Mathf.Clamp(EditorGUILayout.IntField("Move Count", profile.moveCount), 10, 50); } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; GUI.color = currentMode == EditMode.Slot ? unpressedColor : defaultColor; if (GUILayout.Button("Slot", EditorStyles.toolbarButton, GUILayout.Width(40))) { currentMode = EditMode.Slot; } GUI.color = currentMode == EditMode.Chip ? unpressedColor : defaultColor; if (GUILayout.Button("Chip", EditorStyles.toolbarButton, GUILayout.Width(40))) { currentMode = EditMode.Chip; } GUI.color = currentMode == EditMode.PowerUp ? unpressedColor : defaultColor; if (GUILayout.Button("PowerUp", EditorStyles.toolbarButton, GUILayout.Width(70))) { currentMode = EditMode.PowerUp; } GUI.color = currentMode == EditMode.Jelly ? unpressedColor : defaultColor; if (GUILayout.Button("Jelly", EditorStyles.toolbarButton, GUILayout.Width(50))) { currentMode = EditMode.Jelly; } GUI.color = currentMode == EditMode.Block ? unpressedColor : defaultColor; if (GUILayout.Button("Block", EditorStyles.toolbarButton, GUILayout.Width(50))) { currentMode = EditMode.Block; } GUI.color = currentMode == EditMode.Wall ? unpressedColor : defaultColor; if (GUILayout.Button("Wall", EditorStyles.toolbarButton, GUILayout.Width(40))) { currentMode = EditMode.Wall; } GUI.color = defaultColor; GUILayout.FlexibleSpace(); EditorGUILayout.EndVertical(); rect = GUILayoutUtility.GetRect(profile.width * (30 + slotOffect), profile.height * (30 + slotOffect)); rect.x += slotOffect; rect.y += slotOffect; switch (currentMode) { case EditMode.Slot: DrawSlot(); break; case EditMode.Chip: DrawChip(); break; case EditMode.PowerUp: DrawPowerUp(); break; case EditMode.Jelly: DrawJelly(); break; case EditMode.Block: DrawBlock(); break; case EditMode.Wall: DrawWall(); break; } EditorGUILayout.LabelField(help, helpStyle); EditorGUILayout.BeginHorizontal(); DrawModeTools(); EditorGUILayout.EndHorizontal(); button.profile = profile; EditorUtility.SetDirty(button); }
public override void OnInspectorGUI() { level = (Level)target; Undo.RecordObject (level, ""); profile = level.profile; if (profile == null) profile = new LevelProfile(); if (SessionAssistant.main == null) SessionAssistant.main = GameObject.FindObjectOfType<SessionAssistant>(); if (profile.levelID == 0 || profile.levelID != target.GetInstanceID ()) { if (profile.levelID != target.GetInstanceID ()) profile = profile.GetClone(); profile.levelID = target.GetInstanceID (); } profile.level = level.transform.GetSiblingIndex() + 1; level.name = "Level:" + profile.level.ToString() + "," + profile.target + "," + profile.limitation; parametersFade.target = GUILayout.Toggle(parametersFade.target, "Level Parameters", EditorStyles.foldout); if (EditorGUILayout.BeginFadeGroup (parametersFade.faded)) { profile.width = Mathf.RoundToInt (EditorGUILayout.Slider ("Width", 1f * profile.width, 5f, 12f)); profile.height = Mathf.RoundToInt (EditorGUILayout.Slider ("Height", 1f * profile.height, 5f, 12f)); profile.chipCount = Mathf.RoundToInt (EditorGUILayout.Slider ("Count of Possible Colors", 1f * profile.chipCount, 3f, 6f)); profile.buttonPortion = Mathf.Round(EditorGUILayout.Slider ( "Button Portion", profile.buttonPortion, 0f, 0.7f) * 100) / 100; EditorGUILayout.BeginHorizontal (); EditorGUILayout.LabelField ("Score Stars", GUILayout.ExpandWidth(true)); profile.firstStarScore = Mathf.Max(EditorGUILayout.IntField (profile.firstStarScore, GUILayout.ExpandWidth(true)), 1); profile.secondStarScore = Mathf.Max(EditorGUILayout.IntField (profile.secondStarScore, GUILayout.ExpandWidth(true)), profile.firstStarScore+1); profile.thirdStarScore = Mathf.Max(EditorGUILayout.IntField (profile.thirdStarScore, GUILayout.ExpandWidth(true)), profile.secondStarScore+1); EditorGUILayout.EndHorizontal (); profile.limitation = (Limitation) EditorGUILayout.EnumPopup ("Limitation", profile.limitation); switch (profile.limitation) { case Limitation.Moves: profile.moveCount = Mathf.Clamp(EditorGUILayout.IntField("Move Count", profile.moveCount), 5, 50); break; case Limitation.Time: profile.duration = Mathf.Max(0, EditorGUILayout.IntField("Session duration", profile.duration)); break; } profile.target = (FieldTarget) EditorGUILayout.EnumPopup ("Target", profile.target); colorModeFade.target = profile.target == FieldTarget.Color; if (EditorGUILayout.BeginFadeGroup (colorModeFade.faded)) { defaultColor = GUI.color; profile.targetColorCount = Mathf.RoundToInt(EditorGUILayout.Slider("Targets Count", profile.targetColorCount, 1, profile.chipCount)); for (int i = 0; i < 6; i++) { GUI.color = chipColor[i]; if (i < profile.targetColorCount) profile.SetTargetCount(i, Mathf.Clamp(EditorGUILayout.IntField("Color " + alphabet[i].ToString(), profile.GetTargetCount(i)), 1, 999)); else profile.SetTargetCount(i, 0); } GUI.color = defaultColor; } EditorGUILayout.EndFadeGroup (); sugarDropFade.target = profile.target == FieldTarget.SugarDrop; if (EditorGUILayout.BeginFadeGroup(sugarDropFade.faded)) { profile.targetSugarDropsCount = Mathf.RoundToInt(EditorGUILayout.Slider("Sugar Count", profile.targetSugarDropsCount, 1, 20)); } EditorGUILayout.EndFadeGroup(); } EditorGUILayout.EndFadeGroup (); EditorGUILayout.Space (); EditorGUILayout.BeginHorizontal (EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; GUI.color = currentMode == EditMode.Slot ? unpressedColor : defaultColor; if (GUILayout.Button("Slot", EditorStyles.toolbarButton, GUILayout.Width(40))) currentMode = EditMode.Slot; GUI.color = currentMode == EditMode.Chip ? unpressedColor : defaultColor; if (GUILayout.Button("Chip", EditorStyles.toolbarButton, GUILayout.Width(40))) currentMode = EditMode.Chip; GUI.color = currentMode == EditMode.PowerUp ? unpressedColor : defaultColor; if (GUILayout.Button("PowerUp", EditorStyles.toolbarButton, GUILayout.Width(70))) currentMode = EditMode.PowerUp; if (profile.target == FieldTarget.Jelly) { GUI.color = currentMode == EditMode.Jelly ? unpressedColor : defaultColor; if (GUILayout.Button("Jelly", EditorStyles.toolbarButton, GUILayout.Width(50))) currentMode = EditMode.Jelly; } GUI.color = currentMode == EditMode.Block ? unpressedColor : defaultColor; if (GUILayout.Button("Block", EditorStyles.toolbarButton, GUILayout.Width(50))) currentMode = EditMode.Block; GUI.color = currentMode == EditMode.Wall ? unpressedColor : defaultColor; if (GUILayout.Button("Wall", EditorStyles.toolbarButton, GUILayout.Width(40))) currentMode = EditMode.Wall; GUI.color = defaultColor; GUILayout.FlexibleSpace (); if (GUILayout.Button("Reset", EditorStyles.toolbarButton, GUILayout.Width(40))) profile = new LevelProfile (); EditorGUILayout.EndVertical (); // Slot modes if (currentMode == EditMode.Slot) { EditorGUILayout.BeginHorizontal (EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; GUI.color = toolID == "Slots" ? unpressedColor : defaultColor; if (GUILayout.Button("Slots", EditorStyles.toolbarButton, GUILayout.Width(40))) toolID = "Slots"; GUI.color = toolID == "Generators" ? unpressedColor : defaultColor; if (GUILayout.Button("Generators", EditorStyles.toolbarButton, GUILayout.Width(70))) toolID = "Generators"; GUI.color = toolID == "Teleports" ? unpressedColor : defaultColor; if (GUILayout.Button("Teleports", EditorStyles.toolbarButton, GUILayout.Width(70))) toolID = "Teleports"; if (profile.target == FieldTarget.SugarDrop) { GUI.color = toolID == "Sugar Drop" ? unpressedColor : defaultColor; if (GUILayout.Button("Sugar Drop", EditorStyles.toolbarButton, GUILayout.Width(70))) toolID = "Sugar Drop"; } GUI.color = toolID == "Gravity" ? unpressedColor : defaultColor; if (GUILayout.Button("Gravity", EditorStyles.toolbarButton, GUILayout.Width(50))) toolID = "Gravity"; GUI.color = defaultColor; GUILayout.FlexibleSpace (); EditorGUILayout.EndHorizontal (); } // Slot modes if (currentMode == EditMode.PowerUp) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; if (SessionAssistant.main) { foreach (SessionAssistant.PowerUps powerup in SessionAssistant.main.powerups) { if (powerup.levelEditorID > 0) { GUI.color = toolID == powerup.levelEditorName ? unpressedColor : defaultColor; if (GUILayout.Button(powerup.levelEditorName, EditorStyles.toolbarButton, GUILayout.Width(30))) toolID = powerup.levelEditorName; } } } GUI.color = defaultColor; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } // Chip modes if (currentMode == EditMode.Chip) { EditorGUILayout.BeginHorizontal (EditorStyles.toolbar, GUILayout.ExpandWidth(true)); string key; defaultColor = GUI.color; GUI.color = toolID == "Random" ? unpressedColor : defaultColor; if (GUILayout.Button("Random", EditorStyles.toolbarButton, GUILayout.Width(50))) toolID = "Random"; for (int i = 0; i < profile.chipCount; i++) { key = "Color " + alphabet[i]; GUI.color = toolID == key ? unpressedColor * chipColor[i] : defaultColor * chipColor[i]; if (GUILayout.Button(key, EditorStyles.toolbarButton, GUILayout.Width(50))) toolID = key; } GUI.color = toolID == "Button" ? unpressedColor : defaultColor; if (GUILayout.Button("Button", EditorStyles.toolbarButton, GUILayout.Width(50))) toolID = "Button"; GUI.color = defaultColor; GUILayout.FlexibleSpace (); EditorGUILayout.EndHorizontal (); } // Block modes if (currentMode == EditMode.Block) { EditorGUILayout.BeginHorizontal (EditorStyles.toolbar, GUILayout.ExpandWidth(true)); defaultColor = GUI.color; GUI.color = toolID == "Simple Block" ? unpressedColor : defaultColor; if (GUILayout.Button("Simple Block", EditorStyles.toolbarButton, GUILayout.Width(80))) toolID = "Simple Block"; GUI.color = toolID == "Weed" ? unpressedColor : defaultColor; if (GUILayout.Button("Weed", EditorStyles.toolbarButton, GUILayout.Width(40))) toolID = "Weed"; GUI.color = toolID == "Branch" ? unpressedColor : defaultColor; if (GUILayout.Button("Branch", EditorStyles.toolbarButton, GUILayout.Width(50))) toolID = "Branch"; GUI.color = defaultColor; GUILayout.FlexibleSpace (); EditorGUILayout.EndHorizontal (); } EditorGUILayout.BeginVertical (EditorStyles.inspectorDefaultMargins); rect = GUILayoutUtility.GetRect (profile.width * (cellSize + slotOffect), profile.height * (cellSize + slotOffect)); rect.x += slotOffect; rect.y += slotOffect; EditorGUILayout.BeginHorizontal (); DrawModeTools (); EditorGUILayout.EndHorizontal (); EditorGUILayout.EndVertical (); if (SessionAssistant.main) { powerupLabel.Clear(); foreach (SessionAssistant.PowerUps powerup in SessionAssistant.main.powerups) if (powerup.levelEditorID > 0) if (!powerupLabel.ContainsKey(powerup.levelEditorID)) powerupLabel.Add(powerup.levelEditorID, powerup.levelEditorName); } switch (currentMode) { case EditMode.Slot: DrawSlot(); break; case EditMode.Chip: DrawChip(); break; case EditMode.PowerUp: DrawPowerUp(); break; case EditMode.Jelly: DrawJelly(); break; case EditMode.Block: DrawBlock(); break; case EditMode.Wall: DrawWall(); break; } level.profile = profile; }