Exemplo n.º 1
0
        public void Raise(Event ev)
        {
            IEventFactory factory = Factory.GetEventFactory(ev.Meta.TypeId);

            List <CallbackWrapper> newCallbacks;

            if (callbacks.TryGetValue(ev.GetType(), out newCallbacks))
            {
                for (int i = 0; i < callbacks.Count; ++i)
                {
                    newCallbacks[i].Wrapper(ev);
                }
            }

            for (int i = 0; i < targets.Count; ++i)
            {
                EventListener mb = targets[i];

                if (mb.Behaviour)
                {
                    // dont call on disabled behaviours
                    if (mb.Behaviour.enabled == false)
                    {
                        if ((mb.Listener == null) || (mb.Listener.InvokeIfDisabled == false))
                        {
                            continue;
                        }
                    }

                    // dont call on behaviours attached to inactive game objects
                    if (mb.GameObject.activeInHierarchy == false)
                    {
                        if ((mb.Listener == null) || (mb.Listener.InvokeIfGameObjectIsInactive == false))
                        {
                            continue;
                        }
                    }

                    // invoke event
                    try
                    {
                        factory.Dispatch(ev, mb.Behaviour);
                    }
                    catch (Exception exn)
                    {
                        NetLog.Error("User code threw exception when invoking {0}", ev);
                        NetLog.Exception(exn);
                    }
                }
                else
                {
                    // remove callback if this behaviour is destroyed
                    targets.RemoveAt(i);

                    //
                    --i;

                    continue;
                }
            }
        }