| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using Cysharp.Threading.Tasks; |
| | 5 | | using DCL.Builder.Manifest; |
| | 6 | | using DCL.Configuration; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using DCL.Interface; |
| | 9 | | using UnityEngine; |
| | 10 | |
|
| | 11 | | namespace DCL.Builder |
| | 12 | | { |
| | 13 | | public class Publisher : IPublisher |
| | 14 | | { |
| | 15 | | private const string BIGGER_LAND_TO_PUBLISH_TEXT = "Your scene is bigger than any Land you own.\nBrowse the Mark |
| | 16 | | private const string NO_LAND_TO_PUBLISH_TEXT = "To publish a scene first you need a Land where you can deploy it |
| | 17 | | public const string UNPUBLISH_EMPTY_SCENE_NAME = "Empty"; |
| | 18 | |
|
| | 19 | | public enum TYPE |
| | 20 | | { |
| | 21 | | PUBLISH = 0, |
| | 22 | | UNPUBLISH = 1 |
| | 23 | | } |
| | 24 | | public event Action<bool> OnPublishFinish; |
| | 25 | |
|
| | 26 | | private IPublishProjectController projectPublisher; |
| | 27 | | private ILandPublisherController landPublisher; |
| | 28 | | private IPublishProgressController progressController; |
| | 29 | |
|
| | 30 | | private IContext context; |
| | 31 | |
|
| | 32 | | private BuilderInWorldBridge builderInWorldBridge; |
| | 33 | | private float startPublishingTimestamp = 0; |
| | 34 | |
|
| | 35 | | private IBuilderScene builderSceneToDeploy; |
| | 36 | | private PublishInfo publishInfo; |
| | 37 | | private IBuilderScene.SceneType lastTypeWhoStartedPublish; |
| | 38 | | private TYPE type = TYPE.PUBLISH; |
| | 39 | |
|
| | 40 | | private float rotationToApply = 0f; |
| | 41 | |
|
| | 42 | | public void Initialize(IContext context) |
| | 43 | | { |
| 0 | 44 | | this.context = context; |
| | 45 | |
|
| 0 | 46 | | projectPublisher = new PublishProjectController(); |
| 0 | 47 | | landPublisher = new LandPublisherController(); |
| 0 | 48 | | progressController = new PublishProgressController(); |
| | 49 | |
|
| 0 | 50 | | landPublisher.Initialize(); |
| 0 | 51 | | projectPublisher.Initialize(); |
| 0 | 52 | | progressController.Initialize(); |
| | 53 | |
|
| 0 | 54 | | landPublisher.OnPublishPressed += PublishLandScene; |
| 0 | 55 | | projectPublisher.OnPublishPressed += ConfirmDeployment; |
| | 56 | |
|
| 0 | 57 | | landPublisher.OnPublishCancel += Canceled; |
| 0 | 58 | | projectPublisher.OnPublishCancel += Canceled; |
| | 59 | |
|
| 0 | 60 | | progressController.OnConfirm += StartDeployment; |
| 0 | 61 | | progressController.OnBackPressed += BackToPublishInfo; |
| | 62 | |
|
| 0 | 63 | | builderInWorldBridge = context.sceneReferences.biwBridgeGameObject.GetComponent<BuilderInWorldBridge>(); |
| | 64 | |
|
| 0 | 65 | | if (builderInWorldBridge != null) |
| 0 | 66 | | builderInWorldBridge.OnPublishEnd += PublishEnd; |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | public void Dispose() |
| | 70 | | { |
| 0 | 71 | | landPublisher.OnPublishPressed -= PublishLandScene; |
| 0 | 72 | | projectPublisher.OnPublishPressed -= ConfirmDeployment; |
| | 73 | |
|
| 0 | 74 | | landPublisher.OnPublishCancel -= Canceled; |
| 0 | 75 | | projectPublisher.OnPublishCancel -= Canceled; |
| | 76 | |
|
| 0 | 77 | | progressController.OnConfirm -= StartDeployment; |
| 0 | 78 | | progressController.OnBackPressed -= BackToPublishInfo; |
| | 79 | |
|
| 0 | 80 | | if (builderInWorldBridge != null) |
| 0 | 81 | | builderInWorldBridge.OnPublishEnd -= PublishEnd; |
| | 82 | |
|
| 0 | 83 | | projectPublisher.Dispose(); |
| 0 | 84 | | landPublisher.Dispose(); |
| 0 | 85 | | progressController.Dispose(); |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | private void BackToPublishInfo() |
| | 89 | | { |
| 0 | 90 | | switch (lastTypeWhoStartedPublish) |
| | 91 | | { |
| | 92 | | case IBuilderScene.SceneType.PROJECT: |
| 0 | 93 | | projectPublisher.SetActive(true); |
| 0 | 94 | | break; |
| | 95 | | case IBuilderScene.SceneType.LAND: |
| 0 | 96 | | landPublisher.SetActive(true); |
| | 97 | | break; |
| | 98 | | } |
| 0 | 99 | | } |
| | 100 | |
|
| | 101 | | public void StartPublish(IBuilderScene scene) |
| | 102 | | { |
| 0 | 103 | | if (!HasLands()) |
| | 104 | | { |
| 0 | 105 | | context.commonHUD.GetPopUp() |
| | 106 | | .ShowPopUpWithoutTitle(NO_LAND_TO_PUBLISH_TEXT, "BUY LAND", "BACK", () => |
| | 107 | | { |
| 0 | 108 | | WebInterface.OpenURL(BIWSettings.MARKETPLACE_URL); |
| 0 | 109 | | }, null); |
| 0 | 110 | | return; |
| | 111 | | } |
| | 112 | |
|
| 0 | 113 | | if (!CanPublishInLands(scene)) |
| | 114 | | { |
| 0 | 115 | | context.commonHUD.GetPopUp() |
| | 116 | | .ShowPopUpWithoutTitle(BIGGER_LAND_TO_PUBLISH_TEXT, "BUY LAND", "BACK", () => |
| | 117 | | { |
| 0 | 118 | | WebInterface.OpenURL(BIWSettings.MARKETPLACE_URL); |
| 0 | 119 | | }, null); |
| 0 | 120 | | return; |
| | 121 | | } |
| | 122 | |
|
| 0 | 123 | | DataStore.i.builderInWorld.areShortcutsBlocked.Set(true); |
| 0 | 124 | | type = TYPE.PUBLISH; |
| | 125 | |
|
| 0 | 126 | | switch (scene.sceneType) |
| | 127 | | { |
| | 128 | | case IBuilderScene.SceneType.PROJECT: |
| 0 | 129 | | projectPublisher.StartPublishFlow(scene); |
| 0 | 130 | | break; |
| | 131 | | case IBuilderScene.SceneType.LAND: |
| 0 | 132 | | landPublisher.StartPublishFlow(scene); |
| | 133 | | break; |
| | 134 | | } |
| | 135 | |
|
| 0 | 136 | | lastTypeWhoStartedPublish = scene.sceneType; |
| 0 | 137 | | } |
| | 138 | |
|
| | 139 | | public async void Unpublish(Vector2Int coords, Vector2Int size) |
| | 140 | | { |
| 0 | 141 | | type = TYPE.UNPUBLISH; |
| | 142 | |
|
| 0 | 143 | | var manifest = BIWUtils.CreateEmptyDefaultBuilderManifest(size, BIWUtils.Vector2INTToString(coords)); |
| | 144 | |
|
| 0 | 145 | | CatalystSceneEntityMetadata sceneJson = new CatalystSceneEntityMetadata(); |
| | 146 | |
|
| | 147 | | //Display info |
| 0 | 148 | | sceneJson.display = new CatalystSceneEntityMetadata.Display(); |
| 0 | 149 | | sceneJson.display.title = UNPUBLISH_EMPTY_SCENE_NAME; |
| | 150 | |
|
| | 151 | | //Scenes |
| 0 | 152 | | sceneJson.scene = new CatalystSceneEntityMetadata.Scene(); |
| | 153 | |
|
| | 154 | | // Base Parcels |
| 0 | 155 | | string baseParcels = BIWUtils.Vector2INTToString(coords); |
| 0 | 156 | | sceneJson.scene.@base = baseParcels; |
| | 157 | |
|
| | 158 | | // All parcels |
| 0 | 159 | | string[] parcels = new string[size.x*size.y]; |
| 0 | 160 | | int count = 0; |
| | 161 | |
|
| 0 | 162 | | for (int x = 0; x < size.x; x++) |
| | 163 | | { |
| 0 | 164 | | for (int y = 0; y < size.y; y++) |
| | 165 | | { |
| 0 | 166 | | parcels[count] = (coords.x + x) + "," + (coords.y + y); |
| 0 | 167 | | count++; |
| | 168 | | } |
| | 169 | | } |
| | 170 | |
|
| 0 | 171 | | sceneJson.scene.parcels = parcels; |
| | 172 | |
|
| | 173 | | //Main |
| 0 | 174 | | sceneJson.main = BIWSettings.DEPLOYMENT_BUNDLED_GAME_FILE; |
| | 175 | |
|
| | 176 | | //Source |
| 0 | 177 | | sceneJson.source = new CatalystSceneEntityMetadata.Source(); |
| 0 | 178 | | sceneJson.source.origin = BIWSettings.DEPLOYMENT_SOURCE_TYPE; |
| 0 | 179 | | sceneJson.source.version = 1; |
| 0 | 180 | | sceneJson.source.layout = new CatalystSceneEntityMetadata.Source.Layout(); |
| 0 | 181 | | sceneJson.source.layout.rows = size.x; |
| 0 | 182 | | sceneJson.source.layout.cols = size.y; |
| 0 | 183 | | sceneJson.source.point = new CatalystSceneEntityMetadata.Vector2IntRepresentantion(coords); |
| 0 | 184 | | sceneJson.source.isEmpty = true; |
| 0 | 185 | | sceneJson.source.isEmpty = true; |
| | 186 | |
|
| | 187 | | // Prepare the assets |
| 0 | 188 | | List<SceneObject> assets = manifest.scene.assets.Values.ToList(); |
| | 189 | |
|
| | 190 | | // Download the assets files |
| 0 | 191 | | Dictionary<string, object> downloadedFiles = await DownloadAssetFiles(assets); |
| | 192 | |
|
| | 193 | | // This files are not encoded |
| 0 | 194 | | Dictionary<string, object> entityFiles = new Dictionary<string, object> |
| | 195 | | { |
| | 196 | | { BIWSettings.DEPLOYMENT_SCENE_FILE, sceneJson }, |
| | 197 | | { BIWSettings.DEPLOYMENT_ASSETS, assets }, |
| | 198 | | }; |
| | 199 | |
|
| | 200 | | // Prepare the stateless manifest |
| 0 | 201 | | StatelessManifest statelessManifest = ManifestTranslator.WebBuilderSceneToStatelessManifest(manifest.scene); |
| | 202 | |
|
| | 203 | | // Sent scene to kernel |
| 0 | 204 | | StartUnpublishScene(downloadedFiles,entityFiles,statelessManifest, sceneJson); |
| 0 | 205 | | } |
| | 206 | |
|
| | 207 | | internal void Canceled() |
| | 208 | | { |
| 0 | 209 | | DataStore.i.builderInWorld.areShortcutsBlocked.Set(false); |
| 0 | 210 | | } |
| | 211 | |
|
| 0 | 212 | | internal bool HasLands() { return DataStore.i.builderInWorld.landsWithAccess.Get().Length > 0; } |
| | 213 | |
|
| | 214 | | internal bool CanPublishInLands(IBuilderScene scene) |
| | 215 | | { |
| 0 | 216 | | List<Vector2Int> availableLandsToPublish = BIWUtils.GetLandsToPublishProject(DataStore.i.builderInWorld.land |
| 0 | 217 | | return availableLandsToPublish.Count > 0; |
| | 218 | | } |
| | 219 | |
|
| | 220 | | internal void PublishLandScene(IBuilderScene scene) |
| | 221 | | { |
| 0 | 222 | | PublishInfo publishInfo = new PublishInfo(); |
| 0 | 223 | | publishInfo.rotation = PublishInfo.ProjectRotation.NORTH; |
| 0 | 224 | | publishInfo.coordsToPublish = scene.landCoordsAsociated; |
| 0 | 225 | | ConfirmDeployment(scene, publishInfo); |
| 0 | 226 | | } |
| | 227 | |
|
| | 228 | | internal void ConfirmDeployment(IBuilderScene scene, PublishInfo info) |
| | 229 | | { |
| 0 | 230 | | builderSceneToDeploy = scene; |
| 0 | 231 | | publishInfo = info; |
| 0 | 232 | | progressController.SetInfoToPublish(scene, info); |
| 0 | 233 | | progressController.ShowConfirmDeploy(); |
| 0 | 234 | | } |
| | 235 | |
|
| 0 | 236 | | internal void StartDeployment() { DeployScene(builderSceneToDeploy, publishInfo); } |
| | 237 | |
|
| | 238 | | internal void ApplyRotation(IBuilderScene scene, PublishInfo.ProjectRotation rotation) |
| | 239 | | { |
| 0 | 240 | | rotationToApply = 90f * (int)rotation; |
| 0 | 241 | | RotationScene(scene, rotationToApply); |
| 0 | 242 | | } |
| | 243 | |
|
| | 244 | | internal void UndoRotationToScene(IBuilderScene scene) |
| | 245 | | { |
| 0 | 246 | | RotationScene(scene, -rotationToApply); |
| 0 | 247 | | } |
| | 248 | |
|
| | 249 | | internal void RotationScene(IBuilderScene scene, float amount) |
| | 250 | | { |
| | 251 | | // Note: if the aerialscreenshot is not available, this means that the scene has been deployed |
| | 252 | | // from the panel instead of the editor, so we don't have the scene to rotate, we publish it to north direct |
| 0 | 253 | | if (scene.aerialScreenshotTexture == null) |
| 0 | 254 | | return; |
| | 255 | |
|
| 0 | 256 | | var transform = scene.scene.GetSceneTransform(); |
| 0 | 257 | | Vector3 middlePoint = BIWUtils.CalculateUnityMiddlePoint(scene.scene); |
| | 258 | |
|
| 0 | 259 | | transform.RotateAround(middlePoint,Vector3.up,amount); |
| 0 | 260 | | scene.UpdateManifestFromScene(); |
| 0 | 261 | | } |
| | 262 | |
|
| | 263 | | internal async void DeployScene(IBuilderScene scene, PublishInfo info) |
| | 264 | | { |
| | 265 | | try |
| | 266 | | { |
| | 267 | | // We assign the scene to deploy |
| 0 | 268 | | builderSceneToDeploy = scene; |
| | 269 | |
|
| | 270 | | // Prepare the thumbnail |
| 0 | 271 | | byte[] thumbnail = scene.sceneScreenshotTexture.EncodeToPNG(); |
| | 272 | |
|
| | 273 | | // Prepare the assets |
| 0 | 274 | | List<SceneObject> assets = scene.manifest.scene.assets.Values.ToList(); |
| | 275 | |
|
| | 276 | | // Download the assets files |
| 0 | 277 | | Dictionary<string, object> downloadedFiles = await DownloadAssetFiles(assets); |
| | 278 | |
|
| | 279 | | // Prepare scene.json |
| 0 | 280 | | CatalystSceneEntityMetadata sceneJson = CreateSceneJson(scene, info); |
| | 281 | |
|
| | 282 | | // We apply the rotation of the scene so the entities are rotated |
| 0 | 283 | | ApplyRotation(scene, info.rotation); |
| | 284 | |
|
| | 285 | | // Group all entities files |
| 0 | 286 | | StatelessManifest statelessManifest = ManifestTranslator.WebBuilderSceneToStatelessManifest(scene.manife |
| | 287 | |
|
| | 288 | | // We undo the rotation of the scene |
| 0 | 289 | | UndoRotationToScene(scene); |
| | 290 | |
|
| | 291 | | // This files are not encoded |
| 0 | 292 | | Dictionary<string, object> entityFiles = new Dictionary<string, object> |
| | 293 | | { |
| | 294 | | { BIWSettings.DEPLOYMENT_DEFINITION_FILE, statelessManifest }, |
| | 295 | | { BIWSettings.DEPLOYMENT_SCENE_FILE, sceneJson }, |
| | 296 | | { BIWSettings.DEPLOYMENT_ASSETS, assets }, |
| | 297 | | }; |
| | 298 | |
|
| | 299 | | // This file will be encoded automatically |
| 0 | 300 | | Dictionary<string, object> entityFilesToDecode = new Dictionary<string, object> |
| | 301 | | { |
| | 302 | | { BIWSettings.DEPLOYMENT_SCENE_THUMBNAIL, thumbnail }, |
| | 303 | | }; |
| | 304 | |
|
| 0 | 305 | | foreach (var downloadedFile in downloadedFiles) |
| 0 | 306 | | entityFilesToDecode.Add(downloadedFile.Key, downloadedFile.Value); |
| | 307 | |
|
| | 308 | | // Sent scene to kernel |
| 0 | 309 | | StartPublishScene(scene, entityFilesToDecode, entityFiles, sceneJson, statelessManifest); |
| 0 | 310 | | } |
| 0 | 311 | | catch (Exception e) |
| | 312 | | { |
| | 313 | | // If there is a problem while are preparing the files we end the publishing with an error |
| 0 | 314 | | PublishEnd(false, e.Message); |
| 0 | 315 | | } |
| 0 | 316 | | } |
| | 317 | |
|
| | 318 | | private void StartUnpublishScene(Dictionary<string, object > filesToDecode, Dictionary<string, object > files,St |
| | 319 | | { |
| 0 | 320 | | builderInWorldBridge.PublishScene(filesToDecode, files, metadata, statelessManifest, true); |
| 0 | 321 | | } |
| | 322 | |
|
| | 323 | | private void StartPublishScene(IBuilderScene scene, Dictionary<string, object > filesToDecode, Dictionary<string |
| | 324 | | { |
| 0 | 325 | | startPublishingTimestamp = Time.realtimeSinceStartup; |
| 0 | 326 | | BIWAnalytics.StartScenePublish(scene.scene.metricsCounter.currentCount); |
| | 327 | |
|
| | 328 | | // Note: if the aerialscreenshot is not available, this means that the scene has been deployed |
| | 329 | | // from the panel instead of the editor, so we don't have the scene to rotate, we publish it to north direct |
| 0 | 330 | | bool publishFromPanel = scene.aerialScreenshotTexture == null && scene.sceneType == IBuilderScene.SceneType. |
| | 331 | |
|
| 0 | 332 | | builderInWorldBridge.PublishScene(filesToDecode, files, metadata, statelessManifest, publishFromPanel); |
| 0 | 333 | | } |
| | 334 | |
|
| | 335 | | private void PublishEnd(bool isOk, string message) |
| | 336 | | { |
| 0 | 337 | | if (type == TYPE.UNPUBLISH) |
| | 338 | | { |
| 0 | 339 | | PublishSceneResultPayload payload = new PublishSceneResultPayload(); |
| 0 | 340 | | payload.ok = isOk; |
| 0 | 341 | | payload.error = message; |
| 0 | 342 | | DataStore.i.builderInWorld.unpublishSceneResult.Set(payload); |
| 0 | 343 | | } |
| | 344 | | else |
| | 345 | | { |
| 0 | 346 | | if (isOk) |
| | 347 | | { |
| | 348 | | // We notify the success of the deployment |
| 0 | 349 | | progressController.DeploySuccess(); |
| | 350 | |
|
| | 351 | | // Remove link to a land if exists |
| 0 | 352 | | builderSceneToDeploy.manifest.project.creation_coords = null; |
| | 353 | |
|
| | 354 | | // Update project on the builder server |
| 0 | 355 | | context.builderAPIController.SetManifest(builderSceneToDeploy.manifest); |
| 0 | 356 | | } |
| | 357 | | else |
| | 358 | | { |
| 0 | 359 | | progressController.DeployError(message); |
| | 360 | | } |
| 0 | 361 | | string successString = isOk ? "Success" : message; |
| 0 | 362 | | BIWAnalytics.EndScenePublish(builderSceneToDeploy.scene.metricsCounter.currentCount, successString, Time |
| | 363 | |
|
| 0 | 364 | | if (isOk) |
| 0 | 365 | | builderSceneToDeploy = null; |
| | 366 | |
|
| 0 | 367 | | DataStore.i.builderInWorld.areShortcutsBlocked.Set(false); |
| | 368 | |
|
| 0 | 369 | | OnPublishFinish?.Invoke(isOk); |
| | 370 | | } |
| 0 | 371 | | } |
| | 372 | |
|
| | 373 | | internal CatalystSceneEntityMetadata CreateSceneJson(IBuilderScene builderScene, PublishInfo info) |
| | 374 | | { |
| 0 | 375 | | CatalystSceneEntityMetadata sceneJson = new CatalystSceneEntityMetadata(); |
| | 376 | |
|
| | 377 | | // Display info |
| 0 | 378 | | sceneJson.display = new CatalystSceneEntityMetadata.Display(); |
| 0 | 379 | | sceneJson.display.title = builderScene.manifest.project.title; |
| 0 | 380 | | sceneJson.display.description = builderScene.manifest.project.description; |
| 0 | 381 | | sceneJson.display.navmapThumbnail = BIWSettings.DEPLOYMENT_SCENE_THUMBNAIL; |
| | 382 | |
|
| | 383 | | // Contact |
| 0 | 384 | | sceneJson.contact = new CatalystSceneEntityMetadata.Contact(); |
| 0 | 385 | | sceneJson.contact.name = UserProfile.GetOwnUserProfile().name; |
| | 386 | |
|
| | 387 | | // Tags |
| 0 | 388 | | sceneJson.tags = Array.Empty<string>(); |
| | 389 | |
|
| | 390 | | // Spawn points |
| 0 | 391 | | sceneJson.spawnPoints = Array.Empty<CatalystSceneEntityMetadata.SpawnPoint>(); |
| | 392 | |
|
| | 393 | | // Owner |
| 0 | 394 | | sceneJson.owner = UserProfile.GetOwnUserProfile().ethAddress; |
| | 395 | |
|
| | 396 | | // Scenes |
| 0 | 397 | | sceneJson.scene = new CatalystSceneEntityMetadata.Scene(); |
| | 398 | |
|
| | 399 | | // Base Parcels |
| 0 | 400 | | string baseParcels = info.coordsToPublish.x + "," + info.coordsToPublish.y; |
| 0 | 401 | | sceneJson.scene.@base = baseParcels; |
| | 402 | |
|
| | 403 | | // All parcels |
| 0 | 404 | | string[] parcels = new string[builderScene.scene.sceneData.parcels.Length]; |
| 0 | 405 | | int cont = 0; |
| | 406 | |
|
| | 407 | | // Size |
| 0 | 408 | | Vector2Int sceneSize = BIWUtils.GetSceneSize(builderScene.scene); |
| 0 | 409 | | for (int x = 0; x < sceneSize.x; x++) |
| | 410 | | { |
| 0 | 411 | | for (int y = 0; y < sceneSize.y; y++) |
| | 412 | | { |
| 0 | 413 | | parcels[cont] = (info.coordsToPublish.x + x) + "," + (info.coordsToPublish.y + y); |
| 0 | 414 | | cont++; |
| | 415 | | } |
| | 416 | | } |
| | 417 | |
|
| 0 | 418 | | sceneJson.scene.parcels = parcels; |
| | 419 | |
|
| | 420 | | //Main |
| 0 | 421 | | sceneJson.main = BIWSettings.DEPLOYMENT_BUNDLED_GAME_FILE; |
| | 422 | |
|
| | 423 | | //Source |
| 0 | 424 | | sceneJson.source = new CatalystSceneEntityMetadata.Source(); |
| 0 | 425 | | sceneJson.source.origin = BIWSettings.DEPLOYMENT_SOURCE_TYPE; |
| 0 | 426 | | sceneJson.source.version = 1; |
| 0 | 427 | | sceneJson.source.projectId = builderScene.manifest.project.id; |
| 0 | 428 | | sceneJson.source.rotation = info.rotation.ToString().ToLowerInvariant(); |
| 0 | 429 | | sceneJson.source.layout = new CatalystSceneEntityMetadata.Source.Layout(); |
| 0 | 430 | | sceneJson.source.layout.rows = builderScene.manifest.project.rows; |
| 0 | 431 | | sceneJson.source.layout.cols = builderScene.manifest.project.cols; |
| 0 | 432 | | sceneJson.source.point = new CatalystSceneEntityMetadata.Vector2IntRepresentantion(info.coordsToPublish); |
| | 433 | |
|
| 0 | 434 | | return sceneJson; |
| | 435 | | } |
| | 436 | |
|
| | 437 | | internal async UniTask<Dictionary<string, object>> DownloadAssetFiles(List<SceneObject> assetsToDownload) |
| | 438 | | { |
| 0 | 439 | | Dictionary<string, object> downloadedAssets = new Dictionary<string, object>(); |
| 0 | 440 | | List<WebRequestAsyncOperation> asyncOperations = new List<WebRequestAsyncOperation>(); |
| | 441 | |
|
| 0 | 442 | | foreach (SceneObject sceneObject in assetsToDownload) |
| | 443 | | { |
| | 444 | | //We download each assets needed for the SceneObject |
| 0 | 445 | | foreach (KeyValuePair<string, string> assetsContent in sceneObject.contents) |
| | 446 | | { |
| 0 | 447 | | string url = sceneObject.GetBaseURL() + assetsContent.Value; |
| 0 | 448 | | var asyncOperation = Environment.i.platform.webRequest.Get( |
| | 449 | | url: url, |
| | 450 | | OnSuccess: (webRequestResult) => |
| | 451 | | { |
| 0 | 452 | | byte[] byteArray = webRequestResult.GetResultData(); |
| | 453 | |
|
| 0 | 454 | | downloadedAssets.Add(BIWSettings.DEPLOYMENT_MODELS_FOLDER + "/" + assetsContent.Key, byteArr |
| 0 | 455 | | }, |
| 0 | 456 | | OnFail: (webRequestResult) => { }); |
| 0 | 457 | | asyncOperations.Add((WebRequestAsyncOperation)asyncOperation); |
| | 458 | | } |
| | 459 | | } |
| | 460 | |
|
| | 461 | | //We wait for all assets |
| 0 | 462 | | foreach (WebRequestAsyncOperation operation in asyncOperations) |
| | 463 | | { |
| 0 | 464 | | await operation; |
| | 465 | | } |
| | 466 | |
|
| 0 | 467 | | return downloadedAssets; |
| 0 | 468 | | } |
| | 469 | | } |
| | 470 | | } |