예제 #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
 public void ActivateClient(List <Activator> coreActivators, List <Activator> nonCoreActivators)
 {
     this.coreActivators    = coreActivators;
     this.nonCoreActivators = nonCoreActivators;
     InjectionUtils.RegisterInjectionPoints(typeof(InjectAttribute), ServiceRegistry.Current);
     this.LaunchCoreActivators();
 }
예제 #3
0
 public static void Clean()
 {
     AssetBundleDiskCache.Clean();
     AssetBundlesStorage.Clean();
     ServiceRegistry.Reset();
     InjectionUtils.ClearInjectionPoints(typeof(InjectAttribute));
     BaseElementCanvasScaler.MarkNeedInitialize();
     FatalErrorHandler.IsErrorScreenWasShown = false;
 }
예제 #4
0
        private static bool CanInjectCloud(PropertyInfo prop, Inject inject, object obj)
        {
            bool isValidInjectType = (inject.Type == InjectType.Cloud || inject.Type == InjectType.Auto);

            if (isValidInjectType == false)
            {
                return(false);
            }

            var  cloudAttribute    = InjectionUtils.GetAttribute <CloudAttribute>(prop.PropertyType);
            bool hasCloudAttribute = cloudAttribute != null;

            return(hasCloudAttribute);
        }
예제 #5
0
        internal static void InjectBehaviourInner(object obj)
        {
            List <System.Type> typeChain = InjectionUtils.GetObjectTypeChain(obj);

            foreach (var t in typeChain)
            {
                var properties = t.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

                foreach (var prop in properties)
                {
                    var injectAttribute = InjectionUtils.GetAttribute <Inject>(prop);
                    if (injectAttribute != null)
                    {
                        InjectPropertyIntoObjByAttribute(obj, prop, injectAttribute);
                    }
                }
            }
        }
예제 #6
0
 internal static void CallStartMethod(object cloud)
 {
     InjectionUtils.CallAttributedMethod(cloud, START_ATTR_TYPE, INSTANCE_METHOD_FLAGS);
 }
예제 #7
0
 internal static void CallSignalStart(object signal)
 {
     InjectionUtils.CallAttributedMethod(signal, START_ATTR_TYPE, INSTANCE_METHOD_FLAGS);
 }