private void OnLoad(lib.Event e) { if (levelTxt.text == "") { EditorTip.Show("未输入关卡"); return; } LevelConfig level = LevelConfig.GetConfig(Convert.ToInt32(levelTxt.text)); if (level == null) { EditorTip.Show("没有对应的关卡!"); return; } //清除之前的颜色 List <GridVO> grids = EditorVO.Instance.piecesGrids; for (int i = 0; i < grids.Count; i++) { grids[i].color.value = 0; } grids = EditorVO.Instance.grids; for (int i = 0; i < grids.Count; i++) { grids[i].color.value = 0; } grids = EditorVO.Instance.otherGrids1; for (int i = 0; i < grids.Count; i++) { grids[i].color.value = 0; } for (int i = 0; i < level.pieces.Count; i++) { for (int n = 0; n < level.pieces[i].coords.Count; n++) { if (EditorVO.Instance.GetGrid(level.pieces[i].coords[n].x, level.pieces[i].coords[n].y).color.value != 0) { EditorTip.Show("关卡数据错误,有重叠!"); } EditorVO.Instance.GetGrid(level.pieces[i].coords[n].x, level.pieces[i].coords[n].y).color.value = i + 1; } } for (int i = 0; i < level.pieces2.Count; i++) { for (int n = 0; n < level.pieces2[i].coords.Count; n++) { if (EditorVO.Instance.GetGrid1(level.pieces2[i].coords[n].x, level.pieces2[i].coords[n].y).color.value != 0) { EditorTip.Show("关卡数据错误,多余片有重叠!"); } EditorVO.Instance.GetGrid1(level.pieces2[i].coords[n].x, level.pieces2[i].coords[n].y).color.value = level.pieces.Count + i + 1; } } EditorTip.Show("加载成功!"); new CreateLevelCommand(); DrawPieces(); }
public void ReadLevels(long time) { string content = PlayerPrefs.GetString("daily"); //Debug.Log(content); Dictionary <string, object> data; try { data = JSON.Parse(content) as Dictionary <string, object>; } catch { CreateNewLevels(time); return; } createTime = Convert.ToInt64(data["create"]); if (time - createTime > 2 * 3600 * 1000) { CreateNewLevels(time); return; } int count = 0; List <object> list = data["levels"] as List <object>; for (int i = 0; i < list.Count; i++) { Dictionary <string, object> item = list[i] as Dictionary <string, object>; DailyLevelVO levelvo = new DailyLevelVO(); levelvo.config = LevelConfig.GetConfig((int)item["id"]); levelvo.pass = (bool)item["pass"]; levelvo.time = (int)item["time"]; if (levelvo.pass) { count++; allTime.value += levelvo.time; allTimeString.value = StringUtils.TimeToMS(allTime.value); } levels.Add(levelvo); } all.value = levels.length; progress.value = count; isFirstPassAll = true; firstPassAll = false; if (HasAllPass()) { isFirstPassAll = false; } }
/// <summary> /// 构造函数 /// </summary> /// <param name="levelId">关卡 id</param> public StartGameCommand(int levelId) { MainData.Instance.dispatcher.DispatchWith(EventType.DISPOSE_GAME); LevelConfig level = LevelConfig.GetConfig(levelId); if (level != null) { MainData.Instance.levelId.value = levelId; MainData.Instance.time.value = 0; MainData.Instance.config = level; new Game(level); MainData.Instance.dispatcher.DispatchWith(EventType.START_LEVEL); } }
public SaveLevelCommand(int level) { //读取配置 //ConfigDecode.Decode(); //删除之前的 level 相关信息 if (LevelConfig.GetConfig(level) != null) { LevelConfig old = LevelConfig.GetConfig(level); LevelConfig.Configs.Remove(old); for (int i = 0; i < old.pieces.Count; i++) { PieceConfig.Configs.Remove(PieceConfig.GetConfig(old.pieces[i].id)); } for (int i = 0; i < old.pieces2.Count; i++) { PieceConfig.Configs.Remove(PieceConfig.GetConfig(old.pieces2[i].id)); } } if (EditorVO.Instance.level.pieces.Count > 0) { LevelConfig levelConfig = new LevelConfig(); LevelConfig.Configs.Add(levelConfig); levelConfig.id = level; for (int i = 0; i < EditorVO.Instance.level.pieces.Count; i++) { EditorLevelPiece piece = EditorVO.Instance.level.pieces[i]; PieceConfig pieceConfig = new PieceConfig(); levelConfig.pieces.Add(pieceConfig); pieceConfig.id = level * 100 + i; for (int c = 0; c < piece.grids.Count; c++) { if (CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y) == null) { CoordConfig coord = new CoordConfig(); coord.x = piece.grids[c].x; coord.y = piece.grids[c].y; coord.id = piece.grids[c].x * 1000 + -piece.grids[c].y; CoordConfig.Configs.Add(coord); } pieceConfig.coords.Add(CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y)); } PieceConfig.Configs.Add(pieceConfig); } for (int i = 0; i < EditorVO.Instance.level.otherPieces.Count; i++) { EditorLevelPiece piece = EditorVO.Instance.level.otherPieces[i]; PieceConfig pieceConfig = new PieceConfig(); levelConfig.pieces2.Add(pieceConfig); pieceConfig.id = level * 100 + EditorVO.Instance.level.pieces.Count + i; for (int c = 0; c < piece.grids.Count; c++) { if (CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y) == null) { CoordConfig coord = new CoordConfig(); coord.x = piece.grids[c].x; coord.y = piece.grids[c].y; coord.id = piece.grids[c].x * 1000 + -piece.grids[c].y; CoordConfig.Configs.Add(coord); } pieceConfig.coords.Add(CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y)); } PieceConfig.Configs.Add(pieceConfig); } CheckLevelPiecePosition(levelConfig); } //CheckAllLevelPiecePosition(); Save(); //CheckOut(); }
private void CreateNewLevels(long time) { isFirstPassAll = true; firstPassAll = false; createTime = time; //临时代码 生成每日挑战数据 //随机10个关卡,1-999 6 1000-1999 3 2000 1 //levels = new List<LevelConfig>(); List <int> list = new List <int>(); List <int> list2 = new List <int>(); List <int> list3 = new List <int>(); List <int> firstLevels = new List <int>() { }; if (GameVO.Instance.isFirstGame && firstGame) { firstGame = false; firstLevels.Add(1); firstLevels.Add(2); firstLevels.Add(3); firstLevels.Add(4); firstLevels.Add(5); for (int i = 0; i < firstLevels.Count; i++) { DailyLevelVO levelvo = new DailyLevelVO(); levelvo.config = LevelConfig.GetConfig(firstLevels[i]); levels.Add(levelvo); } } for (int i = 0; i < LevelConfig.Configs.Count; i++) { bool find = false; for (int j = 0; j < firstLevels.Count; j++) { if (firstLevels[j] == LevelConfig.Configs[i].id) { find = true; break; } } if (LevelConfig.Configs[i].pieces.Count + LevelConfig.Configs[i].pieces2.Count >= 4 && LevelConfig.Configs[i].pieces.Count + LevelConfig.Configs[i].pieces2.Count <= 6) { list.Add(i); } else if (LevelConfig.Configs[i].pieces.Count + LevelConfig.Configs[i].pieces2.Count >= 7 && LevelConfig.Configs[i].pieces.Count + LevelConfig.Configs[i].pieces2.Count <= 8) { list2.Add(i); } else if (LevelConfig.Configs[i].pieces.Count + LevelConfig.Configs[i].pieces2.Count >= 10) { list3.Add(i); } } while (levels.length < 6) { int index = (int)Math.Floor(UnityEngine.Random.Range(0, 1f) * list.Count); int ind = list[index]; list.RemoveAt(index); DailyLevelVO levelvo = new DailyLevelVO(); levelvo.config = LevelConfig.Configs[ind]; levels.Add(levelvo); } while (levels.length < 9) { int index = (int)Math.Floor(UnityEngine.Random.Range(0, 1f) * list2.Count); int ind = list2[index]; list2.RemoveAt(index); DailyLevelVO levelvo = new DailyLevelVO(); levelvo.config = LevelConfig.Configs[ind]; levels.Add(levelvo); } while (levels.length < 10) { int index = (int)Math.Floor(UnityEngine.Random.Range(0, 1f) * list3.Count); int ind = list3[index]; list3.RemoveAt(index); DailyLevelVO levelvo = new DailyLevelVO(); levelvo.config = LevelConfig.Configs[ind]; levels.Add(levelvo); } all.value = levels.length; allTime.value = 0; //存储 Save(); }