Exemple #1
0
        public IObservable <Unit> Load(Transform mapTransform, MapConfig mapConfig)
        {
            return(_tilesPositionService
                   .GetMostRecent(mapTransform.position.y)
                   .Zip(_boardItemsRepository.GetMostRecent(), (positions, items) => (positions, items))
                   .Select(
                       tuple =>
            {
                var(positions, items) = tuple;

                foreach (var item in items)
                {
                    var(component, gameObject) = _holderFactory.Create(mapTransform, false);
                    var flattenedIndex = _coordinateService.GetFlattenArrayIndexFromAxialCoordinate(
                        item.Coordinate.X,
                        item.Coordinate.Z,
                        mapConfig
                        );

                    gameObject.transform.position = positions[flattenedIndex];
                    gameObject.transform.parent = mapTransform;

                    component.Initialize(item);
                }

                _finishedLoadingEventStream.OnNext(Unit.Default);
                return Unit.Default;
            }
                       ));
        }
        public IObservable <Unit> DestructStronghold(LevelData levelData, MapConfig mapConfig, Coordinate coordinate)
        {
            return(Observable.Create <Unit>(
                       observer =>
            {
                var index = _coordinateService.GetFlattenArrayIndexFromAxialCoordinate(coordinate.X, coordinate.Z, mapConfig);

                CreateUnitFromStrongholdInIndex(levelData, index);
                CreateConstructFromStrongholdInIndex(levelData, index);
                ClearStrongholdInIndex(levelData, index);

                observer.OnNext(Unit.Default);
                observer.OnCompleted();

                return Disposable.Empty;
            }
                       ));
        }
        public void Load(IReadOnlyList <GameObjectFactory> gameObjectProviders, IReadOnlyList <IBoardItemHolder> holders, MapConfig mapConfig)
        {
            foreach (var holder in holders)
            {
                var flattenedIndex = _coordinateService.GetFlattenArrayIndexFromAxialCoordinate(
                    holder.Value.Coordinate.X,
                    holder.Value.Coordinate.Z,
                    mapConfig
                    );

                var gameObjectProvider = gameObjectProviders[flattenedIndex];
                if (gameObjectProvider == null) // if there is no gameObject in that coordinate(no board item)
                {
                    continue;
                }

                gameObjectProvider.Create(holder.Transform, false);
            }
        }