コード例 #1
0
        public static IBindingScope ToPrefab(this IBindingContract contract, GameObject prefab, bool injectHierarchy = true)
        {
            Assert.IsNotNull(prefab);
            Assert.IsTrue(contract.ContractType.Is <GameObject>() || prefab.GetComponent(contract.ContractType) != null);

            return(contract.ToMethod(c =>
            {
                var instance = UnityEngine.Object.Instantiate(prefab);

                if (injectHierarchy)
                {
                    var components = instance.GetComponentsInChildren <MonoBehaviour>();

                    for (int i = 0; i < components.Length; i++)
                    {
                        c.Container.Injector.Inject(components[i]);
                    }
                }

                if (contract.ContractType.Is <GameObject>())
                {
                    return instance;
                }
                else
                {
                    return instance.GetComponent(contract.ContractType);
                }
            }));
        }
コード例 #2
0
        public static IBindingScope ToPrefab(this IBindingContract contract, UnityEngine.Object prefab)
        {
            Assert.IsNotNull(prefab);
            Assert.IsTrue(prefab.GetType().Is(contract.ContractType));

            return(contract.ToMethod(c => UnityEngine.Object.Instantiate(prefab)));
        }
コード例 #3
0
 public static IBindingCondition ToPool <TContract, TConcrete>(this IBindingContract <TContract> contract, IPool <TConcrete> pool) where TConcrete : class, TContract
 {
     return(contract.ToPool(pool));
 }
コード例 #4
0
        public static IBindingCondition ToPool(this IBindingContract contract, IPool pool)
        {
            Assert.IsTrue(pool.Type.Is(contract.ContractType));

            return(contract.ToMethod(c => pool.Create()).AsTransient());
        }
コード例 #5
0
 protected virtual IBindingScope To(IBindingContract contract, Type concreteType)
 {
     return contract.To(concreteType);
 }
コード例 #6
0
 protected virtual IBindingScope To(IBindingContract contract, Type concreteType)
 {
     return(contract.To(concreteType));
 }
コード例 #7
0
 protected override IBindingScope To(IBindingContract contract, Type concreteType)
 {
     return contract.ToFactory(concreteType);
 }
コード例 #8
0
 public static IBindingScope ToPrefab <TContract, TConcrete>(this IBindingContract <TContract> contract, TConcrete prefab) where TConcrete : UnityEngine.Object, TContract
 {
     return(((IBindingContract)contract).ToPrefab(prefab));
 }
コード例 #9
0
        /// <summary>
        /// Determines whether the selected item is bindable to the model class T.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item">The item containing the field with the selected item to bind.</param>
        /// <param name="fieldId">The id of the field containing the selected item to test.</param>
        /// <param name="bindingContract">The binding contract to use for testing the selected item.</param>
        /// <returns><c>true</c> if the selected item is bindable to the model class T; otherwise <c>false</c></returns>
        public static Boolean IsSelectedItemBindable <T>(this Item item, ID fieldId, IBindingContract bindingContract) where T : class
        {
            Item targetItem = item.GetDropLinkSelectedItem(fieldId);

            return(targetItem != null && targetItem.IsBindable <T>(bindingContract));
        }
コード例 #10
0
        /// <summary>
        /// Determines whether the selected item is bindable to the model class T.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item">The item containing the field with the selected item to bind.</param>
        /// <param name="fieldId">The id of the field containing the selected item to test.</param>
        /// <returns><c>true</c> if the selected item is bindable to the model class T; otherwise <c>false</c></returns>
        public static Boolean IsSelectedItemBindable <T>(this Item item, ID fieldId) where T : class
        {
            IBindingContract bindingContract = ModelFactoryService.ResolveModelFactory <T>().BindingContract;

            return(item.IsSelectedItemBindable <T>(fieldId, bindingContract));
        }
コード例 #11
0
 /// <summary>
 /// Determines whether the specified item is bindable to the model class T.
 /// </summary>
 /// <typeparam name="T">The model class that the item should be bindable to.</typeparam>
 /// <param name="item">The item to test.</param>
 /// <param name="bindingContract">The binding contract to use for testing the item.</param>
 /// <returns><c>true</c> if the item is bindable to the model class T; otherwise <c>false</c></returns>
 public static Boolean IsBindable <T>(this Item item, IBindingContract bindingContract) where T : class
 {
     return(bindingContract.IsCompliant <T>(item));
 }
コード例 #12
0
        /// <summary>
        /// Determines whether the specified item is bindable to the model class T.
        /// </summary>
        /// <typeparam name="T">The model class that the item should be bindable to.</typeparam>
        /// <param name="item">The item to test.</param>
        /// <returns><c>true</c> if the item is bindable to the model class T; otherwise <c>false</c></returns>
        public static Boolean IsBindable <T>(this Item item) where T : class
        {
            IBindingContract bindingContract = ModelFactoryService.ResolveModelFactory <T>().BindingContract;

            return(item.IsBindable <T>(bindingContract));
        }
コード例 #13
0
 /// <summary>
 /// Determines whether the specified item or one of its ancestors is bindable to the model class T.
 /// </summary>
 /// <typeparam name="T">The model class that the item should be bindable to.</typeparam>
 /// /// <param name="bindingContract">The binding contract to use for testing the item.</param>
 /// <param name="item">The item to test.</param>
 /// <returns><c>true</c> if the item or one of its ancestors is bindable to the model class T; otherwise <c>false</c></returns>
 public static Boolean IsAncestorOrSelfBindable <T>(this Item item, IBindingContract bindingContract) where T : class
 {
     return(GetAncestorsAndSelf(item).Any(itm => itm.IsBindable <T>()));
 }
コード例 #14
0
 protected override IBindingScope To(IBindingContract contract, Type concreteType)
 {
     return(contract.ToFactory(concreteType));
 }