private T _GetFactoryObject <T>(FactoryTypes type) where T : MonoBehaviour, IFactoryObject { FactoryType ft = _factories.FirstOrDefault(f => f.type == type); if (ft == null) { Debug.LogWarning($"Type {typeof(T).Name} does not exists in the factory."); return(null); } if (ft.queue.Count == 0) { if (ft.allowGrowth == false) { return(null); } ft.Add(); } T obj = ft.queue.Dequeue() as T; if (obj != null) { obj.gameObject.SetActive(true); } else { Debug.LogError($"Failed to get object of type {typeof(T).Name}"); } return(obj); }
public void Test1(FactoryTypes factoryType, AnimalTypes animalType) { var animalFactory = AnimalFactory.CreateAnimalFactory(factoryType); Assert.NotNull(animalFactory); var animal = animalFactory.GetAnimal(animalType); if (factoryType == FactoryTypes.Land) { if (_landAnimals.Contains(animalType)) { Assert.NotNull(animal); switch (animal) { case Cat cat: Assert.Contains("Meow", cat.Speak()); break; case Dog dog: Assert.Contains("Bark", dog.Speak()); break; case Lion lion: Assert.Contains("Roar", lion.Speak()); break; } } else { Assert.Null(animal); } } else { if (_seaAnimals.Contains(animalType)) { Assert.NotNull(animal); switch (animal) { case Octopus octopus: Assert.Contains("SQUAWCK", octopus.Speak()); break; case Shark shark: Assert.Contains("Cannot", shark.Speak()); break; } } else { Assert.Null(animal); } } }
public void Populate() { type = (prefab as IFactoryObject).ObjectType; queue = new Queue <IFactoryObject>(); for (int i = 0; i < startAmount; i++) { Add(); } }
public static OverwriteStrategyBase Strategy(string type) { if (FactoryTypes.ContainsKey(type)) { return(FactoryTypes[type]); } else { throw new Exception("Overwrite strategy type " + type + " not found"); } }
public static AnimalFactory CreateAnimalFactory(FactoryTypes factoryType) { if (factoryType == FactoryTypes.Sea) { return(new SeaAnimalFactory()); } else { return(new LandAnimalFactory()); } }
// Overrides of the GetFactory so it can use enums insteed of strings (more elegant solution) public static NPCFactory GetFactory(FactoryTypes choice) { switch (choice) { case FactoryTypes.enemy: return(new EnemyFactory()); case FactoryTypes.friendly: return(new FriendlyFactory()); default: return(null); } }
public static string GetObjects(FactoryTypes baseType) { switch (baseType) { case FactoryTypes.Employee: classObj = "New Employee object created"; break; case FactoryTypes.Student: classObj = "New Student object creted"; break; default: classObj = "not a valid input found"; break; } return(classObj); }
public FactoryAttribute(FactoryTypes factoryType) { this.factoryType = factoryType; }
public FactoryBuilder(IServiceCollection services) { _services = services; _factoryTypes = new FactoryTypes <I, P>(); }
public Factory(IServiceProvider serviceProvider, FactoryTypes <I, P> factoryTypes) { _serviceProvider = serviceProvider; _factoryTypes = factoryTypes; }
// --- Public/Internal Methods ------------------------------------------------------------------------------------ public static T GetFactoryObject <T>(FactoryTypes type) where T : MonoBehaviour, IFactoryObject { return(Instance._GetFactoryObject <T>(type)); }