protected async override void OnDestroy() { // Save immediately #if UNITY_STANDALONE && !CLIENT_BUILD if (IsServer) { foreach (BasePlayerCharacterEntity playerCharacter in ServerUserHandlers.GetPlayerCharacters()) { if (playerCharacter == null) { continue; } await DbServiceClient.UpdateCharacterAsync(new UpdateCharacterReq() { CharacterData = playerCharacter.CloneTo(new PlayerCharacterData()) }); } string mapName = CurrentMapInfo.Id; foreach (BuildingEntity buildingEntity in ServerBuildingHandlers.GetBuildings()) { if (buildingEntity == null) { continue; } await DbServiceClient.UpdateBuildingAsync(new UpdateBuildingReq() { MapName = mapName, BuildingData = buildingEntity.CloneTo(new BuildingSaveData()) }); } } #endif base.OnDestroy(); }
private async UniTaskVoid SaveBuildingsRoutine() { if (savingBuildings.Count == 0) { int i = 0; List <UniTask> tasks = new List <UniTask>(); foreach (BuildingEntity buildingEntity in ServerBuildingHandlers.GetBuildings()) { if (buildingEntity == null) { continue; } tasks.Add(SaveBuildingRoutine(buildingEntity.CloneTo(new BuildingSaveData()))); ++i; } await UniTask.WhenAll(tasks); if (LogInfo) { Logging.Log(LogTag, "Saved " + i + " building(s)"); } } }