SHARE
TWEET

IPool

BorisKotlyar May 25th, 2020 833 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class PoolManager : IPoolManager
  2.     {
  3.         private readonly DiContainer _container;
  4.  
  5.         public PoolManager(DiContainer container)
  6.         {
  7.             _container = container;
  8.         }
  9.  
  10.         public object Create(Type concreteType, params object[] args)
  11.         {
  12.             var result = _container.Instantiate(concreteType, args);
  13.             if (result == null)
  14.                 throw new UnityException("Missing Factory<" + concreteType.ToString() + ">");
  15.  
  16.             return result;
  17.         }
  18.  
  19.         public T Create<T>(params object[] args)
  20.         {
  21.             var result = _container.Instantiate<T>(args);
  22.             if (result == null)
  23.                 throw new UnityException("Missing Factory<" + typeof(T).ToString() + ">");
  24.  
  25.             return result;
  26.         }
  27.  
  28.         public T CreateComponent<T>(params object[] args) where T : Component
  29.         {
  30.             var type = typeof(T);
  31.             var go = new GameObject(type.Name);
  32.             var result = go.AddComponent<T>();
  33.             return result;
  34.         }
  35.  
  36.         public Component CreateComponent(Type componentType, params object[] args)
  37.         {
  38.             var go = new GameObject(componentType.Name);
  39.             var result = go.AddComponent(componentType);
  40.             return result;
  41.         }
  42.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top