コード例 #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(this IBindingContract contract, IPool pool)
        {
            Assert.IsTrue(pool.Type.Is(contract.ContractType));

            return(contract.ToMethod(c => pool.Create()).AsTransient());
        }