Advertisement
Pro_Unit

StateFactory

Feb 8th, 2023
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System;
  2. using Game.Gameplay.AI.States;
  3. using Zenject;
  4.  
  5. namespace Game.Gameplay
  6. {
  7.     public class StateFactory : PlaceholderFactory<Type, IState>
  8.     {
  9.         public class Custom : IFactory<Type, IState>
  10.         {
  11.             private readonly DiContainer _container;
  12.  
  13.             public Custom(DiContainer container) => _container = container;
  14.  
  15.             public IState Create(Type type)
  16.             {
  17.                 if (typeof(IState).IsAssignableFrom(type))
  18.                     return (IState)_container.Instantiate(type);
  19.  
  20.                 throw new ArgumentException($"Argument {nameof(type)} is not valid value. ");
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement