public void NotifyGeneratorDestroyAndRemoveAllListeners()
        {
            if (m_all_type_listeners == null)
            {
                return;
            }
            var all_type_listeners = m_all_type_listeners;

            m_all_type_listeners = null;
            LogicWorld    logic_world = GetLogicWorldForSignal();
            var           enumerator  = all_type_listeners.GetEnumerator();
            HashSet <int> notified    = new HashSet <int>();

            while (enumerator.MoveNext())
            {
                List <SignalListenerContext> listeners = enumerator.Current.Value;
                for (int i = 0; i < listeners.Count; ++i)
                {
                    SignalListenerContext context = listeners[i];
                    if (notified.Contains(context.ID))
                    {
                        continue;
                    }
                    notified.Add(context.ID);
                    ISignalListener listener = context.GetListener(logic_world);
                    if (listener != null)
                    {
                        listener.OnGeneratorDestroyed(this);
                    }
                }
            }
        }
        public void SendSignal(int signal_type, System.Object signal = null)
        {
            if (m_all_type_listeners == null)
            {
                return;
            }
            List <SignalListenerContext> listeners;

            if (!m_all_type_listeners.TryGetValue(signal_type, out listeners))
            {
                return;
            }
            int cur_count = listeners.Count;

            if (cur_count == 0)
            {
                return;
            }
            LogicWorld logic_world = GetLogicWorldForSignal();
            int        index       = 0;

            while (index < cur_count)
            {
                SignalListenerContext context  = listeners[index];
                ISignalListener       listener = context.GetListener(logic_world);
                if (listener == null)
                {
                    listeners.RemoveAt(index);
                }
                else
                {
                    listener.ReceiveSignal(this, signal_type, signal);
                }
                int new_count = listeners.Count;
                if (new_count < cur_count)
                {
                    cur_count = new_count;
                }
                else
                {
                    ++index;
                }
            }
        }