private void SetupTrackManagerInstance() { /* --- Build the track manager by configuring all the concrete types and supplying the dependencies accordingly --- */ var concreteTrackFactory = new LayoutTrackFactory(); var beatBlockArchetypeFactory = new SimpleBeatBlockArchetypeFactory(animControllerFactory, hbControllerFactory, animOccupationFactory, hbOccupationFactory); // Build the beatblock type-sepcific object pools var concreteSubPools = new QueueBasedObjectPool <BeatBlock> [beatBlockArchetypeFactory.NumArchetypes]; for (int i = 0; i < beatBlockArchetypeFactory.NumArchetypes; i++) { concreteSubPools[i] = new QueueBasedObjectPool <BeatBlock>(() => beatBlockArchetypeFactory.BuildArchetype(i), BEAT_BLOCK_PRE_INIT_SIZE); } var concreteBeatBlockPool = new SimpleCategoricalObjectPool <BeatBlock>(beatBlockArchetypeFactory.NumArchetypes, concreteSubPools); // Instantiate the track manager! trackManager = new TrackManager(concreteTrackFactory, concreteBeatBlockPool); }
private void SetupAnimControllerFactory() { // Each underlying prefab type defines an underlying 'animation archetype', which beatblock archetypes will map to. // We expect some amount of IAnimControllerConfigurationScripts to be attached to this config object, which will define the animation prefabs, // and thus define the animation archetypes. Each prefab will also contain data detailing which BeatBlock types use them! int currAnimationArchetypeId = 0; Dictionary <int, int> BeatBlockToAnimationTypeMapping = new Dictionary <int, int>(); Dictionary <int, IAnimControllerConfigurationScript> AnimationArcheTypeToControllerFactoryFunctionMapping = new Dictionary <int, IAnimControllerConfigurationScript>(); List <IObjectPool <AnimationObject> > prefabPools = new List <IObjectPool <AnimationObject> >(); foreach (IAnimControllerConfigurationScript config in GetComponents <IAnimControllerConfigurationScript>()) { foreach (AnimationObject prefab in config.GetPrefabs()) { // Each prefab type is pooled individually. var newPool = MakeNewPool(prefab); // Store this new subpool in the global list (which will later be passed into the categorical pool when that is constructed) prefabPools.Insert(currAnimationArchetypeId, newPool); // Add a mapping refence for all the BeatBlock types which will end up using this. foreach (int bbType in prefab.BeatBlockTypesWhichUseThis) { BeatBlockToAnimationTypeMapping.Add(bbType, currAnimationArchetypeId); } // Add a mapping reference to the config object capable of creating the correct Controller object for this animation archetype AnimationArcheTypeToControllerFactoryFunctionMapping.Add(currAnimationArchetypeId, config); // Increment! currAnimationArchetypeId++; } } // Create the shared pool of animation prefab objects ICategoricalObjectPool <AnimationObject> animPrefabPool = new SimpleCategoricalObjectPool <AnimationObject>(currAnimationArchetypeId, prefabPools.ToArray()); // Create the Animation controller factory! animControllerFactory = new AnimationControllerFactory(BeatBlockToAnimationTypeMapping, AnimationArcheTypeToControllerFactoryFunctionMapping, animPrefabPool); }