public GameObject Instantiate(InjectContext context, List <TypeValuePair> args, out Action injectAction) { Assert.That(_argumentTarget == null || _argumentTarget.DerivesFromOrEqual(context.MemberType)); bool shouldMakeActive; var gameObject = _container.CreateAndParentPrefab( GetPrefab(context), _gameObjectBindInfo, context, out shouldMakeActive); Assert.IsNotNull(gameObject); injectAction = () => { var allArgs = ZenPools.SpawnList <TypeValuePair>(); allArgs.AllocFreeAddRange(_extraArguments); allArgs.AllocFreeAddRange(args); if (_argumentTarget == null) { Assert.That( allArgs.IsEmpty(), "Unexpected arguments provided to prefab instantiator. Arguments are not allowed if binding multiple components in the same binding"); } if (_argumentTarget == null || allArgs.IsEmpty()) { _container.InjectGameObject(gameObject); } else { _container.InjectGameObjectForComponentExplicit( gameObject, _argumentTarget, allArgs, context, null); Assert.That(allArgs.Count == 0); } ZenPools.DespawnList <TypeValuePair>(allArgs); if (shouldMakeActive && !_container.IsValidating) { #if ZEN_INTERNAL_PROFILING using (ProfileTimers.CreateTimedBlock("User Code")) #endif { gameObject.SetActive(true); } } if (_instantiateCallback != null) { var callbackObjects = ZenPools.SpawnHashSet <object>(); foreach (var type in _instantiateCallbackTypes) { var obj = gameObject.GetComponentInChildren(type); if (obj != null) { callbackObjects.Add(obj); } } foreach (var obj in callbackObjects) { _instantiateCallback(context, obj); } ZenPools.DespawnHashSet(callbackObjects); } }; return(gameObject); }