Advertisement
Alior

Untitled

Oct 10th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using OSGraphicsAPI;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. using Zenject;
  8.  
  9. public interface ISkyboxCubemapLoader
  10. {
  11.     event Action<TourPoint, Cubemap> OnCubemapLoaded;
  12. }
  13.  
  14. public class SkyboxCubemapLoader : ITourPointResourceDependencyHolder, ISkyboxCubemapLoader
  15. {
  16.     [Inject]
  17.     private ITourController tourController;
  18.  
  19.     [Inject]
  20.     private ITaskRunner taskRunner;
  21.  
  22.     [Inject]
  23.     private ICacheManager cacheManager;
  24.  
  25.     public event Action<TourPoint, Cubemap> OnCubemapLoaded;
  26.  
  27.     void ITourPointResourceDependencyHolder.SatisfyDependency(TourPoint point, Action onComplete)
  28.     {
  29.         var loadedCubemap = new Cubemap(tourController.CurrentTour.MaxResolution, TextureFormat.RGBA32, false);
  30.         var pointer = loadedCubemap.GetNativeTexturePtr();
  31.  
  32.         Task.Factory.StartNew(() =>
  33.             {
  34.                 var skyboxPath = cacheManager.GetCacheSkyboxPathes(tourController.CurrentEstate.Id, tourController.CurrentTour.Id, point.Skybox.Id, tourController.CurrentTour.MaxResolution);
  35.                 Loader.LoadCubemapInternal(pointer, skyboxPath);
  36.  
  37.                 taskRunner.ExecuteInMainThreadUpdate(() =>
  38.                     {
  39.                         if (OnCubemapLoaded != null)
  40.                             OnCubemapLoaded(point, loadedCubemap);
  41.                     });
  42.  
  43.                 taskRunner.ExecuteInMainThreadUpdate(onComplete);
  44.             });
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement