Пример #1
0
    /// <summary>
    /// 绑定数据类监听
    /// </summary>
    /// <param name="dataType"></param>
    /// <param name="eventMgr"></param>
    public void AddDataWatch(DataType dataType, EventMgr eventMgr)
    {
        if (EventMgrDict == null)
        {
            EventMgrDict = new Dictionary <DataType, DataEvent>();
        }

        if (EventMgrDict.ContainsKey(dataType))
        {
            //已存在该信息的刷新方法 先移除监听 绑定方法后重新监听
            EventManager.Instance.UnRegister((int)dataType);
            EventMgrDict[dataType].BindEvnt(eventMgr);
            EventManager.Instance.Register((int)dataType, EventMgrDict[dataType].InstanceEvent);
        }
        else
        {
            //不存在该信息的刷新方法,需注册
            var dataEvent = new DataEvent();
            dataEvent.BindEvnt(eventMgr);
            EventMgrDict.Add(dataType, dataEvent);
            EventManager.Instance.Register((int)dataType, dataEvent.InstanceEvent);
        }
    }