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); }
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; } }