Beispiel #1
0
            /// <summary>
            /// 注册一个signal监听函数,自注册后释放的signal会触发该监听函数
            /// </summary>
            /// <typeparam name="T">signal类型</typeparam>
            /// <param name="action">监听函数</param>
            /// <param name="times">触发次数,负数表示无限触发</param>
            /// <returns>handler</returns>
            public SignalHandler <T> OnSignal <T>(Action <T> action, int times = -1)
            {
                var handler = new SignalHandler <T>(this, action, times);

                handlers.Add(handler);
                manager.AddHandler(handler);
                return(handler);
            }
Beispiel #2
0
        private void AddHandler(SignalHandler handler)
        {
            if (!dictionary.TryGetValue(handler.SignalType, out var handlers))
            {
                handlers = new SignalHandlers();
                dictionary.Add(handler.SignalType, handlers);
            }

            handlers.List.Add(handler);
        }
Beispiel #3
0
        private void RemoveHandler(SignalHandler handler)
        {
            if (!dictionary.TryGetValue(handler.SignalType, out var handlers))
            {
                return;
            }
            if (callStack > 0)
            {
                handlers.Delete = true;
                return;
            }

            handlers.List.Remove(handler);
        }
Beispiel #4
0
 internal void RemoveHandler(SignalHandler handler)
 {
     handlers.Remove(handler);
     manager.RemoveHandler(handler);
 }