Ejemplo n.º 1
0
        public override object GetInstance(Type contractType, InjectContext context)
        {
            Assert.That(_componentType.DerivesFromOrEqual(contractType));

            if (_instance == null)
            {
                if (_instantiator == null)
                {
                    _instantiator = _container.Resolve <GameObjectInstantiator>();
                }

                // We don't use the generic version here to avoid duplicate generic arguments to binder
                _instance = _instantiator.Instantiate(_componentType, _name);
                Assert.That(_instance != null);
            }

            return(_instance);
        }
Ejemplo n.º 2
0
        public TContract Create(params object[] constructorArgs)
        {
            if (_instantiator == null)
            {
                _instantiator = _container.Resolve <GameObjectInstantiator>();
            }

            var gameObj = _instantiator.Instantiate(_prefab, constructorArgs);

            var component = gameObj.GetComponentInChildren <TContract>();

            if (component == null)
            {
                throw new ZenjectResolveException(
                          "Could not find component '{0}' when creating game object from prefab".With(typeof(TContract).Name()));
            }

            return(component);
        }
Ejemplo n.º 3
0
        public override object GetInstance(Type contractType, InjectContext context)
        {
            Assert.That(_componentType.DerivesFromOrEqual(contractType));

            if (_instance == null)
            {
                if (_instantiator == null)
                {
                    _instantiator = _container.Resolve <GameObjectInstantiator>();
                }

                Assert.That(!_container.AllowNullBindings,
                            "Tried to instantiate a MonoBehaviour with type '{0}' during validation. Object graph: {1}", _componentType, DiContainer.GetCurrentObjectGraph());

                // We don't use the generic version here to avoid duplicate generic arguments to binder
                _instance = _instantiator.Instantiate(_componentType, _name);
                Assert.That(_instance != null);
            }

            return(_instance);
        }