Exemplo n.º 1
0
    public void AddEventListener(CEventType eventType, CEventListenerDelegate listener)
    {
        CEventListenerDelegate ceventListenerDelegate = this.listeners[eventType] as CEventListenerDelegate;

        ceventListenerDelegate    = (CEventListenerDelegate)Delegate.Combine(ceventListenerDelegate, listener);
        this.listeners[eventType] = ceventListenerDelegate;
    }
Exemplo n.º 2
0
    public void AddEventListener(string eventName, CEventListenerDelegate listener)
    {
        CEventListenerDelegate ceventListenerDelegate = this.listeners[eventName] as CEventListenerDelegate;

        //这个combine就相当于委托的+=    (整体的实现就是类似于观察者模式)
        ceventListenerDelegate    = (CEventListenerDelegate)Delegate.Combine(ceventListenerDelegate, listener);
        this.listeners[eventName] = ceventListenerDelegate;
    }
Exemplo n.º 3
0
    public void RemoveEventListener(CEventType eventType, CEventListenerDelegate listener)
    {
        CEventListenerDelegate ceventListenerDelegate = this.listeners[eventType] as CEventListenerDelegate;

        if (ceventListenerDelegate != null)
        {
            ceventListenerDelegate = (CEventListenerDelegate)Delegate.Remove(ceventListenerDelegate, listener);
        }
        this.listeners[eventType] = ceventListenerDelegate;
    }
Exemplo n.º 4
0
        /// <summary>
        /// 移出事件的监听
        /// </summary>
        /// <param name="eventType"></param>
        /// <param name="listener"></param>
        public void RemoveEventListener(CEventType eventType,CEventListenerDelegate listener)
        {
            CEventListenerDelegate ceventListenerDelegate = this.listeners[eventType] as CEventListenerDelegate;
            if(ceventListenerDelegate != null)
            {
                ceventListenerDelegate = (CEventListenerDelegate)Delegate.Remove(ceventListenerDelegate, listener);
            }

            this.listeners[eventType] = ceventListenerDelegate;
        }
Exemplo n.º 5
0
    public void RemoveEventListener(CEventType cEventType, CEventListenerDelegate listener)
    {
        CEventListenerDelegate cEventListenerDelegate = this.listeners[cEventType];

        if (cEventListenerDelegate != null)
        {
            cEventListenerDelegate -= listener;
        }

        this.listeners[cEventType] = cEventListenerDelegate;
    }
Exemplo n.º 6
0
    public void DispatchEvent(CBaseEvent cBaseEvent)
    {
        CEventListenerDelegate cEventListenerDelegate = this.listeners[cBaseEvent.eventType];

        if (cEventListenerDelegate != null)
        {
            try
            {
                cEventListenerDelegate(cBaseEvent);
            }
            catch (System.Exception e)
            {
                Debug.Log("An exception was thrown.The message was:" + e.Message + ".The detail of stack trace was:" + e.StackTrace);
            }
        }
    }
Exemplo n.º 7
0
    public void AddEventListener(CEventType cEventType, CEventListenerDelegate listener)
    {
        CEventListenerDelegate cEventListenerDelegate;

        this.listeners.TryGetValue(cEventType, out cEventListenerDelegate);

        //Debug.Log(cEventListenerDelegate.ToString());

        if (cEventListenerDelegate != null)
        {
            cEventListenerDelegate += listener;
        }
        else
        {
            cEventListenerDelegate = listener;
        }

        this.listeners[cEventType] = cEventListenerDelegate;
    }
Exemplo n.º 8
0
    /// <summary>
    /// 使用字符串传递
    /// </summary>
    /// <param name="evt"></param>
    public void DispatchStringEvent(CBaseEvent evt)
    {
        CEventListenerDelegate ceventListenerDelegate = this.listeners[evt.EventName] as CEventListenerDelegate;

        if (ceventListenerDelegate != null)
        {
            try
            {
                ceventListenerDelegate(evt);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Concat(new string[]
                {
                    "Error dispatching event ",
                    evt.Type.ToString(),
                    ": ",
                    ex.Message,
                    " ",
                    ex.StackTrace
                }), ex);
            }
        }
    }
Exemplo n.º 9
0
 /// <summary>
 /// 添加事件的监听
 /// </summary>
 /// <param name="eventType"></param>
 /// <param name="listener"></param>
 public void AddEventListener(CEventType eventType,CEventListenerDelegate listener)
 {
     CEventListenerDelegate ceventListenerDelegate = this.listeners[eventType] as CEventListenerDelegate;
     ceventListenerDelegate = (CEventListenerDelegate)Delegate.Combine(ceventListenerDelegate, listener);
     this.listeners[eventType] = ceventListenerDelegate;
 }