Example #1
0
        /// <summary>
        /// Post parameters to all subscibed methods
        /// 将参数广播到全部监听方法
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="parameters"></param>
        public void Post(string tag, params object[] parameters)
        {
            if (!_subscribeTag2Methods.TryGetValue(tag, out var todo))
            {
                return;
            }
            if (todo.Count == 0)
            {
                return;
            }
            var executeEvent = RecyclableList <MessageEvent> .Create();

            foreach (var td in todo)
            {
                if (td.Tag != tag)
                {
                    continue;
                }
                try
                {
                    executeEvent.Add(td);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
            }
            foreach (var messageEvent in executeEvent)
            {
                messageEvent.Invoke(parameters);
            }
            executeEvent.Dispose();
        }
Example #2
0
        void Start()
        {
            Init();

            RecyclableList.Create(Data.Count, ListItem);
            RecyclableList.gameObject.SetActive(true);
        }
Example #3
0
        /// <summary>
        /// Unregister all subscribed methods in a type
        /// 取消注册某类型中全部被监听方法
        /// </summary>
        /// <param name="val"></param>
        public void Unregister <T>(T val) where T : class
        {
            if (!_subscribeInstance2Methods.TryGetValue(val, out var methods))
            {
                return;
            }
            var tmpMethods = RecyclableList <MessageEvent> .Create();

            tmpMethods.AddRange(methods);
            foreach (var method in tmpMethods)
            {
                UnregisterOneMethod(method.Tag, val);
            }
            tmpMethods.Dispose();
        }