Example #1
0
 public void RemoveEvent(T cmd, ProtoCallBack cb)
 {
     if (events != null)
     {
         NetEventsWarp warp = null;
         if (events.TryGetValue(cmd, out warp))
         {
             warp.cbs -= cb;
             if (warp.cbs == null)
             {
                 events.Remove(cmd);
             }
         }
     }
 }
Example #2
0
    public Action AddEvent(T cmd, ProtoCallBack cb)
    {
        if (events == null)
        {
            events = new Dictionary <T, NetEventsWarp>();
        }
        NetEventsWarp warp = null;

        if (events.TryGetValue(cmd, out warp))
        {
            warp.cbs += cb;
        }
        else
        {
            events.Add(cmd, new NetEventsWarp(cb));
        }
        return(() =>
        {
            RemoveEvent(cmd, cb);
        });
    }
Example #3
0
 /// <summary>
 /// 移除监听
 /// </summary>
 public void RemoveLisener(byte protoID, ProtoCallBack cb)
 {
     eventLib.RemoveEvent(protoID, cb);
 }
Example #4
0
 /// <summary>
 /// 添加监听
 /// </summary>
 public void AddLisener(byte protoID, ProtoCallBack cb)
 {
     eventLib.AddEvent(protoID, cb);
 }
Example #5
0
 public NetEventsWarp(ProtoCallBack cbs)
 {
     this.cbs = cbs;
 }
Example #6
0
 /// <summary>
 /// 监听Proto
 /// </summary>
 /// <param name="protoID"></param>
 /// <param name="cb"></param>
 protected void RegisterListenProto(byte protoID, ProtoCallBack cb)
 {
     Connection.GetInstance().AddLisener(protoID, cb);
 }