public async Task <LevelConfig> GetNewLevelConfig(string levelName) { LevelConfig newLevelConfig = new LevelConfig(); // 房间 add by TangJian 2018/12/27 12:30 newLevelConfig.rooms = await AssetManager.LoadJson <List <RoomConfig> >("Level/" + levelName + "/Rooms.json"); // Tools.Json2Obj<List<RoomConfig>>(Tools.getJsonStringFromResource("Configs/Levels/" + levelName + "/Rooms")); // 房间连接 add by TangJian 2018/12/27 12:30 for (int i = 1; i < 999; i++) { string pathString = await AssetManager.LoadString("Level/" + levelName + "/Path" + i + ".json"); if (pathString == null) { break; } PathConfig newPath = Tools.Json2Obj <PathConfig>(pathString); newLevelConfig.paths.Add(newPath); } // 房间怪物物品 add by TangJian 2018/12/27 12:31 newLevelConfig.objectses = await AssetManager.LoadJson <List <RoomObjectesConfig> >("Level/" + levelName + "/Roles.json"); // 读取场景事件 add by TangJian 2018/12/29 16:04 newLevelConfig.sceneEvents = await AssetManager.LoadJson <SceneEvents>("Level/" + levelName + "/Events.json"); return(newLevelConfig); }
IEnumerator LoadLevelConfig(LevelConfig levelConfig) { levelConfig.currPath = levelConfig.paths[Random.Range(0, levelConfig.paths.Count)]; CurrPathName = levelConfig.currPath.pathName; IEnumerator loadSceneList = SceneManager.Instance.LoadLevelConfig(levelConfig); // 显示载入条 add by TangJian 2019/3/25 22:18 loadingUIController.Show(); loadingUIController.SetProgress(0); while (loadSceneList.MoveNext()) { loadingUIController.SetProgress(Convert.ToSingle(loadSceneList.Current)); yield return(null); } // 创建角色 进入第一个场景 add by TangJian 2017/11/23 17:34:30 { var task = CreatePlayer1Async(gameData.player1Data); while (task.IsCompleted == false) { yield return(null); } Player1 = task.Result; SceneManager.Instance.RoleEnterAndSwitchScene(Player1, levelConfig.currPath.beginRoom, "RoleAreas"); } // 隐藏载入界面 add by TangJian 2017/11/23 18:22:25 loadingUIController.gameObject.SetActive(false); gamingUIController.Init(); newRoleInfoUIController.Init(); gameoverUIController.Init(); suspendUIController.Init(); storeUIController.Init(); initRoleInfovalueMonitorPool(); }
IEnumerator StartNewGame(int level = 1) { var newLevelConfigTask = LevelManager.Instance.GetNewLevelConfig(NewLevelName); while (newLevelConfigTask.IsCompleted == false) { yield return(null); } LevelConfig newLevelConfig = newLevelConfigTask.Result; newLevelConfig.difficultyLevel = level; var loadScene = LoadLevelConfig(newLevelConfig); bool canMoveNext = true; while (canMoveNext) { canMoveNext = loadScene.MoveNext(); yield return(null); } }
public IEnumerator LoadLevelConfig(LevelConfig levelConfig) { ClearLoadedScene(); List<SceneData> sceneDataList = new List<SceneData>(); PathConfig currPath = levelConfig.currPath; Debug.Assert(currPath != null); // 创建场景数据 add by TangJian 2018/12/26 15:31 foreach (var roomData in levelConfig.rooms) { SceneData sceneData = new SceneData(); sceneData.sceneId = roomData.id; sceneData.rawSceneId = roomData.RawId; sceneDataList.Add(sceneData); } // 创建场景连接 add by TangJian 2018/12/26 15:32 foreach (var connectionData in currPath.connections) { string fromSceneId = connectionData.fromScene; string fromPortalId = connectionData.fromPortal; string toSceneId = connectionData.toScene; string toPortalId = connectionData.toPortal; SceneData fromSceneData = sceneDataList.Find((SceneData sceneData_) => { return fromSceneId == sceneData_.sceneId; }); SceneData toSceneData = sceneDataList.Find((SceneData sceneData_) => { return toSceneId == sceneData_.sceneId; }); Debug.Assert(fromSceneData!= null, "找不到场景" + fromSceneId); Debug.Assert(toSceneData!= null, "找不到场景" + toSceneId); // 添加门 add by TangJian 2018/12/26 15:42 { PortalData fromPortalData = new PortalData(); fromPortalData.id = fromPortalId; fromPortalData.sceneId = fromSceneId; fromPortalData.toSceneId = toSceneId; fromPortalData.toPortalId = toPortalId; fromSceneData.portalDatas.Add(fromPortalData); PortalData toPortalData = new PortalData(); toPortalData.id = toPortalId; toPortalData.sceneId = toSceneId; toPortalData.toSceneId = fromSceneId; toPortalData.toPortalId = fromPortalId; toSceneData.portalDatas.Add(toPortalData); } } // 向场景数据中添加怪物数据 add by TangJian 2018/12/27 12:42 foreach (var objectData in levelConfig.objectses) { RoomObjectesConfig newRoomObjects = objectData; SceneData sceneData = sceneDataList.Find((SceneData sceneData_) => { return newRoomObjects.roomId == sceneData_.sceneId; }); Debug.Assert(sceneData!=null, "找不到SceneData: " + newRoomObjects.roomId); for (int j = 0; j < newRoomObjects.objects.Count; j++) { RoomObjectConfig newRoomObject = newRoomObjects.objects[j]; for (int k = 0; k < newRoomObject.count; k++) { RoleData roleData = new RoleData(); roleData.Id = newRoomObject.objectId; roleData.Prefab = newRoomObject.objectId; roleData.TeamId = "2"; roleData.locationData.areaId = newRoomObject.areaId; sceneData.roleDatas.Add(roleData); } } } // 设置场景事件 add by TangJian 2019/1/2 14:49 InitSceneEvent(levelConfig.sceneEvents); int step = 0; int stepCount = sceneDataList.Count; // 创建场景 add by TangJian 2018/12/26 15:48 for (int i = 0; i < sceneDataList.Count; i++) { SceneData sceneData = sceneDataList[i]; var handle = CreateSceneAsync(sceneData, levelConfig.difficultyLevel); while (handle.IsCompleted == false) { yield return (float)(step) / stepCount; } SceneController scene = handle.Result; // SceneController scene = CreateScene(sceneData, levelConfig.difficultyLevel); scenes.Add(sceneData.sceneId, scene); scene.gameObject.SetActive(false); yield return (float)(++step) / stepCount; } }