示例#1
0
        public GridOverlayViewModel(ICoordinateService coordinateService,
                                    IWorldConfigRepository loadedWorldConfigRepository,
                                    IMapConfigRepository mapConfigRepository,
                                    ITilesPositionService tilesPositionService,
                                    Transform centerTransform)
        {
            CoordinateVisibilityLiveData = new LiveData <bool>(true);
            GridVisibilityLiveData       = new LiveData <bool>(true);
            CellsCountLiveData           = new LiveData <int>();
            CellsPositionLiveData        = new LiveData <IReadOnlyList <Vector3> >();
            WorldConfigLiveData          = new LiveData <WorldConfig>();
            CoordinatesLiveData          = new LiveData <IReadOnlyList <Coordinate> >();

            _compositeDisposable = new CompositeDisposable
            {
                mapConfigRepository.GetObservableStream()
                .CombineLatest(
                    loadedWorldConfigRepository.GetObservableStream(),
                    tilesPositionService.GetObservableStream(centerTransform.position.y),
                    (mapConfig, worldConfig, positions) => (mapConfig, worldConfig, positions)
                    )
                .Subscribe(
                    tuple =>
                {
                    var(mapConfig, worldConfig, positions) = tuple;
                    var coordinates = coordinateService.GetFlattenCoordinates(mapConfig);

                    UpdateCellsCountsWhenNeeded(coordinates.Count);
                    UpdateCellsPositionWhenNeeded(positions);
                    UpdateWorldConfigWhenNeeded(worldConfig);
                    UpdateCoordinatesWhenNeeded(coordinates);
                }
                    )
            };
        }
示例#2
0
 public IObservable <IReadOnlyList <Vector3> > GetObservableStream(float yPosition)
 {
     return(_mapConfigRepository.GetObservableStream()
            .CombineLatest(_worldConfigRepository.GetObservableStream(), (mapConfig, worldConfig) => (mapConfig, worldConfig))
            .Select(
                tuple =>
     {
         var(mapConfig, worldConfig) = tuple;
         return CreateData(mapConfig, worldConfig, yPosition);
     }
                ));
 }
        public ClosestTileHolderFromPositionService(IWorldConfigRepository loadedWorldConfigRepository,
                                                    IBoardItemHoldersFetchingService <TileHolder> holderFetchingService,
                                                    ILoadBoardItemsHolderService tileHolderLoadService)
        {
            _holderFetchingService = holderFetchingService;
            _currentTileHolders    = new List <TileHolder>();

            _compositeDisposable = new CompositeDisposable
            {
                loadedWorldConfigRepository.GetObservableStream()
                .SubscribeOn(Scheduler.ThreadPool)
                .ObserveOn(Scheduler.MainThread)
                .Subscribe(config => _currentWorldConfig = config),
                tileHolderLoadService.FinishedLoadingEventStream
                .SubscribeOn(Scheduler.ThreadPool)
                .ObserveOn(Scheduler.MainThread)
                .Subscribe(_ => UpdateCurrentTileHolders())
            };
        }