public void ReloadLevel() { if (level == null) { Debug.Log("当前地图为空"); return; } int x = level.X; int y = level.Y; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (GridController.Instance.DicGrid.ContainsKey(i * 10 + j)) { continue; } GameObject grid = Instantiate(Resources.Load("Prefabs/Grid")) as GameObject; GridUnit mgrid = grid.AddComponent <GridUnit>(); mgrid.GridId = GridController.Instance.GetGridID(i, j); grid.transform.SetParent(GridController.Instance.GridControllerTransform, false); GridController.Instance.DicGrid[mgrid.GridId] = mgrid; mgrid.GridType = GridController.Instance.GetNewType(mgrid.GridId); mgrid.Init(); grid.transform.SetAsFirstSibling(); } } }
public void LoadLevel(string levelName) { Debug.Log(levelName); level = LevelDic[levelName]; int x = level.X; int y = level.Y; mapPosList = level.mapPosList; mapTypeList = level.MapTypeList; if (!Global.instance.SoundManager.isPlayingBGM) { int order = (int)Random.Range(1f, 4f); string BGMName = "GamePlay0" + order.ToString(); Global.instance.SoundManager.PlayBGM(BGMName); } GridController.Instance.InitXandY(x, y); for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { GameObject grid = Instantiate(Resources.Load("Prefabs/Grid")) as GameObject; GridUnit mgrid = grid.AddComponent <GridUnit>(); mgrid.GridId = GridController.Instance.GetGridID(i, j); grid.transform.SetParent(GridController.Instance.GridControllerTransform, false); GridController.Instance.DicGrid[mgrid.GridId] = mgrid; mgrid.GridType = GridController.Instance.GetNewType(mgrid.GridId); mgrid.Init(); } } GridController.Instance.PlayKey = true; for (int i = 0; i < mapPosList.Count; i++) { GridController.Instance.DicGrid[mapPosList[i]].ChangeTypeTo(mapTypeList[i]); } /*GameObject[] UIsGo = GameObject.FindGameObjectsWithTag("UIElement"); * List<Vector2> UIsPos=level.UIsPos; * List<Vector2> UIsWH=level.UIsWH; * for(int i=0;i<UIsPos.Count;i++) * { * RectTransform rt = UIsGo[i].GetComponent<RectTransform>(); * rt.localPosition = UIsPos[i]; * rt.sizeDelta = UIsWH[i]; * }*/ gameProps = GameObject.Find("Tools/GamePropManager").GetComponent <GameProps>(); gameProps.ShowTioPropCount = level.PropsGetTip; gameProps.ResetMapCount = level.PropsMapReset; }
void ReSetNullGrid() { for (int i = 0; i < xl; i++) { for (int j = 0; j < yl; j++) { if (!DicGrid.ContainsKey(GetGridID(i, j))) { GameObject grid = Instantiate(Resources.Load("Prefabs/Grid")) as GameObject; GridUnit mgrid = grid.AddComponent <GridUnit>(); mgrid.GridId = GetGridID(i, j); grid.transform.SetParent(GridControllerTransform, false); DicGrid[mgrid.GridId] = mgrid; mgrid.GridType = GetNewType(mgrid.GridId); mgrid.Init(); if (iceDicGrid.ContainsKey(GetGridID(i, j))) { grid.transform.SetAsFirstSibling(); } } } } foreach (int id in iceDicGrid.Keys) { iceDicGrid[id].transform.SetAsLastSibling(); } RemoveGrid(); //在这里检查有没有还能消的,没有就重新加载地图 if (!ReStart()) { loopTimes++; if (loopTimes >= 50) { Debug.Log("死循环!"); loopTimes = 0; return; } ResetMap(); GamePlay(); } }