示例#1
0
        internal static void AutoCreateEntities(BaseInjectionBinder binder)
        {
            var           typeDic        = InjectionUtils.GetTypesWithAttribute <AutoCreateAttribute>();
            List <object> cloudsCreated  = new List <object>();
            List <object> signalsCreated = new List <object>();

            foreach (var typeKVP in typeDic)
            {
                var type       = typeKVP.Key;
                var attribute  = typeKVP.Value;
                var binderType = attribute.BinderType;

                if (binderType != null &&
                    binder.GetType().IsAssignableFrom(binderType) == false)
                {
                    continue; //This entity does not permit auto creation from this binder
                }

                if (BASE_SIGNAL_TYPE.IsAssignableFrom(type))
                {
                    bool isNew;
                    var  newSignal = GetOrMakeSignal(type, out isNew, "[AutoCreate]-" + type.ToString());
                    if (isNew)
                    {
                        signalsCreated.Add(newSignal);
                    }
                }
                else if (InjectionUtils.GetAttribute <CloudAttribute>(type) != null)
                {
                    if (_cloudDictionary.ContainsKey(type))
                    {
                        continue;

                        /*
                         *  Cloud already exists,
                         *  this may be normal behaviour if two Scenes
                         *  have invoked the AutoCreate via their binders
                         */
                    }

                    cloudsCreated.Add(CreateCloud(type));
                }
                else
                {
                    Debug.LogWarning("Can't AutoCreate type " + type.ToString() + " Ignoring");
                }
            }

            foreach (var cloudCreated in cloudsCreated)
            {
                Binder._onStart.AddOnce(() => InjectBehaviourInner(cloudCreated));
                Binder._onStartFinished.AddOnce(() => CallStartMethod(cloudCreated));
            }

            foreach (var signalCreate in signalsCreated)
            {
                Binder._onStart.AddOnce(() => InjectSignal(signalCreate));
                Binder._onStartFinished.AddOnce(() => CallSignalStart(signalCreate));
            }
        }
示例#2
0
        internal static void AssureBindingsApplied(BaseInjectionBinder binderToUse = null)
        {
            if (_bindingsApplyAttempted)
            {
                return;
            }

            var binder = binderToUse ?? UnityEngine.Object.FindObjectOfType <BaseInjectionBinder>();

            if (binder != null)
            {
                binder.Initialize();
            }
            else
            {
                var defaultBinderGameObject = new GameObject("EasyJect Default Binder", typeof(DefaultInjectionBinder));
            }

            _bindingsApplyAttempted = true;
        }