public ConcurrentAssetPrecacher(MonoBehaviour hostMonoBehaviour, IList <string> assetsToPrecache, Action onCompleted, Action <int> onProgress, IEntityTemplateProvider entityTemplateProvider, int concurrentConnections = 5)
        {
            this.hostMonoBehaviour      = hostMonoBehaviour;
            this.assetsToPrecache       = assetsToPrecache;
            this.onCompleted            = onCompleted;
            this.onProgress             = onProgress;
            this.entityTemplateProvider = entityTemplateProvider;

            maxConcurrentConnections = concurrentConnections;
        }
Exemple #2
0
        internal static void Dispose()
        {
            if (connectionLifecycle == null)
            {
                throw new InvalidOperationException("Dispose called while not connected.");
            }

            connectionLifecycle = null;
            SignalDisconnection();

            templateProvider = null;
            Disconnecting    = false;
        }
Exemple #3
0
        public AssetPreloader(MonoBehaviour hostBehaviour, IEntityTemplateProvider templateProvider, IList <string> assetsToPrecache, IEnumerable <KeyValuePair <string, int> > assetsToPrePool, int maxConcurrentPrecacheConnections)
        {
            this.templateProvider = templateProvider;

            this.prefabPool       = new PooledPrefabFactory();
            this.assetsToPrecache = assetsToPrecache;
            this.assetsToPrePool  = assetsToPrePool;

            downloader = new ConcurrentAssetPrecacher(
                hostBehaviour,
                assetsToPrecache,
                OnPrecachingCompleted,
                OnPrecachingProgress,
                templateProvider,
                maxConcurrentPrecacheConnections);
        }
        public RuntimeEntityService(IEventDispatcher eventDispatcher,
            ILogger logger, [CanBeNull] IEntityTemplateProvider templateProvider = null, [CanBeNull] ICollection<EngineEntity> entities = null)
        {
            _eventDispatcher = eventDispatcher;
            _logger = logger;
            TemplateProvider = templateProvider;

            if (entities != null)
            {
                foreach (var entity in entities)
                {
                    _entityList.Add(entity);
                    _entityLookup.Add(entity.Id, entity);
                }
            }

            _idProvider = new UniqueIdProvider(_entityList.Count > 0 ? _entityList.Max(p => p.Id + 1) : 0);
        }
        public RuntimeEntityService(IEventDispatcher eventDispatcher,
                                    ILogger logger, [CanBeNull] IEntityTemplateProvider templateProvider = null,
                                    [CanBeNull] ICollection <EngineEntity> entities = null)
        {
            _eventDispatcher = eventDispatcher;
            _logger          = logger;
            TemplateProvider = templateProvider;

            if (entities != null)
            {
                foreach (var entity in entities)
                {
                    _entityList.Add(entity);
                    _entityLookup.Add(entity.Id, entity);
                }
            }

            _idProvider = new UniqueIdProvider(_entityList.Count > 0 ? _entityList.Max(p => p.Id + 1) : 0);
        }
        public LegacyEntityCreator(IEntityTemplateProvider templateProvider,
                                   ISpatialCommunicator spatialCommunicator,
                                   IPrefabFactory <GameObject> prefabFactory,
                                   IMutableUniverse universe,
                                   IEntityComponentInterestOverridesUpdater entityComponentInterestOverridesUpdater,
                                   IInterestedComponentUpdaterProvider interestedComponentUpdaterProvider,
                                   WorkerMetrics metrics)
        {
            this.templateProvider    = templateProvider;
            this.prefabFactory       = new PrefabFactoryMetrics(prefabFactory, metrics); // Associate metrics with the factory
            this.spatialCommunicator = spatialCommunicator;
            this.universe            = universe;
            this.entityComponentInterestOverridesUpdater = entityComponentInterestOverridesUpdater;
            this.interestedComponentUpdaterProvider      = interestedComponentUpdaterProvider;

            entitiesToSpawn = new Dictionary <EntityId, EntitySpawnData>();
            knownEntities   = new HashSet <EntityId>();

            this.metrics = metrics;
        }
Exemple #7
0
        public LegacyEntityPipelineSetup(MonoBehaviour hostBehaviour, IEntityPipeline entityPipeline, ISpatialCommunicator spatialCommunicator, IMutableUniverse universe, ILegacyEntityPipelineConfiguration config, IEntitySpawnLimiter spawnLimiter)
        {
            this.entityPipeline = entityPipeline;
            IPrefabFactory <GameObject> prefabFactory;

            if (!config.UsePrefabPooling && config.AssetsToPrePool != null && config.AssetsToPrePool.Any())
            {
                Debug.LogError("There are prefabs specified for pre-pooling, but prefab pooling is not enabled - pooling will occur");
            }

            bool preloaderHasFactory = false;

            if (config.UsePrefabPooling || config.AssetsToPrecache != null || config.AssetsToPrePool != null)
            {
                preloaderHasFactory = true;
#pragma warning disable 0612
                assetPreloader = new AssetPreloader(hostBehaviour,
                                                    config.TemplateProvider,
                                                    config.AssetsToPrecache,
                                                    config.AssetsToPrePool,
                                                    config.MaxConcurrentPrecacheConnections);
#pragma warning restore 0612
                assetPreloader.PrecachingCompleted += () =>
                {
                    if (config.OnPrecachingCompleted != null)
                    {
                        config.OnPrecachingCompleted();
                    }
                };

                assetPreloader.PrecachingProgress += progress =>
                {
                    if (config.OnPrecacheProgress != null)
                    {
                        config.OnPrecacheProgress(progress);
                    }
                };
            }

            if (preloaderHasFactory && config.UsePrefabPooling)
            {
                prefabFactory = assetPreloader.PrefabFactory;
            }
            else
            {
                prefabFactory = new UnityPrefabFactory();
            }

            criticalSectionPipelineBlock = new CriticalSectionPipelineBlock();

            throttledEntityDispatcher = new ThrottledEntityDispatcher(universe, spawnLimiter, config.Metrics);

            legacyEntityCreator = new LegacyEntityCreator(
                config.TemplateProvider,
                spatialCommunicator,
                prefabFactory,
                universe,
                config.EntityComponentInterestOverridesUpdater,
                config.InterestedComponentUpdaterProvider,
                config.Metrics);

            legacyComponentPipeline = new LegacyComponentPipeline(universe);

            entityComponentUpdater = new EntityComponentUpdater(universe);

            templateProvider = config.TemplateProvider;
        }