public U_PrefabFacade Create(Object prefab, C c)
    {
        // This is marchingninja's solution:
        var instance   = (GameObject)Object.Instantiate(prefab);
        var components = new List <MonoBehaviour>();

        ZenUtilInternal.GetInjectableMonoBehavioursUnderGameObject(instance, components);
        foreach (MonoBehaviour component in components)
        {
            _container.Inject(component, new[] { c });
        }

        return(instance.GetComponent <U_PrefabFacade>());
    }
示例#2
0
        protected override void GetInjectableMonoBehaviours(List <MonoBehaviour> monoBehaviours)
        {
            ZenUtilInternal.AddStateMachineBehaviourAutoInjectersUnderGameObject(gameObject);

            // We inject on all components on the root except ourself
            foreach (var monoBehaviour in GetComponents <MonoBehaviour>())
            {
                if (monoBehaviour == null)
                {
                    // Missing script
                    continue;
                }

                if (!ZenUtilInternal.IsInjectableMonoBehaviourType(monoBehaviour.GetType()))
                {
                    continue;
                }

                if (monoBehaviour == this)
                {
                    continue;
                }

                monoBehaviours.Add(monoBehaviour);
            }

            for (int i = 0; i < transform.childCount; i++)
            {
                var child = transform.GetChild(i);

                if (child != null)
                {
                    ZenUtilInternal.GetInjectableMonoBehavioursUnderGameObject(
                        child.gameObject, monoBehaviours);
                }
            }
        }
示例#3
0
 protected override void GetInjectableMonoBehaviours(List <MonoBehaviour> monoBehaviours)
 {
     ZenUtilInternal.AddStateMachineBehaviourAutoInjectersUnderGameObject(this.gameObject);
     ZenUtilInternal.GetInjectableMonoBehavioursUnderGameObject(this.gameObject, monoBehaviours);
 }