Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
0
        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");
     }
 }
Exemplo n.º 5
0
 public static AnimalFactory CreateAnimalFactory(FactoryTypes factoryType)
 {
     if (factoryType == FactoryTypes.Sea)
     {
         return(new SeaAnimalFactory());
     }
     else
     {
         return(new LandAnimalFactory());
     }
 }
Exemplo n.º 6
0
        // 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);
        }
Exemplo n.º 8
0
 public FactoryAttribute(FactoryTypes factoryType)
 {
     this.factoryType = factoryType;
 }
Exemplo n.º 9
0
 public FactoryBuilder(IServiceCollection services)
 {
     _services     = services;
     _factoryTypes = new FactoryTypes <I, P>();
 }
Exemplo n.º 10
0
 public Factory(IServiceProvider serviceProvider, FactoryTypes <I, P> factoryTypes)
 {
     _serviceProvider = serviceProvider;
     _factoryTypes    = factoryTypes;
 }
Exemplo n.º 11
0
 // --- Public/Internal Methods ------------------------------------------------------------------------------------
 public static T GetFactoryObject <T>(FactoryTypes type) where T : MonoBehaviour, IFactoryObject
 {
     return(Instance._GetFactoryObject <T>(type));
 }