public static ZenjectTypeInfo GetInfo(Type type)
        {
#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
            using (ProfileBlock.Start("Zenject Reflection"))
#endif
            {
                Assert.That(!type.IsAbstract(),
                            "Tried to analyze abstract type '{0}'.  This is not currently allowed.", type);

                ZenjectTypeInfo info;

#if ZEN_MULTITHREADING
                lock (_typeInfo)
#endif
                {
                    if (!_typeInfo.TryGetValue(type, out info))
                    {
                        info = CreateTypeInfo(type);
                        _typeInfo.Add(type, info);
                    }
                }

                return(info);
            }
        }
Example #2
0
        public void Initialize()
        {
            Assert.That(!_hasInitialized);
            _hasInitialized = true;

            _initializables = _initializables.OrderBy(x => x.Priority).ToList();

#if UNITY_EDITOR
            foreach (var initializable in _initializables.Select(x => x.Initializable).GetDuplicates())
            {
                Assert.That(false, "Found duplicate IInitializable with type '{0}'".Fmt(initializable.GetType()));
            }
#endif

            foreach (var initializable in _initializables)
            {
                Log.Debug("Initializing '" + initializable.Initializable.GetType() + "'");

                try
                {
#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
                    using (ProfileBlock.Start("{0}.Initialize()", initializable.Initializable.GetType()))
#endif
                    {
                        initializable.Initializable.Initialize();
                    }
                }
                catch (Exception e)
                {
                    throw Assert.CreateException(
                              e, "Error occurred while initializing IInitializable with type '{0}'", initializable.Initializable.GetType());
                }
            }
        }
        protected override void UpdateItem(IFixedTickable task)
        {
#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
            using (ProfileBlock.Start("{0}.FixedTick()", task.GetType()))
#endif
            {
                task.FixedTick();
            }
        }
Example #4
0
        public override void Execute(object[] args)
        {
            Assert.That(args.IsEmpty());

#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
            using (ProfileBlock.Start(_method.ToDebugString()))
#endif
            {
                _method();
            }
        }
        protected override void InternalExecute(THandler handler, object[] args)
        {
            Assert.That(args.IsEmpty());

#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
            using (ProfileBlock.Start(_method.ToDebugString()))
#endif
            {
                _method(handler);
            }
        }
Example #6
0
        public void Fire(TParam1 p1, TParam2 p2)
        {
#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
            using (ProfileBlock.Start("Signal '{0}'", this.GetType().Name))
#endif
            {
                var wasHandled = Manager.Trigger(SignalId, new object[] { p1, p2 });

                wasHandled |= (_listeners.Count > 0);

                // Iterate over _tempListeners in case the
                // listener removes themselves in the callback
                // (we use _tempListeners to avoid memory allocs)
                _tempListeners.Clear();

                for (int i = 0; i < _listeners.Count; i++)
                {
                    _tempListeners.Add(_listeners[i]);
                }

                for (int i = 0; i < _tempListeners.Count; i++)
                {
                    var listener = _tempListeners[i];

#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
                    using (ProfileBlock.Start(listener.ToDebugString()))
#endif
                    {
                        listener(p1, p2);
                    }
                }

#if ZEN_SIGNALS_ADD_UNIRX
                wasHandled |= _observable.HasObservers;
#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
                using (ProfileBlock.Start("UniRx Stream"))
#endif
                {
                    _observable.OnNext(UniRx.Tuple.Create(p1, p2));
                }
#endif

                if (Settings.RequiresHandler && !wasHandled)
                {
                    throw Assert.CreateException(
                              "Signal '{0}' was fired but no handlers were attached and the signal is marked to require a handler!", SignalId);
                }
            }
        }
        public void LazyInjectAll()
        {
#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
            using (ProfileBlock.Start("LazyInstanceInjector.LazyInjectAll"))
#endif
            {
                var tempList = new List <object>();
                while (!_instancesToInject.IsEmpty())
                {
                    tempList.Clear();
                    tempList.AddRange(_instancesToInject);
                    _instancesToInject.Clear();
                    foreach (var instance in tempList)
                    {
                        _container.Inject(instance);
                    }
                }
            }
        }
Example #8
0
        public void OnGui()
        {
            foreach (var renderable in _renderables)
            {
                try
                {
#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
                    using (ProfileBlock.Start("{0}.GuiRender()", renderable.Renderable.GetType()))
#endif
                    {
                        renderable.Renderable.GuiRender();
                    }
                }
                catch (Exception e)
                {
                    throw Assert.CreateException(
                              e, "Error occurred while initializing IGuiRenderable with type '{0}'", renderable.Renderable.GetType());
                }
            }
        }
        // Returns true the signal was handled
        public bool Trigger(BindingId signalType, object[] args)
        {
            var handlers = GetList(signalType);

            if (handlers.Count == 0)
            {
                return(false);
            }

#if UNITY_EDITOR && ZEN_PROFILING_ENABLED
            using (ProfileBlock.Start("Signal '{0}'", signalType))
#endif
            {
                foreach (var handler in handlers)
                {
                    handler.Execute(args);
                }
            }

            return(true);
        }