public ScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentsInParents( bool excludeSelf = false, bool includeInactive = true) { BindingUtil.AssertIsInterfaceOrComponent(AllParentTypes); BindInfo.RequireExplicitScope = false; // Don't know how it's created so can't assume here that it violates AsSingle BindInfo.MarkAsCreationBinding = false; SubFinalizer = new ScopableBindingFinalizer( BindInfo, (container, concreteType) => new MethodMultipleProviderUntyped(ctx => { Assert.That(ctx.ObjectType.DerivesFromOrEqual <MonoBehaviour>(), "Cannot use FromComponentSibling to inject data into non monobehaviours!"); Assert.IsNotNull(ctx.ObjectInstance); var monoBehaviour = (MonoBehaviour)ctx.ObjectInstance; var res = monoBehaviour.GetComponentsInParent(concreteType, includeInactive) .Where(x => !ReferenceEquals(x, ctx.ObjectInstance)); if (excludeSelf) { res = res.Where(x => x.gameObject != monoBehaviour.gameObject); } return(res.Cast <object>()); }, container)); return(this); }
internal NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentsInNewPrefabResource( string resourcePath, GameObjectCreationParameters gameObjectInfo) { BindingUtil.AssertIsValidResourcePath(resourcePath); BindingUtil.AssertIsInterfaceOrComponent(AllParentTypes); BindInfo.RequireExplicitScope = true; SubFinalizer = new PrefabResourceBindingFinalizer( BindInfo, gameObjectInfo, resourcePath, (contractType, instantiator) => new GetFromPrefabComponentProvider(contractType, instantiator, false)); return(new NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo, gameObjectInfo)); }
internal NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentInNewPrefab( UnityEngine.Object prefab, GameObjectCreationParameters gameObjectInfo) { BindingUtil.AssertIsValidPrefab(prefab); BindingUtil.AssertIsInterfaceOrComponent(AllParentTypes); BindInfo.RequireExplicitScope = true; SubFinalizer = new PrefabBindingFinalizer( BindInfo, gameObjectInfo, prefab, (contractType, instantiator) => new GetFromPrefabComponentProvider(contractType, instantiator, true)); return(new NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo, gameObjectInfo)); }
public ConditionCopyNonLazyBinder FromComponentInHierarchy( bool includeInactive = true) { BindingUtil.AssertIsInterfaceOrComponent(ContractType); return(FromMethod(_ => { var res = BindContainer.Resolve <Context>().GetRootGameObjects() .Select(x => x.GetComponentInChildren <TContract>(includeInactive)) .Where(x => x != null).FirstOrDefault(); Assert.IsNotNull(res, "Could not find component '{0}' through FromComponentInHierarchy factory binding", typeof(TContract)); return res; })); }
public NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentInNewPrefabResource(string resourcePath) { BindingUtil.AssertIsValidResourcePath(resourcePath); BindingUtil.AssertIsInterfaceOrComponent(ContractType); var gameObjectInfo = new GameObjectCreationParameters(); ProviderFunc = (container) => new GetFromPrefabComponentProvider( ContractType, new PrefabInstantiator( container, gameObjectInfo, ContractType, new [] { ContractType }, BindInfo.Arguments, new PrefabProviderResource(resourcePath), BindInfo.InstantiatedCallback), true); return(new NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo, gameObjectInfo)); }
public ScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentInChildren( bool includeInactive = true) { BindingUtil.AssertIsInterfaceOrComponent(AllParentTypes); BindInfo.RequireExplicitScope = false; // Don't know how it's created so can't assume here that it violates AsSingle BindInfo.MarkAsCreationBinding = false; SubFinalizer = new ScopableBindingFinalizer( BindInfo, (container, concreteType) => new MethodMultipleProviderUntyped(ctx => { Assert.That(ctx.ObjectType.DerivesFromOrEqual <MonoBehaviour>(), "Cannot use FromComponentInChildren to inject data into non monobehaviours!"); Assert.IsNotNull(ctx.ObjectInstance); var monoBehaviour = (MonoBehaviour)ctx.ObjectInstance; var match = monoBehaviour.GetComponentInChildren(concreteType, includeInactive); if (match == null) { Assert.That(ctx.Optional, "Could not find any component with type '{0}' through FromComponentInChildren binding", concreteType); return(Enumerable.Empty <object>()); } return(new object[] { match }); }, container)); return(this); }