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 UniTask SaveBuildingRoutine(BuildingSaveData buildingSaveData) { if (!savingBuildings.Contains(buildingSaveData.Id)) { savingBuildings.Add(buildingSaveData.Id); // Update building await DbServiceClient.UpdateBuildingAsync(new UpdateBuildingReq() { MapName = CurrentMapInfo.Id, BuildingData = buildingSaveData, }); savingBuildings.Remove(buildingSaveData.Id); if (LogInfo) { Logging.Log(LogTag, "Building [" + buildingSaveData.Id + "] Saved"); } } }
private async UniTask SaveBuildingRoutine(BuildingSaveData buildingSaveData) { if (!savingBuildings.Contains(buildingSaveData.Id)) { savingBuildings.Add(buildingSaveData.Id); // Update building await DbServiceClient.UpdateBuildingAsync(new UpdateBuildingReq() { MapName = Assets.onlineScene.SceneName, BuildingData = buildingSaveData.ToByteString() }); savingBuildings.Remove(buildingSaveData.Id); if (LogInfo) { Logging.Log(LogTag, "Building [" + buildingSaveData.Id + "] Saved"); } } }